add go plugin tests and update list reversal logic

This commit is contained in:
cornfeedhobo
2018-12-06 17:07:03 -05:00
parent 4ff305c009
commit 3645305644
2 changed files with 46 additions and 2 deletions

View File

@@ -6,9 +6,16 @@ about-plugin 'go environment variables & path configuration'
[ ! command -v go &>/dev/null ] && return
function _split_path_reverse() {
local a=( ${@//:/ } )
local i=${#a[@]}
local r=
for p in ${@//:/ } ; do
r="$p $r"
while [ $i -gt 0 ] ; do
i=$(( i - 1 ))
if [ $(( i + 1 )) -eq ${#a[@]} ] ; then
r="${a[i]}"
else
r="${r} ${a[i]}"
fi
done
echo "$r"
}

View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bats
#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 'plugins go: multiple entries in GOPATH' {
export GOPATH="/foo:/bar"
load ../../plugins/available/go.plugin
echo "$(echo $PATH | cut -d':' -f1,2)"
[ "$(echo $PATH | cut -d':' -f1,2)" = "/foo/bin:/bar/bin" ]
}