Ensure goenv and go play together well
This PR seeks to address several issues surrounding the go and goenv plugins. The nature of goenv allows for a situation where the initial shell does not point to a working go binary, and instead at the included shim script. The result is that one must run reload after moving to a project directory with a version file, however in doing so, PATH is updated, requiring they exit the shell or risk lookup collisions and unexpected behavior. This is solved by using preexec to check the version before changing directories and restarting the shell if the version has changed. The exec pattern is copied from _bash-it-restart, but is edited to support this specific use case. Additionally, tests have been uploaded and these are now being linted.
This commit is contained in:
@@ -4,57 +4,51 @@ load ../test_helper
|
||||
load ../../lib/helpers
|
||||
load ../../lib/composure
|
||||
|
||||
@test 'ensure _go_pathmunge_wrap is defined' {
|
||||
@test 'ensure _bash-it-gopath-pathmunge is defined' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
load ../../plugins/available/go.plugin
|
||||
run type -t _go_pathmunge_wrap
|
||||
run type -t _bash-it-gopath-pathmunge
|
||||
assert_line 'function'
|
||||
}
|
||||
|
||||
@test 'plugins go: single entry in GOPATH' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: single entry in GOPATH, with space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: single entry in GOPATH, with escaped space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo\ bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo\ bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
export GOPATH="/foo:/bar"
|
||||
export GOROOT="/baz"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1,2,3 <<<$PATH)" "/foo/bin:/bar/bin:/baz/bin"
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH, with space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
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"
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo bar/bin"
|
||||
}
|
||||
|
||||
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
|
||||
{ [[ $CI ]] || _command_exists go; } || skip 'golang not found'
|
||||
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"
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "/foo/bin:/foo\ bar/bin"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user