@@ -141,14 +141,94 @@ teardown() {
141141 assert_success " $TEST_GO_SCRIPTS_DIR /plugins/baz/bin/baz"
142142}
143143
144- @test " $SUITE : nested plugins dir doesn't leak to sibling plugin" {
145- @go.create_test_command_script ' plugins/foo/bin/foo' ' @go bar'
146- @go.create_test_command_script ' plugins/foo/bin/plugins/bar/bin/bar' ' @go baz'
147- @go.create_test_command_script ' plugins/foo/bin/plugins/quux/bin/quux' \
144+ @test " $SUITE : plugin doesn't leak own plugins to sibling plugin" {
145+ @go.create_test_command_script ' plugins/foo/bin/foo' ' @go baz'
146+ @go.create_test_command_script ' plugins/bar/bin/bar' ' @go foo'
147+ @go.create_test_command_script ' plugins/bar/bin/plugins/baz/bin/baz' \
148+ " $PRINT_SOURCE "
149+
150+ run " $TEST_GO_SCRIPT " ' bar'
151+ assert_failure
152+ assert_line_equals 0 ' Unknown command: baz'
153+ }
154+
155+ @test " $SUITE : plugin doesn't leak own plugins to parent plugin" {
156+ @go.create_test_command_script ' plugins/foo/bin/foo' ' @go baz'
157+ @go.create_test_command_script ' plugins/foo/bin/bar' ' @go quux'
158+ @go.create_test_command_script ' plugins/foo/bin/plugins/baz/bin/baz' ' @go bar'
159+ @go.create_test_command_script \
160+ ' plugins/foo/bin/plugins/baz/bin/plugins/quux/bin/quux' \
148161 " $PRINT_SOURCE "
149- @go.create_test_command_script ' plugins/baz/bin/baz' ' @go quux'
150162
151163 run " $TEST_GO_SCRIPT " ' foo'
152164 assert_failure
153165 assert_line_equals 0 ' Unknown command: quux'
154166}
167+
168+ @test " $SUITE : non-plugin script when _GO_SCRIPTS_DIR contains /plugins/" {
169+ create_bats_test_script ' go' \
170+ " . '$_GO_CORE_DIR /go-core.bash' 'plugins'" \
171+ ' @go "$@"'
172+ create_bats_test_script ' plugins/foo' \
173+ ' @go.print_stack_trace 1'
174+
175+ run " $TEST_GO_SCRIPT " ' foo'
176+ assert_success
177+ assert_line_matches 0 \
178+ " $_GO_CORE_DIR /go-core.bash:[0-9]+ _@go.run_command_script"
179+ fail_if line_matches 1 \
180+ " $_GO_CORE_DIR /go-core.bash:[1-9]+ _@go.run_plugin_command_script"
181+ }
182+
183+ @test " $SUITE : non-plugin script when /plugins/ in relative path" {
184+ create_bats_test_script ' go' \
185+ " . '$_GO_CORE_DIR /go-core.bash' 'plugins'" \
186+ ' @go "$@"'
187+ create_bats_test_script ' plugins/plugins/foo' \
188+ ' @go.print_stack_trace 1'
189+
190+ run " $TEST_GO_SCRIPT " ' plugins/foo'
191+ assert_success
192+ assert_line_matches 0 \
193+ " $_GO_CORE_DIR /go-core.bash:[0-9]+ _@go.run_command_script"
194+ fail_if line_matches 1 \
195+ " $_GO_CORE_DIR /go-core.bash:[1-9]+ _@go.run_plugin_command_script"
196+ }
197+
198+ @test " $SUITE : script isn't a plugin if /plugins/ in _GO_ROOTDIR" {
199+ local test_rootdir=" $TEST_GO_ROOTDIR /plugins/rootdir"
200+ mkdir -p " $test_rootdir "
201+ mv " $TEST_GO_SCRIPT " " $test_rootdir "
202+
203+ # We can't use `@go.create_test_command_script` since we can't change the
204+ # readonly `TEST_GO_*` variables.
205+ create_bats_test_script " ${test_rootdir# $BATS_TEST_ROOTDIR / } /scripts/foo" \
206+ ' @go.print_stack_trace 1'
207+
208+ run " $test_rootdir /go" ' foo'
209+ assert_success
210+ assert_line_matches 0 \
211+ " $_GO_CORE_DIR /go-core.bash:[0-9]+ _@go.run_command_script"
212+ fail_if line_matches 1 \
213+ " $_GO_CORE_DIR /go-core.bash:[1-9]+ _@go.run_plugin_command_script"
214+ }
215+
216+ @test " $SUITE : script isn't a plugin despite /plugins/ paths all the way down" {
217+ local test_rootdir=" $TEST_GO_ROOTDIR /plugins/plugins"
218+ local test_scripts_dir=" $test_rootdir /plugins"
219+ mkdir -p " $test_scripts_dir /plugins"
220+
221+ create_bats_test_script " ${test_rootdir# $BATS_TEST_ROOTDIR / } /go" \
222+ " . '$_GO_CORE_DIR /go-core.bash' 'plugins'" \
223+ ' @go "$@"'
224+ create_bats_test_script \
225+ " ${test_rootdir# $BATS_TEST_ROOTDIR / } /plugins/plugins/foo" \
226+ ' @go.print_stack_trace 1'
227+
228+ run " $test_rootdir /go" ' plugins/foo'
229+ assert_success
230+ assert_line_matches 0 \
231+ " $_GO_CORE_DIR /go-core.bash:[0-9]+ _@go.run_command_script"
232+ fail_if line_matches 1 \
233+ " $_GO_CORE_DIR /go-core.bash:[1-9]+ _@go.run_plugin_command_script"
234+ }
0 commit comments