From 4ff305c009c9fb74b66aece0c8e786dbcd3bd55c Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Fri, 9 Nov 2018 18:55:19 -0500 Subject: [PATCH 1/3] add multiple path support to go plugin --- plugins/available/go.plugin.bash | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 827ac388..819ebc3a 100755 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -5,7 +5,18 @@ about-plugin 'go environment variables & path configuration' [ ! command -v go &>/dev/null ] && return +function _split_path_reverse() { + local r= + for p in ${@//:/ } ; do + r="$p $r" + done + echo "$r" +} + export GOROOT=${GOROOT:-$(go env GOROOT)} pathmunge "${GOROOT}/bin" + export GOPATH=${GOPATH:-$(go env GOPATH)} -pathmunge "${GOPATH}/bin" +for p in $( _split_path_reverse ${GOPATH} ) ; do + pathmunge "${p}/bin" +done From 3645305644ff62f217c3a68713adba3dcddd3e45 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Thu, 6 Dec 2018 17:07:03 -0500 Subject: [PATCH 2/3] add go plugin tests and update list reversal logic --- plugins/available/go.plugin.bash | 11 ++++++++-- test/plugins/go.plugin.bats | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 test/plugins/go.plugin.bats diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 819ebc3a..910194e5 100755 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -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" } diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats new file mode 100644 index 00000000..0cc257ed --- /dev/null +++ b/test/plugins/go.plugin.bats @@ -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" ] +} From 1030c0e9e1ccaddbeb21c9b12b60649921f64e61 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Thu, 6 Dec 2018 17:11:13 -0500 Subject: [PATCH 3/3] one more test ... why not --- test/plugins/go.plugin.bats | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index 0cc257ed..e2b27e02 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -29,6 +29,13 @@ load ../../plugins/available/go.plugin [ "$output" = "/bar /foo" ] } +@test 'plugins go: single entry in GOPATH' { + export GOPATH="/foo" + load ../../plugins/available/go.plugin + echo "$(echo $PATH | cut -d':' -f1,2)" + [ "$(echo $PATH | cut -d':' -f1)" = "/foo/bin" ] +} + @test 'plugins go: multiple entries in GOPATH' { export GOPATH="/foo:/bar" load ../../plugins/available/go.plugin