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
|
cite about-plugin
|
||||||
about-plugin 'go environment variables & path configuration'
|
about-plugin 'go environment variables & path configuration'
|
||||||
|
|
||||||
[ ! command -v go &>/dev/null ] && return
|
command -v go &>/dev/null || return
|
||||||
|
|
||||||
function _split_path_reverse() {
|
function _go_pathmunge_wrap() {
|
||||||
local a=( ${@//:/ } )
|
IFS=':' local -a 'a=($1)'
|
||||||
local i=${#a[@]}
|
local i=${#a[@]}
|
||||||
local r=
|
|
||||||
while [ $i -gt 0 ] ; do
|
while [ $i -gt 0 ] ; do
|
||||||
i=$(( i - 1 ))
|
i=$(( i - 1 ))
|
||||||
if [ $(( i + 1 )) -eq ${#a[@]} ] ; then
|
pathmunge "${a[i]}/bin"
|
||||||
r="${a[i]}"
|
|
||||||
else
|
|
||||||
r="${r} ${a[i]}"
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
echo "$r"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export GOROOT=${GOROOT:-$(go env GOROOT)}
|
export GOROOT="${GOROOT:-$(go env GOROOT)}"
|
||||||
pathmunge "${GOROOT}/bin"
|
export GOPATH="${GOPATH:-$(go env GOPATH)}"
|
||||||
|
_go_pathmunge_wrap "${GOPATH}:${GOROOT}"
|
||||||
export GOPATH=${GOPATH:-$(go env GOPATH)}
|
|
||||||
for p in $( _split_path_reverse ${GOPATH} ) ; do
|
|
||||||
pathmunge "${p}/bin"
|
|
||||||
done
|
|
||||||
|
|
|
||||||
|
|
@ -1,44 +1,53 @@
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
#load ../test_helper
|
load ../test_helper
|
||||||
load ../../lib/helpers
|
load ../../lib/helpers
|
||||||
load ../../lib/composure
|
load ../../lib/composure
|
||||||
load ../../plugins/available/go.plugin
|
|
||||||
|
|
||||||
@test 'plugins go: reverse path: single entry' {
|
@test 'ensure _go_pathmunge_wrap is defined' {
|
||||||
run _split_path_reverse '/foo'
|
load ../../plugins/available/go.plugin
|
||||||
echo "output = ${output}"
|
run type -t _go_pathmunge_wrap
|
||||||
[ "$output" = "/foo" ]
|
assert_line 'function'
|
||||||
}
|
|
||||||
|
|
||||||
@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 'plugins go: single entry in GOPATH' {
|
@test 'plugins go: single entry in GOPATH' {
|
||||||
export GOPATH="/foo"
|
export GOPATH="/foo"
|
||||||
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
echo "$(echo $PATH | cut -d':' -f1,2)"
|
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/baz/bin"
|
||||||
[ "$(echo $PATH | cut -d':' -f1)" = "/foo/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' {
|
@test 'plugins go: multiple entries in GOPATH' {
|
||||||
export GOPATH="/foo:/bar"
|
export GOPATH="/foo:/bar"
|
||||||
|
export GOROOT="/baz"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
echo "$(echo $PATH | cut -d':' -f1,2)"
|
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/bar/bin:/baz/bin"
|
||||||
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/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