Simplify multiple path support in go plugin (#1284)
* simplify wrapped pathmunge logic. update tests to account for cases with spaces in $PATH.pull/1438/head
parent
9d6bb73356
commit
377f02714d
|
|
@ -3,27 +3,17 @@
|
|||
cite about-plugin
|
||||
about-plugin 'go environment variables & path configuration'
|
||||
|
||||
[ ! command -v go &>/dev/null ] && return
|
||||
command -v go &>/dev/null || return
|
||||
|
||||
function _split_path_reverse() {
|
||||
local a=( ${@//:/ } )
|
||||
function _go_pathmunge_wrap() {
|
||||
IFS=':' local -a 'a=($1)'
|
||||
local i=${#a[@]}
|
||||
local r=
|
||||
while [ $i -gt 0 ] ; do
|
||||
i=$(( i - 1 ))
|
||||
if [ $(( i + 1 )) -eq ${#a[@]} ] ; then
|
||||
r="${a[i]}"
|
||||
else
|
||||
r="${r} ${a[i]}"
|
||||
fi
|
||||
pathmunge "${a[i]}/bin"
|
||||
done
|
||||
echo "$r"
|
||||
}
|
||||
|
||||
export GOROOT=${GOROOT:-$(go env GOROOT)}
|
||||
pathmunge "${GOROOT}/bin"
|
||||
|
||||
export GOPATH=${GOPATH:-$(go env GOPATH)}
|
||||
for p in $( _split_path_reverse ${GOPATH} ) ; do
|
||||
pathmunge "${p}/bin"
|
||||
done
|
||||
export GOROOT="${GOROOT:-$(go env GOROOT)}"
|
||||
export GOPATH="${GOPATH:-$(go env GOPATH)}"
|
||||
_go_pathmunge_wrap "${GOPATH}:${GOROOT}"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue