Merge pull request #1934 from gaelicWizard/helpers
lib/helpers: lint, cleanup, & improvementspull/2034/head
commit
7e54aea8c7
|
|
@ -78,6 +78,7 @@ completion/available/vuejs.completion.bash
|
|||
completion/available/wpscan.completion.bash
|
||||
|
||||
# libraries
|
||||
lib/helpers.bash
|
||||
lib/log.bash
|
||||
lib/utilities.bash
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -168,12 +168,18 @@ function _bash-it-component-list-disabled() {
|
|||
# Examples:
|
||||
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
|
||||
function _bash-it-component-item-is-enabled() {
|
||||
local component="$1" item="$2"
|
||||
local each_file
|
||||
local component_type item_name each_file
|
||||
|
||||
for each_file in "${BASH_IT}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item}.${component}"*."bash" \
|
||||
"${BASH_IT}/${component}"*/"enabled/${item}.${component}"*."bash" \
|
||||
"${BASH_IT}/${component}"*/"enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item}.${component}"*."bash"; do
|
||||
if [[ -f "${1}" ]]; then
|
||||
item_name="$(_bash-it-get-component-name-from-path "${1}")"
|
||||
component_type="$(_bash-it-get-component-type-from-path "${1}")"
|
||||
else
|
||||
component_type="${1}" item_name="${2}"
|
||||
fi
|
||||
|
||||
for each_file in "${BASH_IT}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash" \
|
||||
"${BASH_IT}/${component_type}"*/"enabled/${item_name}.${component_type}"*."bash" \
|
||||
"${BASH_IT}/${component_type}"*/"enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash"; do
|
||||
[[ -f "${each_file}" ]] && return
|
||||
done
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
load ../test_helper
|
||||
load ../test_helper_libs
|
||||
load ../../plugins/available/base.plugin
|
||||
load ../../themes/colors.theme
|
||||
|
||||
function local_setup {
|
||||
setup_test_fixture
|
||||
|
|
@ -289,8 +290,9 @@ function local_setup {
|
|||
assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash"
|
||||
}
|
||||
|
||||
@test "helper: profile load command sanity" {
|
||||
@test "helpers: profile load command sanity" {
|
||||
run _bash-it-profile-load "default"
|
||||
assert_success
|
||||
|
||||
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
||||
assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash"
|
||||
|
|
@ -299,7 +301,7 @@ function local_setup {
|
|||
assert_link_exist "$BASH_IT/enabled/325---system.completion.bash"
|
||||
}
|
||||
|
||||
@test "helper: profile save command sanity" {
|
||||
@test "helpers: profile save command sanity" {
|
||||
run _enable-plugin "nvm"
|
||||
|
||||
run _bash-it-profile-save "test"
|
||||
|
|
@ -310,7 +312,7 @@ function local_setup {
|
|||
assert_file_exist "$BASH_IT/profiles/test.bash_it"
|
||||
}
|
||||
|
||||
@test "helper: profile save creates valid file with only plugin enabled" {
|
||||
@test "helpers: profile save creates valid file with only plugin enabled" {
|
||||
run _enable-plugin "nvm"
|
||||
|
||||
run _bash-it-profile-save "test"
|
||||
|
|
@ -320,7 +322,7 @@ function local_setup {
|
|||
assert_line -n 2 "plugins nvm"
|
||||
}
|
||||
|
||||
@test "helper: profile save creates valid file with only completion enabled" {
|
||||
@test "helpers: profile save creates valid file with only completion enabled" {
|
||||
run _enable-completion "bash-it"
|
||||
|
||||
run _bash-it-profile-save "test"
|
||||
|
|
@ -330,7 +332,7 @@ function local_setup {
|
|||
assert_line -n 2 "completion bash-it"
|
||||
}
|
||||
|
||||
@test "helper: profile save creates valid file with only aliases enabled" {
|
||||
@test "helpers: profile save creates valid file with only aliases enabled" {
|
||||
run _enable-alias "general"
|
||||
|
||||
run _bash-it-profile-save "test"
|
||||
|
|
@ -340,7 +342,7 @@ function local_setup {
|
|||
assert_line -n 2 "aliases general"
|
||||
}
|
||||
|
||||
@test "helper: profile edge case, empty configuration" {
|
||||
@test "helpers: profile edge case, empty configuration" {
|
||||
run _bash-it-profile-save "test"
|
||||
assert_line -n 3 "It seems like no configuration was enabled.."
|
||||
assert_line -n 4 "Make sure to double check that this is the wanted behavior."
|
||||
|
|
@ -359,7 +361,7 @@ function local_setup {
|
|||
assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash"
|
||||
}
|
||||
|
||||
@test "helper: profile save and load" {
|
||||
@test "helpers: profile save and load" {
|
||||
run _enable-alias "general"
|
||||
run _enable-plugin "base"
|
||||
run _enable-plugin "alias-completion"
|
||||
|
|
@ -375,52 +377,52 @@ function local_setup {
|
|||
assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash"
|
||||
}
|
||||
|
||||
@test "helper: profile load corrupted profile file: bad component" {
|
||||
@test "helpers: profile load corrupted profile file: bad component" {
|
||||
run _bash-it-profile-load "test-bad-component"
|
||||
assert_line -n 1 -p "Bad line(#12) in profile, aborting load..."
|
||||
}
|
||||
|
||||
@test "helper: profile load corrupted profile file: bad subdirectory" {
|
||||
@test "helpers: profile load corrupted profile file: bad subdirectory" {
|
||||
run _bash-it-profile-load "test-bad-type"
|
||||
assert_line -n 1 -p "Bad line(#5) in profile, aborting load..."
|
||||
}
|
||||
|
||||
@test "helper: profile rm sanity" {
|
||||
@test "helpers: profile rm sanity" {
|
||||
run _bash-it-profile-save "test"
|
||||
assert_file_exist "$BASH_IT/profiles/test.bash_it"
|
||||
run _bash-it-profile-rm "test"
|
||||
assert_line -n 0 "Removed profile \"test\" successfully!"
|
||||
assert_line -n 0 "Removed profile 'test' successfully!"
|
||||
assert_file_not_exist "$BASH_IT/profiles/test.bash_it"
|
||||
}
|
||||
|
||||
@test "helper: profile rm no params" {
|
||||
@test "helpers: profile rm no params" {
|
||||
run _bash-it-profile-rm ""
|
||||
assert_line -n 0 -p "Please specify profile name to remove..."
|
||||
}
|
||||
|
||||
@test "helper: profile load no params" {
|
||||
@test "helpers: profile load no params" {
|
||||
run _bash-it-profile-load ""
|
||||
assert_line -n 0 -p "Please specify profile name to load, not changing configuration..."
|
||||
}
|
||||
|
||||
@test "helper: profile rm default" {
|
||||
@test "helpers: profile rm default" {
|
||||
run _bash-it-profile-rm "default"
|
||||
assert_line -n 0 -p "Can not remove the default profile..."
|
||||
assert_file_exist "$BASH_IT/profiles/default.bash_it"
|
||||
}
|
||||
|
||||
@test "helper: profile rm bad profile name" {
|
||||
@test "helpers: profile rm bad profile name" {
|
||||
run _bash-it-profile-rm "notexisting"
|
||||
assert_line -n 0 -p "Could not find profile \"notexisting\"..."
|
||||
assert_line -n 0 -p "Could not find profile 'notexisting'..."
|
||||
}
|
||||
|
||||
@test "helper: profile list sanity" {
|
||||
@test "helpers: profile list sanity" {
|
||||
run _bash-it-profile-list
|
||||
assert_line -n 0 "Available profiles:"
|
||||
assert_line -n 1 "default"
|
||||
}
|
||||
|
||||
@test "helper: profile list more profiles" {
|
||||
@test "helpers: profile list more profiles" {
|
||||
run _bash-it-profile-save "cactus"
|
||||
run _bash-it-profile-save "another"
|
||||
run _bash-it-profile-save "brother"
|
||||
|
|
@ -732,5 +734,5 @@ function __migrate_all_components() {
|
|||
|
||||
@test "helpers: describe the todo.txt-cli aliases without enabling them" {
|
||||
run _bash-it-aliases
|
||||
assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations"
|
||||
assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,22 @@
|
|||
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' {
|
||||
|
|
@ -14,42 +30,47 @@ load ../test_helper_libs
|
|||
|
||||
@test 'plugins go: single entry in GOPATH' {
|
||||
{ _command_exists go && go version &>/dev/null; } || skip 'golang not found'
|
||||
export GOPATH="/foo"
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/gopath"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo/bin"
|
||||
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'
|
||||
export GOPATH="/foo bar"
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/go path"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo bar/bin"
|
||||
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'
|
||||
export GOPATH="/foo\ bar"
|
||||
setup_go_path "$BASH_IT/test/fixtures/go/go\ path"
|
||||
load ../../plugins/available/go.plugin
|
||||
assert_equal "$(cut -d':' -f1 <<<$PATH)" "/foo\ bar/bin"
|
||||
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'
|
||||
export GOPATH="/foo:/bar"
|
||||
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)" "/foo/bin:/bar/bin"
|
||||
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'
|
||||
export GOPATH="/foo:/foo bar"
|
||||
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)" "/foo/bin:/foo bar/bin"
|
||||
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'
|
||||
export GOPATH="/foo:/foo\ bar"
|
||||
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)" "/foo/bin:/foo\ bar/bin"
|
||||
assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ load ../test_helper_libs
|
|||
function local_setup {
|
||||
setup_test_fixture
|
||||
|
||||
_command_exists "ruby" && mkdir -p "$(ruby -e 'print Gem.user_dir')/bin"
|
||||
|
||||
export OLD_PATH="$PATH"
|
||||
export PATH="/usr/bin:/bin:/usr/sbin"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue