Skip to content

Commit 41ebe94

Browse files
committed
use/plugins: Refactor test to use _G_U_M, not @go
This is part of the refactoring of `_GO_USE_MODULES` to provide correct `@go` command script scope for plugin modules. Specifically, this makes sure that the module search paths are set correctly independent of the `@go` function being called. This is to ensure that modules behave as expected when imported before the top-level `./go` script calls `@go`.
1 parent 8a56710 commit 41ebe94

File tree

1 file changed

+55
-46
lines changed

1 file changed

+55
-46
lines changed

tests/modules/use/plugins.bats

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PRINT_SOURCE='printf -- "%s\n" "$BASH_SOURCE"'
66

77
setup() {
88
test_filter
9-
@go.create_test_go_script '@go "$@"' \
9+
@go.create_test_go_script '. "$_GO_USE_MODULES" "$@"' \
1010
'printf "%s\n" "${_GO_IMPORTED_MODULES[@]}"'
1111
}
1212

@@ -15,129 +15,136 @@ teardown() {
1515
}
1616

1717
@test "$SUITE: plugin imports own internal module" {
18-
local module_path='foo/bin/lib/foo'
19-
@go.create_test_command_script 'plugins/foo/bin/foo' \
20-
'. "$_GO_USE_MODULES" foo'
18+
local module_path='foo/bin/lib/bar'
19+
@go.create_test_command_script 'plugins/foo/lib/foo' \
20+
'. "$_GO_USE_MODULES" bar'
2121
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
2222

23-
run "$TEST_GO_SCRIPT" 'foo'
24-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'foo/foo'
23+
run "$TEST_GO_SCRIPT" 'foo/foo'
24+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'foo/foo' 'foo/bar'
2525
}
2626

2727
@test "$SUITE: plugin imports own exported module" {
28-
local module_path='foo/lib/foo'
29-
@go.create_test_command_script 'plugins/foo/bin/foo' \
30-
'. "$_GO_USE_MODULES" foo'
28+
local module_path='foo/lib/bar'
29+
@go.create_test_command_script 'plugins/foo/lib/foo' \
30+
'. "$_GO_USE_MODULES" bar'
3131
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
3232

33-
run "$TEST_GO_SCRIPT" 'foo'
34-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'foo/foo'
33+
run "$TEST_GO_SCRIPT" 'foo/foo'
34+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'foo/foo' 'foo/bar'
3535
}
3636

3737
@test "$SUITE: plugin imports module from own plugin" {
3838
local module_path='foo/bin/plugins/bar/lib/bar'
39-
@go.create_test_command_script 'plugins/foo/bin/foo' \
39+
@go.create_test_command_script 'plugins/foo/lib/foo' \
4040
'. "$_GO_USE_MODULES" bar/bar'
4141
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
4242

43-
run "$TEST_GO_SCRIPT" 'foo'
44-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar'
43+
run "$TEST_GO_SCRIPT" 'foo/foo'
44+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'foo/foo' 'bar/bar'
4545
}
4646

4747
@test "$SUITE: plugin imports module from other plugin in _GO_PLUGINS_DIR" {
4848
local module_path='bar/lib/bar'
49-
@go.create_test_command_script 'plugins/foo/bin/foo' \
49+
@go.create_test_command_script 'plugins/foo/lib/foo' \
5050
'. "$_GO_USE_MODULES" bar/bar'
5151
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
5252

53-
run "$TEST_GO_SCRIPT" 'foo'
54-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar'
53+
run "$TEST_GO_SCRIPT" 'foo/foo'
54+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'foo/foo' 'bar/bar'
5555
}
5656

5757
@test "$SUITE: nested plugin imports own internal module" {
5858
local module_path='foo/bin/plugins/bar/bin/lib/bar-2'
59-
@go.create_test_command_script 'plugins/foo/bin/foo' \
59+
@go.create_test_command_script 'plugins/foo/lib/foo' \
6060
'. "$_GO_USE_MODULES" bar/bar'
6161
@go.create_test_command_script 'plugins/foo/bin/plugins/bar/lib/bar' \
6262
'. "$_GO_USE_MODULES" bar-2'
6363
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
6464

65-
run "$TEST_GO_SCRIPT" 'foo'
66-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar' 'bar/bar-2'
65+
run "$TEST_GO_SCRIPT" 'foo/foo'
66+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" \
67+
'foo/foo' 'bar/bar' 'bar/bar-2'
6768
}
6869

