simplify wrapped pathmunge logic. update tests to account for cases with spaces in $PATH.
parent
7f34570a05
commit
177730de96
|
|
@ -5,25 +5,15 @@ 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,76 @@
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
#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' {
|
|
||||||
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 'plugins go: single entry in GOPATH' {
|
@test 'plugins go: single entry in GOPATH' {
|
||||||
|
export GOROOT="/baz"
|
||||||
export GOPATH="/foo"
|
export GOPATH="/foo"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
echo "$(echo $PATH | cut -d':' -f1,2)"
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f1)"
|
||||||
[ "$(echo $PATH | cut -d':' -f1)" = "/foo/bin" ]
|
[ "$(echo $PATH | cut -d':' -f1)" = "/foo/bin" ]
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f2)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f2)" = "/baz/bin" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: single entry in GOPATH, with space' {
|
||||||
|
export GOROOT="/baz"
|
||||||
|
export GOPATH="/foo bar"
|
||||||
|
load ../../plugins/available/go.plugin
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f1)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f1)" = "/foo bar/bin" ]
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f2)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f2)" = "/baz/bin" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: single entry in GOPATH, with escaped space' {
|
||||||
|
export GOROOT="/baz"
|
||||||
|
export GOPATH="/foo\ bar"
|
||||||
|
load ../../plugins/available/go.plugin
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f1)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f1)" = "/foo\ bar/bin" ]
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f2)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f2)" = "/baz/bin" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test 'plugins go: multiple entries in GOPATH' {
|
@test 'plugins go: multiple entries in GOPATH' {
|
||||||
|
export GOROOT="/baz"
|
||||||
export GOPATH="/foo:/bar"
|
export GOPATH="/foo:/bar"
|
||||||
load ../../plugins/available/go.plugin
|
load ../../plugins/available/go.plugin
|
||||||
|
|
||||||
echo "$(echo $PATH | cut -d':' -f1,2)"
|
echo "$(echo $PATH | cut -d':' -f1,2)"
|
||||||
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/bin" ]
|
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/bin" ]
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f3)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f3)" = "/baz/bin" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: multiple entries in GOPATH, with space' {
|
||||||
|
export GOROOT="/baz"
|
||||||
|
export GOPATH="/foo:/foo bar"
|
||||||
|
load ../../plugins/available/go.plugin
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f1,2)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/foo bar/bin" ]
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f3)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f3)" = "/baz/bin" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
|
||||||
|
export GOROOT="/baz"
|
||||||
|
export GOPATH="/foo:/foo\ bar"
|
||||||
|
load ../../plugins/available/go.plugin
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f1,2)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/foo\ bar/bin" ]
|
||||||
|
|
||||||
|
echo "$(echo $PATH | cut -d':' -f3)"
|
||||||
|
[ "$(echo $PATH | cut -d':' -f3)" = "/baz/bin" ]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue