Quote things, SC2268, SC2143, SC2181, SC2162, SC2016, SC2013, &c. Rewrite globbing per `shellcheck`’s SC2013, and alsö s/typeset/local/g. Eliminate `compgen` where possible. Alsö: use the existing utility functions `_bash-it-get-component-type-from-path` and `_bash-it-get-component-name-from-path`, which just use parameter substitution anyway. Why was `sed` here? Alsö, don't add not-existing directories to `$PATH` in `pathmunge()`. Finally, merge PR #1865 from NoahGorny...and clean it a bit...
77 lines
2.8 KiB
Bash
77 lines
2.8 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load ../test_helper
|
|
load ../test_helper_libs
|
|
|
|
function local_setup()
|
|
{
|
|
setup_test_fixture
|
|
}
|
|
|
|
function setup_go_path()
|
|
{
|
|
local go_path="$1"
|
|
|
|
# Make sure that the requested GO folder is available
|
|
assert_dir_exist "$go_path/bin"
|
|
|
|
# Make sure that the requested GO folder is on the path
|
|
export GOPATH="$go_path:${GOPATH:-}"
|
|
}
|
|
|
|
# We test `go version` in each test to account for users with goenv and no system go.
|
|
|
|
@test 'ensure _bash-it-gopath-pathmunge is defined' {
|
|
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
|
load ../../plugins/available/go.plugin
|
|
run type -t _bash-it-gopath-pathmunge
|
|
assert_line 'function'
|
|
}
|
|
|
|
@test 'plugins go: single entry in GOPATH' {
|
|
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
|
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
|
|
load ../../plugins/available/go.plugin
|
|
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath/bin"
|
|
}
|
|
|
|
@test 'plugins go: single entry in GOPATH, with space' {
|
|
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
|
setup_go_path "$BASH_IT/test/fixtures/go/go path"
|
|
load ../../plugins/available/go.plugin
|
|
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin"
|
|
}
|
|
|
|
@test 'plugins go: single entry in GOPATH, with escaped space' {
|
|
skip 'huh?'
|
|
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
|
setup_go_path "$BASH_IT/test/fixtures/go/go\ path"
|
|
load ../../plugins/available/go.plugin
|
|
assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin"
|
|
}
|
|
|
|
@test 'plugins go: multiple entries in GOPATH' {
|
|
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
|
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
|
|
setup_go_path "$BASH_IT/test/fixtures/go/gopath2"
|
|
load ../../plugins/available/go.plugin
|
|
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin"
|
|
}
|
|
|
|
@test 'plugins go: multiple entries in GOPATH, with space' {
|
|
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
|
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
|
|
setup_go_path "$BASH_IT/test/fixtures/go/go path"
|
|
load ../../plugins/available/go.plugin
|
|
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
|
|
}
|
|
|
|
@test 'plugins go: multiple entries in GOPATH, with escaped space' {
|
|
skip 'huh?'
|
|
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
|
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
|
|
setup_go_path "$BASH_IT/test/fixtures/go/go path"
|
|
load ../../plugins/available/go.plugin
|
|
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
|
|
}
|