Simplify multiple path support in go plugin (#1284)

* simplify wrapped pathmunge logic. update tests to account for cases with spaces in $PATH.
This commit is contained in:
cornfeedhobo
2019-11-20 01:49:34 -06:00
committed by Nils Winkler
parent 9d6bb73356
commit 377f02714d
2 changed files with 44 additions and 45 deletions

View File

@@ -1,44 +1,53 @@
#!/usr/bin/env bats
#load ../test_helper
load ../test_helper
load ../../lib/helpers
load ../../lib/composure
load ../../plugins/available/go.plugin
@test 'plugins go: reverse path: single entry' {
run _split_path_reverse '/foo'
echo "output = ${output}"
[ "$output" = "/foo" ]
}
@test 'plugins go: reverse path: single entry, colon empty' {
run _split_path_reverse '/foo:'
echo "output = ${output}"
[ "$output" = "/foo" ]
}
@test 'plugins go: reverse path: single entry, colon whitespace' {
run _split_path_reverse '/foo: '
echo "output = ${output}"
[ "$output" = "/foo" ]
}
@test 'plugins go: reverse path: multiple entries' {
run _split_path_reverse '/foo:/bar'
echo "output = ${output}"
[ "$output" = "/bar /foo" ]
@test 'ensure _go_pathmunge_wrap is defined' {
load ../../plugins/available/go.plugin
run type -t _go_pathmunge_wrap
assert_line 'function'
}
@test 'plugins go: single entry in GOPATH' {
export GOPATH="/foo"
export GOROOT="/baz"
load ../../plugins/available/go.plugin
echo "$(echo $PATH | cut -d':' -f1,2)"
[ "$(echo $PATH | cut -d':' -f1)" = "/foo/bin" ]
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/baz/bin"
}
@test 'plugins go: single entry in GOPATH, with space' {
export GOPATH="/foo bar"
export GOROOT="/baz"
load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo bar/bin:/baz/bin"
}
@test 'plugins go: single entry in GOPATH, with escaped space' {
export GOPATH="/foo\ bar"
export GOROOT="/baz"
load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo\ bar/bin:/baz/bin"
}
@test 'plugins go: multiple entries in GOPATH' {
export GOPATH="/foo:/bar"
export GOROOT="/baz"
load ../../plugins/available/go.plugin
echo "$(echo $PATH | cut -d':' -f1,2)"
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/bin" ]
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/bar/bin:/baz/bin"
}
@test 'plugins go: multiple entries in GOPATH, with space' {
export GOPATH="/foo:/foo bar"
export GOROOT="/baz"
load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/foo bar/bin:/baz/bin"
}
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
export GOPATH="/foo:/foo\ bar"
export GOROOT="/baz"
load ../../plugins/available/go.plugin
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/foo\ bar/bin:/baz/bin"
}