6970
@test "$SUITE: nested plugin imports own exported module" {
7071
local module_path='foo/bin/plugins/bar/lib/bar-2'
71-
@go.create_test_command_script 'plugins/foo/bin/foo' \
72+
@go.create_test_command_script 'plugins/foo/lib/foo' \
7273
'. "$_GO_USE_MODULES" bar/bar'
7374
@go.create_test_command_script 'plugins/foo/bin/plugins/bar/lib/bar' \
7475
'. "$_GO_USE_MODULES" bar-2'
7576
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
7677

77-
run "$TEST_GO_SCRIPT" 'foo'
78-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar' 'bar/bar-2'
78+
run "$TEST_GO_SCRIPT" 'foo/foo'
79+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" \
80+
'foo/foo' 'bar/bar' 'bar/bar-2'
7981
}
8082

8183
@test "$SUITE: nested plugin imports module from own plugin" {
8284
local module_path='foo/bin/plugins/bar/bin/plugins/baz/lib/baz'
83-
@go.create_test_command_script 'plugins/foo/bin/foo' \
85+
@go.create_test_command_script 'plugins/foo/lib/foo' \
8486
'. "$_GO_USE_MODULES" bar/bar'
8587
@go.create_test_command_script 'plugins/foo/bin/plugins/bar/lib/bar' \
8688
'. "$_GO_USE_MODULES" baz/baz'
8789
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
8890

89-
run "$TEST_GO_SCRIPT" 'foo'
90-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar' 'baz/baz'
91+
run "$TEST_GO_SCRIPT" 'foo/foo'
92+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" \
93+
'foo/foo' 'bar/bar' 'baz/baz'
9194
}
9295

9396
@test "$SUITE: nested plugin imports own module instead of parent module" {
9497
local module_path='foo/bin/plugins/bar/lib/bar-2'
95-
@go.create_test_command_script 'plugins/foo/bin/foo' \
98+
@go.create_test_command_script 'plugins/foo/lib/foo' \
9699
'. "$_GO_USE_MODULES" bar/bar'
97100
@go.create_test_command_script 'plugins/foo/bin/plugins/bar/lib/bar' \
98101
'. "$_GO_USE_MODULES" bar-2'
99102
@go.create_test_command_script "plugins/foo/lib/bar-2" "$PRINT_SOURCE"
100103
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
101104

102-
run "$TEST_GO_SCRIPT" 'foo'
103-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar' 'bar/bar-2'
105+
run "$TEST_GO_SCRIPT" 'foo/foo'
106+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" \
107+
'foo/foo' 'bar/bar' 'bar/bar-2'
104108
}
105109

106110
@test "$SUITE: nested plugin imports module from parent plugin" {
107-
local module_path='foo/lib/foo'
108-
@go.create_test_command_script 'plugins/foo/bin/foo' \
111+
local module_path='foo/lib/baz'
112+
@go.create_test_command_script 'plugins/foo/lib/foo' \
109113
'. "$_GO_USE_MODULES" bar/bar'
110114
@go.create_test_command_script 'plugins/foo/bin/plugins/bar/lib/bar' \
111-
'. "$_GO_USE_MODULES" foo/foo'
115+
'. "$_GO_USE_MODULES" foo/baz'
112116
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
113117

114-
run "$TEST_GO_SCRIPT" 'foo'
115-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar' 'foo/foo'
118+
run "$TEST_GO_SCRIPT" 'foo/foo'
119+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" \
120+
'foo/foo' 'bar/bar' 'foo/baz'
116121
}
117122

118123
@test "$SUITE: nested plugin imports module from _GO_PLUGINS_DIR" {
119124
local module_path='baz/lib/baz'
120-
@go.create_test_command_script 'plugins/foo/bin/foo' \
125+
@go.create_test_command_script 'plugins/foo/lib/foo' \
121126
'. "$_GO_USE_MODULES" bar/bar'
122127
@go.create_test_command_script 'plugins/foo/bin/plugins/bar/lib/bar' \
123128
'. "$_GO_USE_MODULES" baz/baz'
124129
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
125130

126-
run "$TEST_GO_SCRIPT" 'foo'
127-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar' 'baz/baz'
131+
run "$TEST_GO_SCRIPT" 'foo/foo'
132+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" \
133+
'foo/foo' 'bar/bar' 'baz/baz'
128134
}
129135

130136
@test "$SUITE: nested plugin imports own module before _GO_PLUGINS_DIR copy" {
131137
local module_path='foo/bin/plugins/bar/bin/plugins/baz/lib/baz'
132-
@go.create_test_command_script 'plugins/foo/bin/foo' \
138+
@go.create_test_command_script 'plugins/foo/lib/foo' \
133139
'. "$_GO_USE_MODULES" bar/bar'
134140
@go.create_test_command_script 'plugins/foo/bin/plugins/bar/lib/bar' \
135141
'. "$_GO_USE_MODULES" baz/baz'
136142
@go.create_test_command_script 'plugins/baz/lib/baz' "$PRINT_SOURCE"
137143
@go.create_test_command_script "plugins/$module_path" "$PRINT_SOURCE"
138144

139-
run "$TEST_GO_SCRIPT" 'foo'
140-
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" 'bar/bar' 'baz/baz'
145+
run "$TEST_GO_SCRIPT" 'foo/foo'
146+
assert_success "$TEST_GO_PLUGINS_DIR/$module_path" \
147+
'foo/foo' 'bar/bar' 'baz/baz'
141148
}
142149

143150
@test "$SUITE: module collision produces warning message, top level first" {
@@ -149,11 +156,11 @@ teardown() {
149156
@go.create_test_command_script "plugins/$top_module_path" "$PRINT_SOURCE"
150157
@go.create_test_command_script "plugins/$nested_module_path" "$PRINT_SOURCE"
151158

152-
@go.create_test_command_script 'plugins/foo/bin/foo' \
159+
@go.create_test_command_script 'plugins/foo/lib/foo' \
153160
'. "$_GO_USE_MODULES" baz/baz bar/bar'
154-
run "$TEST_GO_SCRIPT" 'foo'
161+
run "$TEST_GO_SCRIPT" 'foo/foo'
155162

156-
local parent_importer="$TEST_GO_PLUGINS_DIR/foo/bin/foo:2"
163+
local parent_importer="$TEST_GO_PLUGINS_DIR/foo/lib/foo:2"
157164
local nested_importer="$TEST_GO_PLUGINS_DIR/foo/bin/plugins/bar/lib/bar:2"
158165
assert_success
159166
assert_lines_equal "$TEST_GO_PLUGINS_DIR/$top_module_path" \
@@ -162,6 +169,7 @@ teardown() {
162169
"from file: $TEST_GO_PLUGINS_DIR/$nested_module_path" \
163170
"previously imported at: $parent_importer source" \
164171
"from file: $TEST_GO_PLUGINS_DIR/$top_module_path" \
172+
'foo/foo' \
165173
'baz/baz' \
166174
'bar/bar'
167175
}
@@ -175,11 +183,11 @@ teardown() {
175183
@go.create_test_command_script "plugins/$top_module_path" "$PRINT_SOURCE"
176184
@go.create_test_command_script "plugins/$nested_module_path" "$PRINT_SOURCE"
177185

178-
@go.create_test_command_script 'plugins/foo/bin/foo' \
186+
@go.create_test_command_script 'plugins/foo/lib/foo' \
179187
'. "$_GO_USE_MODULES" bar/bar baz/baz'
180-
run "$TEST_GO_SCRIPT" 'foo'
188+
run "$TEST_GO_SCRIPT" 'foo/foo'
181189

182-
local parent_importer="$TEST_GO_PLUGINS_DIR/foo/bin/foo:2"
190+
local parent_importer="$TEST_GO_PLUGINS_DIR/foo/lib/foo:2"
183191
local nested_importer="$TEST_GO_PLUGINS_DIR/foo/bin/plugins/bar/lib/bar:2"
184192
assert_success
185193
assert_lines_equal "$TEST_GO_PLUGINS_DIR/$nested_module_path" \
@@ -188,6 +196,7 @@ teardown() {
188196
"from file: $TEST_GO_PLUGINS_DIR/$top_module_path" \
189197
"previously imported at: $nested_importer source" \
190198
"from file: $TEST_GO_PLUGINS_DIR/$nested_module_path" \
199+
'foo/foo' \
191200
'bar/bar' \
192201
'baz/baz'
193202
}

0 commit comments

Comments
 (0)