From bf811cd38e30e63e0ddd7ca5138fb4e115933b2e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 00:02:52 -0800 Subject: [PATCH 01/13] BATS: require `shellcheck` on test files BATS: add `*.bats` to `.gitattributes` --- .gitattributes | 1 + .pre-commit-config.yaml | 4 +--- hooks/dot-bash.sh | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index de622e0618..8a9080546c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ *.sh text eol=lf *.bash text eol=lf +*.bats text eol=lf # Docs allow trailing whitespaces *.md whitespace=-blank-at-eol diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af5f30afe5..8c3f35253f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,6 @@ repos: hooks: - id: git-check # Configure in .gitattributes - id: shellcheck - exclude: ".bats$" - id: shfmt exclude: ".bats$" - repo: https://github.com/Lucas-C/pre-commit-hooks @@ -38,10 +37,9 @@ repos: types: [file] - id: dot-bash name: Check .bash files against bash-it requirements - exclude: "test/test_helper.bash" entry: ./hooks/dot-bash.sh language: system - files: "\\.bash$" + files: "\\.ba[ts][sh]$" types: [file] - id: clean-files-txt name: Check that clean_files.txt is sorted alphabetically. diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh index 253cb595e4..94a03708b5 100755 --- a/hooks/dot-bash.sh +++ b/hooks/dot-bash.sh @@ -12,7 +12,8 @@ for file in "$@"; do # Confirm expected schellcheck header # LINE1="$(head -n 1 "${file}")" - if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then + SCSH="${file##*.}" + if [[ "${LINE1}" != "# shellcheck shell=${SCSH}" ]]; then echo "Bash include file \`${file}\` has bad/missing shellcheck header" exit_code=1 fi From 49b477ef3f64971047088e835cbc36f69c1f46e5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:29:04 -0800 Subject: [PATCH 02/13] test/lib: `shellcheck` --- test/lib/helpers.bats | 392 ++++++++++++++++++++++-------------------- test/lib/log.bats | 33 ++-- test/lib/preexec.bats | 16 +- test/lib/search.bats | 40 ++++- 4 files changed, 271 insertions(+), 210 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 38a917fe95..b27e775e0a 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -4,25 +4,25 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { setup_libs "colors" - load "${BASH_IT?}/plugins/available/base.plugin.bash" } function local_setup() { # Copy the test fixture to the Bash-it folder - cp -RP "$BASH_IT/test/fixtures/bash_it"/* "$BASH_IT/" + cp -RP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" } # TODO Create global __is_enabled function # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function @test "bash-it: verify that the test fixture is available" { - assert_file_exist "$BASH_IT/profiles/test-bad-component.bash_it" - assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-component.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-type.bash_it" } @test "helpers: _command_exists function exists" { - run type -a _command_exists &> /dev/null + run type -t _command_exists assert_success + assert_output "function" } @test "helpers: _command_exists function positive test ls" { @@ -41,8 +41,9 @@ function local_setup() { } @test "helpers: _binary_exists function exists" { - run type -a _binary_exists &> /dev/null + run type -t _binary_exists assert_success + assert_output "function" } @test "helpers: _binary_exists function positive test ls" { @@ -67,54 +68,54 @@ function local_setup() { @test "helpers: bash-it help aliases without any aliases enabled" { run bash-it help aliases - assert_line -n 0 "" + assert_output "" } @test "helpers: bash-it help plugins" { run bash-it help plugins - assert_line -n 1 "base:" + assert_line -n 1 "composure:" } @test "helpers: bash-it help list aliases without any aliases enabled" { - run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/available/ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with ag aliases enabled" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_line -n 0 "todo.txt-cli:" } @test "helpers: bash-it help list aliases with docker-compose aliases enabled" { - ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" assert_line -n 0 "docker-compose:" } @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in the old directory" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -123,11 +124,11 @@ function local_setup() { @test "helpers: bash-it help aliases one alias enabled in global directory" { run bash-it enable alias "ag" assert_line -n 0 'ag enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run bash-it enable plugin "aws" assert_line -n 0 'aws enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---aws.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---aws.plugin.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -137,58 +138,58 @@ function local_setup() { @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line -n 0 'todo.txt-cli enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" } @test "helpers: enable the curl aliases" { run _enable-alias "curl" assert_line -n 0 'curl enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---curl.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---curl.aliases.bash" } @test "helpers: enable the apm completion through the bash-it function" { run bash-it enable completion "apm" assert_line -n 0 'apm enabled with priority 350.' - assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---apm.completion.bash" } @test "helpers: enable the brew completion" { run _enable-completion "brew" assert_line -n 0 'brew enabled with priority 375.' - assert_link_exist "$BASH_IT/enabled/375---brew.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/375---brew.completion.bash" } @test "helpers: enable the node plugin" { run _enable-plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" } @test "helpers: enable the node plugin through the bash-it function" { run bash-it enable plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: enable the node and nvm plugins through the bash-it function" { run bash-it enable plugin "node" "nvm" assert_line -n 0 'node enabled with priority 250.' assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { run bash-it enable plugin "foo-unknown" "nvm" assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable an unknown plugin" { @@ -196,11 +197,11 @@ function local_setup() { assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure - assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: enable an unknown plugin through the bash-it function" { @@ -209,11 +210,11 @@ function local_setup() { assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure - assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: disable a plugin that is not enabled" { @@ -224,75 +225,75 @@ function local_setup() { @test "helpers: enable and disable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled without a priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled without a priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin twice" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @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" - assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save command sanity" { @@ -303,14 +304,14 @@ function local_setup() { assert_line -n 1 "Saving completion configuration..." assert_line -n 2 "Saving aliases configuration..." assert_line -n 3 "All done!" - assert_file_exist "$BASH_IT/profiles/test.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile save creates valid file with only plugin enabled" { run _enable-plugin "nvm" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# plugins" assert_line -n 2 "plugins nvm" @@ -320,7 +321,7 @@ function local_setup() { run _enable-completion "bash-it" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# completion" assert_line -n 2 "completion bash-it" @@ -330,7 +331,7 @@ function local_setup() { run _enable-alias "general" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# aliases" assert_line -n 2 "aliases general" @@ -338,37 +339,53 @@ function local_setup() { @test "helpers: profile edge case, empty configuration" { run _bash-it-profile-save "test" + assert_success 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." run _enable-alias "general" + assert_success run _enable-plugin "base" - run _enable-plugin "alias-completion" + assert_success + run _enable-completion "aliases" + assert_success run _enable-completion "bash-it" + assert_success run _enable-completion "system" + assert_success run _bash-it-profile-load "test" - assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_not_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_success + assert_line -n 0 "Trying to parse profile 'test'..." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_not_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_not_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save and load" { run _enable-alias "general" + assert_success run _enable-plugin "base" + assert_success run _enable-plugin "alias-completion" + assert_success run _enable-completion "bash-it" + assert_success run _enable-completion "system" + assert_success run _bash-it-profile-save "test" assert_success run _disable-alias "general" - assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_success + assert_output "general disabled." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" run _bash-it-profile-load "test" - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_success + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" } @test "helpers: profile load corrupted profile file: bad component" { @@ -383,10 +400,10 @@ function local_setup() { @test "helpers: profile rm sanity" { run _bash-it-profile-save "test" - assert_file_exist "$BASH_IT/profiles/test.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test.bash_it" run _bash-it-profile-rm "test" assert_line -n 0 "Removed profile 'test' successfully!" - assert_file_not_exist "$BASH_IT/profiles/test.bash_it" + assert_file_not_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile rm no params" { @@ -402,7 +419,7 @@ function local_setup() { @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" + assert_file_exist "${BASH_IT?}/profiles/default.bash_it" } @test "helpers: profile rm bad profile name" { @@ -429,11 +446,11 @@ function local_setup() { } @test "helpers: migrate plugins and completions that share the same name" { - ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash" + ln -s "${BASH_IT?}/completion/available/dirs.completion.bash" "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" - ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/dirs.plugin.bash" "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating plugin dirs.' @@ -444,60 +461,60 @@ function local_setup() { assert_line -n 5 'dirs enabled with priority 350.' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_link_exist "$BASH_IT/enabled/350---dirs.completion.bash" - assert_link_exist "$BASH_IT/enabled/250---dirs.plugin.bash" - assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/250---dirs.plugin.bash" + assert [ ! -L "${BASH_IT?}/completion/enabled/350----dirs.completion.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----dirs.plugin.bash" ] } @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating alias todo.txt-cli.' assert_line -n 1 'todo.txt-cli disabled.' assert_line -n 2 'todo.txt-cli enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" ] } @test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225----node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/250----todo.txt-cli.aliases.bash" ] } @test "helpers: run the migrate command without anything to migrate and nothing enabled" { @@ -506,28 +523,28 @@ function local_setup() { @test "helpers: run the migrate command without anything to migrate" { run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" } function __migrate_all_components() { - subdirectory="$1" - one_type="$2" - priority="$3" + subdirectory="${1:-}" + one_type="${2:-}" + priority="${3:-}" for f in "${BASH_IT}/$subdirectory/available/"*.bash do - to_enable=$(basename $f) - if [ -z "$priority" ]; then + to_enable=$(basename "$f") + if [[ -z "$priority" ]]; then ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable" else ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable" fi done - ls ${BASH_IT}/${subdirectory}/enabled + ls "${BASH_IT?}/${subdirectory}/enabled" all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs) all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) @@ -547,47 +564,53 @@ function __migrate_all_components() { subdirectory="plugins" one_type="plugin" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all aliases" { subdirectory="aliases" one_type="aliases" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all completions" { subdirectory="completion" one_type="completion" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all plugins with previous priority" { subdirectory="plugins" one_type="plugin" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all aliases with previous priority" { subdirectory="aliases" one_type="aliases" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all completions with previous priority" { subdirectory="completion" one_type="completion" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: verify that existing components are automatically migrated when something is enabled" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run bash-it enable plugin "node" assert_line -n 0 'Migrating plugin nvm.' @@ -595,16 +618,16 @@ function __migrate_all_components() { assert_line -n 2 'nvm enabled with priority 225.' assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 4 'node enabled with priority 250.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: verify that existing components are automatically migrated when something is disabled" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" run bash-it disable plugin "node" assert_line -n 0 'Migrating plugin node.' @@ -615,89 +638,94 @@ function __migrate_all_components() { assert_line -n 5 'nvm enabled with priority 225.' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 7 'node disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---node.plugin.bash" ] } @test "helpers: enable all plugins" { + local available enabled run _enable-plugin "all" - local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "$available" "$enabled" } @test "helpers: disable all plugins" { + local available enabled enabled2 run _enable-plugin "all" - local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "$available" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" - local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure with priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins without anything enabled" { - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + local enabled enabled2 + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" assert_line -n 0 'ansible enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---ansible.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ansible.aliases.bash" } @test "helpers: describe the nvm plugin without enabling it" { @@ -707,21 +735,21 @@ function __migrate_all_components() { @test "helpers: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory with priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } diff --git a/test/lib/log.bats b/test/lib/log.bats index 7d868fd6da..906d5fa22c 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -7,77 +8,77 @@ function local_setup_file() { } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_debug "test test test" assert_output "DEBUG: default: test test test" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_warning "test test test" assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_warning "test test test" assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_warning "test test test" - refute_output + assert_output "" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug silent logging" { run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning silent logging" { run _log_warning "test test test" - refute_output + assert_output "" } @test "lib log: basic error silent logging" { run _log_error "test test test" - refute_output + assert_output "" } @test "lib log: logging with prefix" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} BASH_IT_LOG_PREFIX="nice: prefix: " run _log_debug "test test test" assert_output "DEBUG: nice: prefix: test test test" diff --git a/test/lib/preexec.bats b/test/lib/preexec.bats index 10dc666d04..3c5ed4b041 100644 --- a/test/lib/preexec.bats +++ b/test/lib/preexec.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2030 disable=SC2031 load ../test_helper @@ -11,8 +12,9 @@ function local_setup { test_prompt_string="" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" $'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' } @@ -21,8 +23,9 @@ function local_setup { test_prompt_string="nah" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"$'\n__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' } @@ -32,8 +35,9 @@ function local_setup { export PROMPT_COMMAND="$test_prompt_string" export __bp_delay_install="blarg" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" "$test_prompt_string" @@ -48,8 +52,9 @@ function local_setup { test_prompt_string="" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run __bp_install assert_success @@ -62,8 +67,9 @@ function local_setup { test_prompt_string="nah" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run __bp_install assert_success diff --git a/test/lib/search.bats b/test/lib/search.bats index e28922f455..99b7cc39c6 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -12,25 +12,30 @@ function local_setup() { } @test "search: plugin base" { - export BASH_IT_SEARCH_USE_COLOR=false run _bash-it-search-component 'plugins' 'base' + assert_success assert_line -n 0 ' plugins: base ' } @test "search: git" { + local plugin completion run _bash-it-search 'git' --no-color + assert_success assert_line -n 0 ' aliases: git gitsvn ' assert_line -n 1 -p ' plugins:' for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump" do - echo $plugin - assert_line -n 1 -p $plugin + assert_line -n 1 -p "$plugin" + done + for completion in "git" "git_flow" "git_flow_avh" "github-cli" + do + assert_line -n 2 -p "$completion" done - assert_line -n 2 ' completions: git git_flow git_flow_avh github-cli ' } @test "search: ruby gem bundle rake rails" { run _bash-it-search rails ruby gem bundler rake --no-color + assert_success assert_line -n 0 ' aliases: bundler rails ' assert_line -n 1 ' plugins: chruby chruby-auto rails ruby ' @@ -39,6 +44,7 @@ function local_setup() { @test "search: rails ruby gem bundler rake -chruby" { run _bash-it-search rails ruby gem bundler rake -chruby --no-color + assert_success assert_line -n 0 ' aliases: bundler rails ' assert_line -n 1 ' plugins: rails ruby ' @@ -47,22 +53,42 @@ function local_setup() { @test "search: @git" { run _bash-it-search '@git' --no-color + assert_success assert_line -n 0 ' aliases: git ' assert_line -n 1 ' plugins: git ' assert_line -n 2 ' completions: git ' } -@test "search: @git --enable / --disable" { - set -e +@test "search: @git --enable / --disable" { run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p '✓' + + run _bash-it-search '@git' --disable --no-color + assert_success run _bash-it-search '@git' --no-color + assert_success - [[ "${lines[0]}" =~ '✓' ]] + assert_line -n 0 ' aliases: git ' + assert_line -n 1 ' plugins: git ' + assert_line -n 2 ' completions: git ' +} +@test "search: @git --disable / --enable" { run _bash-it-search '@git' --disable --no-color + assert_success run _bash-it-search '@git' --no-color + assert_success assert_line -n 0 ' aliases: git ' assert_line -n 1 ' plugins: git ' assert_line -n 2 ' completions: git ' + + run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p '✓' } From 45ab5b3d9668c563e2c6c3742ea8a4144fdcaaef Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:57:19 -0800 Subject: [PATCH 03/13] test/theme: `shellcheck` test: don't clobber `$PATH` BATS depends on `$PATH` somehow and if not handled properly, modifying `$PATH` breaks BATS badly. But, it doesn't seem like we have any reason to modify `$PATH` in the first place...so don't. test/svn: don't clobber `$PATH` test/ruby: don't clobber `$PATH` test/search: don't clobber `$PATH` --- test/themes/base.theme.bats | 2 +- test/themes/base.theme.git.bats | 148 ++++++++++++++++---------------- test/themes/base.theme.svn.bats | 44 ++++++---- 3 files changed, 102 insertions(+), 92 deletions(-) diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 81b08a01fc..dd2b9288ba 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -25,7 +25,7 @@ function local_setup_file() { assert_line "function" run battery_char - assert_line -n 0 "" + assert_output "" } @test 'themes base: battery_char should exist if battery plugin loaded' { diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index b2bc7c5ae0..2d43414d4b 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -20,12 +20,12 @@ add_commit() { enter_new_git_repo() { repo="$(setup_repo)" - pushd "${repo}" + pushd "${repo}" || return } setup_repo() { upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return git init . > /dev/null echo "$upstream" @@ -33,83 +33,83 @@ setup_repo() { setup_repo_with_upstream() { upstream="$(setup_repo)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return add_commit > /dev/null git checkout -b branch-two git checkout -b gone-branch git checkout master - popd > /dev/null + popd > /dev/null || return downstream="$(setup_repo)" - pushd "$downstream" > /dev/null + pushd "$downstream" > /dev/null || return add_commit > /dev/null git remote add my-remote "$upstream" git fetch my-remote git branch -u my-remote/master > /dev/null - popd > /dev/null + popd > /dev/null || return - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return git branch -d gone-branch > /dev/null - popd > /dev/null + popd > /dev/null || return - pushd "$downstream" > /dev/null + pushd "$downstream" > /dev/null || return git fetch my-remote - popd > /dev/null + popd > /dev/null || return echo "$downstream" } @test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' remote="$(setup_repo)" - pushd "$remote" + pushd "$remote" || return add_commit add_commit - popd + popd || return clone="$(mktemp -d)" - pushd "$clone" + pushd "$clone" || return git clone "$remote" clone cd clone SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑1" + assert_equal "${SCM_BRANCH?}" "${pre} ↑1" add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑2" - popd + assert_equal "${SCM_BRANCH?}" "${pre} ↑2" + popd || return - pushd "$remote" + pushd "$remote" || return add_commit add_commit add_commit - popd + popd || return - pushd "$clone/clone" + pushd "$clone/clone" || return git fetch git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑2 ↓3" + assert_equal "${SCM_BRANCH?}" "${pre} ↑2 ↓3" git reset HEAD~2 --hard SCM_GIT_BEHIND_CHAR="↓" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↓3" + assert_equal "${SCM_BRANCH?}" "${pre} ↓3" } @test 'themes base: Git: when stashes exist: it shows the number of stashes' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo add_commit @@ -121,90 +121,90 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_STASH_INFO=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} {1}" + assert_equal "${SCM_BRANCH?}" "${pre} {1}" touch file2 git add file2 git stash git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} {2}" + assert_equal "${SCM_BRANCH?}" "${pre} {2}" } @test 'themes base: Git: remote info: when there is no upstream remote: is empty' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' post=" ↑1 ↓1" enter_new_git_repo add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' { - pre="\$(_git-friendly-ref) → " + pre='$(_git-friendly-ref) → ' eval_pre="master → " post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is auto: includes the remote when more than one remote' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' eval_pre="master" post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=auto SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}${post}" + assert_equal "${SCM_BRANCH?}" "${pre}${post}" pre="${pre} → " eval_pre="${eval_pre} → " git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" git remote add second-remote "$(mktemp -d)" git branch -u my-remote/master git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is false: never include the remote' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' eval_pre="master" post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return git remote add second-remote "$(mktemp -d)" git remote add third-remote "$(mktemp -d)" @@ -212,59 +212,59 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}${post}" + assert_equal "${SCM_BRANCH?}" "${pre}${post}" pre="${pre} → " eval_pre="${eval_pre} → " git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" } @test 'themes base: Git: remote info: when showing remote info: show if upstream branch is gone' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} → my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre} → my-remote${post}" git checkout gone-branch git fetch --prune --all git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ⇢ my-remote" + assert_equal "${SCM_BRANCH?}" "${pre} ⇢ my-remote" } @test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' { enter_new_git_repo git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" git checkout -b second-branch git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when a branch is not checked out: shows that branch' { enter_new_git_repo git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" git checkout -b second-branch git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and tag: show a tag' { @@ -276,7 +276,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "tag:first-tag" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "tag:first-tag" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and no tag: show a branch' { @@ -287,7 +287,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is parent to a named ref: show relative name' { @@ -297,7 +297,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master~1" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master~1" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is not parent to a named ref: show short sha' { @@ -309,11 +309,11 @@ setup_repo_with_upstream() { git checkout "$sha" git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:$sha" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:$sha" } @test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo echo "line1" > file1 @@ -324,7 +324,7 @@ setup_repo_with_upstream() { git commit -m"commit1" git_prompt_vars - assert_equal "$SCM_STATE" " ✓" + assert_equal "${SCM_STATE?}" " ✓" echo "line2" >> file1 git add file1 @@ -332,56 +332,56 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_DETAILS=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1" - assert_equal "$SCM_STATE" " ✗" - assert_equal "$SCM_DIRTY" "3" + assert_equal "${SCM_BRANCH?}" "${pre} S:1" + assert_equal "${SCM_STATE?}" " ✗" + assert_equal "${SCM_DIRTY?}" "3" echo "line2" >> file2 echo "line2" >> file3 echo "line2" >> file4 git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1 U:3" - assert_equal "$SCM_DIRTY" "2" + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3" + assert_equal "${SCM_DIRTY?}" "2" echo "line1" > newfile5 echo "line1" > newfile6 git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1 U:3 ?:2" - assert_equal "$SCM_DIRTY" "1" + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3 ?:2" + assert_equal "${SCM_DIRTY?}" "1" git config bash-it.hide-status 1 SCM_DIRTY='nope' git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" - assert_equal "$SCM_DIRTY" "nope" + assert_equal "${SCM_BRANCH?}" "${pre}" + assert_equal "${SCM_DIRTY?}" "nope" } @test 'themes base: Git: git user info: shows user initials' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo git config user.name "Cool User" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" SCM_GIT_SHOW_CURRENT_USER=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ cu" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ cu" git config user.name "Çool Üser" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ çü" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ çü" # show initials set by `git pair` git config user.initials "ab cd" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ ab+cd" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ ab+cd" } diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index 360e8636ae..e2fc10135d 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -9,7 +9,7 @@ function local_setup_file() { function setup_repo { upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return # Create a dummy SVN folder - this will not work with an actual `svn` command, # but will be enough to trigger the SVN check in the base theme. mkdir .svn @@ -24,83 +24,93 @@ function setup_svn_path { assert_file_exist "$svn_path/svn" # Make sure that the requested SVN script is on the path - export PATH="$svn_path:/usr/bin:/bin:/usr/sbin" + export PATH="$svn_path:$PATH" } @test 'themes base: SVN: detect SVN repo' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return setup_svn_path "$BASH_IT/test/fixtures/svn/working" # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that the SVN command is used - assert_equal "$SCM" "$SCM_SVN" + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: detect SVN repo even from a subfolder' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return mkdir foo - pushd foo + pushd foo || return setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # init the base theme again so that the working SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that the SVN command is used - assert_equal "$SCM" "$SCM_SVN" + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: no SCM if no .svn folder can be found' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return rm -rf .svn setup_svn_path "$BASH_IT/test/fixtures/svn/working" # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo when using broken SVN command' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the broken SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is not used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return mkdir foo - pushd foo + pushd foo || return setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the broken SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } From 99decb80108083040470a55c235dd9c6e7acaed8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:48:03 -0800 Subject: [PATCH 04/13] test/bash_it: `shellcheck` --- test/bash_it/bash_it.bats | 258 ++++++++++++++++---------------------- 1 file changed, 111 insertions(+), 147 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index ef3cdbab3c..dc9d28112a 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -9,27 +9,24 @@ function local_setup_file() { } @test "bash-it: verify that the test fixture is available" { - assert_file_exist "$BASH_IT/aliases/available/a.aliases.bash" - assert_file_exist "$BASH_IT/aliases/available/b.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/a.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/b.aliases.bash" } @test "bash-it: load aliases in order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -37,22 +34,19 @@ function local_setup_file() { } @test "bash-it: load aliases in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/175---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/175---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -60,24 +54,21 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -85,25 +76,21 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - mkdir -p $BASH_IT/completion/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -112,25 +99,21 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - mkdir -p $BASH_IT/completion/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/450---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/450---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/950---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/950---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -139,24 +122,21 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -166,21 +146,19 @@ function local_setup_file() { } @test "bash-it: load global aliases in order" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -188,21 +166,19 @@ function local_setup_file() { } @test "bash-it: load global aliases in priority order" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/175---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/175---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -210,23 +186,21 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order" { - mkdir -p $BASH_IT/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -234,23 +208,21 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -260,27 +232,24 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { - mkdir -p $BASH_IT/enabled - mkdir -p $BASH_IT/aliases/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # Add one file in the old directory structure - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -290,53 +259,48 @@ function local_setup_file() { } @test "bash-it: load enabled aliases from new structure, priority-based" { - mkdir -p $BASH_IT/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success } @test "bash-it: load enabled aliases from old structure, priority-based" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success } @test "bash-it: load enabled aliases from old structure, without priorities" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success From 5f11a0d3a2e74b77325ce0de35ba2fed66316ad4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:29:39 -0800 Subject: [PATCH 05/13] test/completion: `shellcheck` --- test/completion/aliases.completion.bats | 2 +- test/completion/bash-it.completion.bats | 160 ++++++++++++------------ 2 files changed, 83 insertions(+), 79 deletions(-) mode change 100755 => 100644 test/completion/bash-it.completion.bats diff --git a/test/completion/aliases.completion.bats b/test/completion/aliases.completion.bats index 83ae947a35..2367e6154b 100644 --- a/test/completion/aliases.completion.bats +++ b/test/completion/aliases.completion.bats @@ -26,5 +26,5 @@ function local_setup_file() { alias rm='rm -v' run load "${BASH_IT?}/completion/available/aliases.completion.bash" - refute_output + assert_output "" } diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats old mode 100755 new mode 100644 index 29d1dc944b..7fe60e3e19 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -13,11 +13,12 @@ function local_setup_file() { assert_output "function" } -function __check_completion () { +function __check_completion() { # Get the parameters as a single value COMP_LINE=$* # Get the parameters as an array + # shellcheck disable=SC2294 eval set -- "$@" COMP_WORDS=("$@") @@ -25,7 +26,7 @@ function __check_completion () { COMP_POINT=${#COMP_LINE} # Get the last character of the line that was entered - COMP_LAST=$((${COMP_POINT} - 1)) + COMP_LAST=$((COMP_POINT - 1)) # If the last character was a space... if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then @@ -45,315 +46,318 @@ function __check_completion () { @test "completion bash-it: doctor - show options" { run __check_completion 'bash-it doctor ' - assert_line -n 0 "errors warnings all" + assert_output "errors warnings all" } @test "completion bash-it: help - show options" { run __check_completion 'bash-it help ' - assert_line -n 0 "aliases completions migrate plugins update" + assert_output "aliases completions migrate plugins update" } @test "completion bash-it: help - aliases v" { run __check_completion 'bash-it help aliases v' - assert_line -n 0 "vagrant vault vim" + assert_output "vagrant vault vim" } @test "completion bash-it: update - show options" { run __check_completion 'bash-it update ' - assert_line -n 0 "stable dev" + assert_output "stable dev" } @test "completion bash-it: update - show optional flags" { run __check_completion 'bash-it update -' - assert_line -n 0 "-s --silent" + assert_output "-s --silent" } @test "completion bash-it: search - show no options" { run __check_completion 'bash-it search ' - assert_line -n 0 "" + assert_output "" } @test "completion bash-it: migrate - show no options" { run __check_completion 'bash-it migrate ' - assert_line -n 0 "" + assert_output "" } @test "completion bash-it: show options" { run __check_completion 'bash-it ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash-ti - show options" { run __check_completion 'bash-ti ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: shit - show options" { run __check_completion 'shit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bashit - show options" { run __check_completion 'bashit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: batshit - show options" { run __check_completion 'batshit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash_it - show options" { run __check_completion 'bash_it ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: profile - show options" { run __check_completion 'bash-it profile ' - assert_line -n 0 "load save list rm" + assert_output "load save list rm" } @test "completion bash-it: profile load - show options" { run __check_completion 'bash-it profile load ' - assert_line -n 0 "default" + assert_output "default" } @test "completion bash-it: show - show options" { run __check_completion 'bash-it show ' - assert_line -n 0 "aliases completions plugins" + assert_output "aliases completions plugins" } @test "completion bash-it: enable - show options" { run __check_completion 'bash-it enable ' - assert_line -n 0 "alias completion plugin" + assert_output "alias completion plugin" } @test "completion bash-it: enable - show options a" { run __check_completion 'bash-it enable a' - assert_line -n 0 "alias" + assert_output "alias" } @test "completion bash-it: disable - show options" { run __check_completion 'bash-it disable ' - assert_line -n 0 "alias completion plugin" + assert_output "alias completion plugin" } @test "completion bash-it: disable - show options a" { run __check_completion 'bash-it disable a' - assert_line -n 0 "alias" + assert_output "alias" } @test "completion bash-it: disable - provide nothing when atom is not enabled" { run __check_completion 'bash-it disable alias ato' - assert_line -n 0 "" + assert_output "" } -@test "completion bash-it: disable - provide all when atom is not enabled" { +@test "completion bash-it: disable - provide 'all' when atom is not enabled" { run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all" + assert_output "all" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash" + run _bash-it-component-item-is-enabled "alias" "atom" + assert_success + run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the atom aliases when not enabled" { run __check_completion 'bash-it enable alias ato' - assert_line -n 0 "atom" + assert_output "atom" } @test "completion bash-it: enable - provide the a* aliases when not enabled" { run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt atom" + assert_output "all ag ansible apt atom" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the docker* plugins when docker-compose is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } From 61247a1b76ebf9da0ae8ec53498fc2a068357c6a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 14:20:40 -0800 Subject: [PATCH 06/13] test/plugin: `shellcheck` --- test/plugins/base.plugin.bats | 32 +++++++++++--------- test/plugins/cmd-returned-notify.plugin.bats | 13 ++++---- test/plugins/go.plugin.bats | 27 +++++++++-------- test/plugins/ruby.plugin.bats | 3 +- test/plugins/xterm.plugin.bats | 9 +++--- 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 6022451a91..11b8ee0cf5 100644 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -8,37 +8,39 @@ function local_setup_file() { } @test 'plugins base: ips()' { - declare -r localhost='127.0.0.1' + readonly localhost='127.0.0.1' run ips assert_success - assert_line $localhost + assert_line "$localhost" } @test 'plugins base: myip()' { + local mask_ip run myip assert_success - declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?') - [[ $mask_ip == 'Your public IP is:'*'?.?.?.?'* ]] + shopt -s extglob + mask_ip="${output//+([[:digit:]]|[[:digit:]][[:digit:]]|[[:digit:]][[:digit:]][[:digit:]])/?}" #$(echo "$output" | tr -s '0-9' '?') + [[ $mask_ip == 'Your public IP is: ?.?.?.? ' ]] } @test 'plugins base: pickfrom()' { - stub_file="${BATS_TEST_TMPDIR}/stub_file" - printf "l1\nl2\nl3" > $stub_file - run pickfrom $stub_file + stub_file="${BATS_TEST_TMPDIR?}/stub_file" + printf "l1\nl2\nl3" > "$stub_file" + run pickfrom "$stub_file" assert_success [[ $output == l? ]] } @test 'plugins base: mkcd()' { - cd "${BATS_TEST_TMPDIR}" + cd "${BATS_TEST_TMPDIR?}" declare -r dir_name="-dir_with_dash" # Make sure that the directory does not exist prior to the test - rm -rf "${BATS_TEST_TMPDIR}/${dir_name}" + rm -rf "${BATS_TEST_TMPDIR:?}/${dir_name}" run mkcd "${dir_name}" assert_success - assert_dir_exist "${BATS_TEST_TMPDIR}/${dir_name}" + assert_dir_exist "${BATS_TEST_TMPDIR?}/${dir_name}" mkcd "${dir_name}" assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}" @@ -46,20 +48,20 @@ function local_setup_file() { @test 'plugins base: lsgrep()' { for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done - cd $BASH_IT + cd "${BASH_IT?}" run lsgrep 2 assert_success - assert_equal $output 2 + assert_equal "$output" 2 } @test 'plugins base: buf()' { - declare -r file="${BATS_TEST_TMPDIR}/file" - touch $file + declare -r file="${BATS_TEST_TMPDIR?}/file" + touch "$file" # Take one timestamp before running the `buf` function declare -r stamp1=$(date +%Y%m%d_%H%M%S) - run buf $file + run buf "$file" # Take another timestamp after running `buf`. declare -r stamp2=$(date +%Y%m%d_%H%M%S) diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index 04edad9582..e120e9ef6b 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -8,8 +9,8 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: notify after elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + NOTIFY_IF_COMMAND_RETURNS_AFTER=0 + COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -17,8 +18,8 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: do not notify before elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + NOTIFY_IF_COMMAND_RETURNS_AFTER=10 + COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -26,13 +27,13 @@ function local_setup_file() { } @test "lib command_duration: preexec no output" { - export COMMAND_DURATION_START_SECONDS= + COMMAND_DURATION_START_SECONDS= run _command_duration_pre_exec assert_success assert_output "" } @test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" { - export COMMAND_DURATION_START_SECONDS= + COMMAND_DURATION_START_SECONDS= assert_equal "${COMMAND_DURATION_START_SECONDS}" "" NOW="${EPOCHREALTIME:-$SECONDS}" _command_duration_pre_exec diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index ebb9cd8823..b8fb779a4b 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -21,7 +22,7 @@ function setup_go_path() @test 'ensure _bash-it-gopath-pathmunge is defined' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' - load ../../plugins/available/go.plugin + load "${BASH_IT?}/plugins/available/go.plugin.bash" run type -t _bash-it-gopath-pathmunge assert_line 'function' } @@ -29,39 +30,39 @@ function setup_go_path() @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" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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' { @@ -69,6 +70,6 @@ function setup_go_path() { _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" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" } diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 7bfc64555d..a6ff87c4f3 100644 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -16,6 +16,7 @@ function local_setup_file() { } @test "plugins ruby: PATH includes ~/.gem/ruby/bin" { + local last_path_entry if ! type ruby >/dev/null; then skip 'ruby not installed' fi @@ -26,6 +27,6 @@ function local_setup_file() { assert_success load "${BASH_IT?}/plugins/available/ruby.plugin.bash" - local last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" + last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] } diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index 4cb1ffdae0..0d2c629816 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -8,28 +9,28 @@ function local_setup_file() { } @test "plugins xterm: shorten command output" { - export SHORT_TERM_LINE=true + SHORT_TERM_LINE=true run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0" } @test "plugins xterm: full command output" { - export SHORT_TERM_LINE=false + SHORT_TERM_LINE=false run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)" } @test "plugins xterm: shorten dirname output" { - export SHORT_TERM_LINE=true + SHORT_TERM_LINE=true run _short-dirname assert_success assert_output "$(basename "${PWD}")" } @test "plugins xterm: full dirname output" { - export SHORT_TERM_LINE=false + SHORT_TERM_LINE=false run _short-dirname assert_success assert_output "${PWD}" From 6f6a99e3ebf41d91b730ed26cc1a47efceded35c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:30:10 -0800 Subject: [PATCH 07/13] test/install: `shellcheck` --- test/install/install.bats | 21 +++++++++++---------- test/install/uninstall.bats | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index c9e1794c57..c5e3187524 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -3,7 +3,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="$BATS_TEST_TMPDIR" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { @@ -20,7 +20,7 @@ function local_setup_file() { } @test "install: verify that the install script exists" { - assert_file_exist "$BASH_IT/install.sh" + assert_file_exist "${BASH_IT?}/install.sh" } @test "install: run the install script silently" { @@ -30,26 +30,27 @@ function local_setup_file() { assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "install: verify that a backup file is created" { - cd "$BASH_IT" + local md5_orig md5_bak + cd "${BASH_IT?}" touch "$HOME/$BASH_IT_CONFIG_FILE" echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') ./install.sh --silent assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') assert_equal "$md5_orig" "$md5_bak" } diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index ab71a775f7..849e01d2d6 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -3,7 +3,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="$BATS_TEST_TMPDIR" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { @@ -20,15 +20,16 @@ function local_setup_file() { } @test "uninstall: verify that the uninstall script exists" { - assert_file_exist "$BASH_IT/uninstall.sh" + assert_file_exist "${BASH_IT?}/uninstall.sh" } @test "uninstall: run the uninstall script with an existing backup file" { - cd "$BASH_IT" + local md5_bak md5_conf + cd "${BASH_IT?}" echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') run ./uninstall.sh assert_success @@ -37,16 +38,17 @@ function local_setup_file() { assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') assert_equal "$md5_bak" "$md5_conf" } @test "uninstall: run the uninstall script without an existing backup file" { - cd "$BASH_IT" + local md5_orig md5_uninstall + cd "${BASH_IT?}" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') run ./uninstall.sh assert_success @@ -55,7 +57,7 @@ function local_setup_file() { assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') assert_equal "$md5_orig" "$md5_uninstall" } From c893be359467eaadf28a3d8beabbe0b9a659a08b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:20:50 -0800 Subject: [PATCH 08/13] tests: add to `clean_files.txt` --- clean_files.txt | 7 +------ test/fixtures/bash_it/aliases/available/a.aliases.bash | 2 +- test/fixtures/bash_it/aliases/available/b.aliases.bash | 2 +- test/fixtures/bash_it/plugins/available/c.plugin.bash | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index e52d5a9f29..82b07d7b0a 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -20,6 +20,7 @@ aliases/ docs/ hooks/ scripts/ +test/ # root files # @@ -134,12 +135,6 @@ plugins/available/todo.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash -# tests -# -test/plugins/alias-completion.plugin.bats -test/run -test/test_helper.bash - # themes # themes/90210 diff --git a/test/fixtures/bash_it/aliases/available/a.aliases.bash b/test/fixtures/bash_it/aliases/available/a.aliases.bash index 9dede3f66c..7410181383 100644 --- a/test/fixtures/bash_it/aliases/available/a.aliases.bash +++ b/test/fixtures/bash_it/aliases/available/a.aliases.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="a" diff --git a/test/fixtures/bash_it/aliases/available/b.aliases.bash b/test/fixtures/bash_it/aliases/available/b.aliases.bash index 4f90a7ad66..f0321d491b 100644 --- a/test/fixtures/bash_it/aliases/available/b.aliases.bash +++ b/test/fixtures/bash_it/aliases/available/b.aliases.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="b" diff --git a/test/fixtures/bash_it/plugins/available/c.plugin.bash b/test/fixtures/bash_it/plugins/available/c.plugin.bash index 3d17ad7aeb..db52fd0f4d 100644 --- a/test/fixtures/bash_it/plugins/available/c.plugin.bash +++ b/test/fixtures/bash_it/plugins/available/c.plugin.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="c" From 93a05ccb64c95ea1e7e78d4014c3471d2b124132 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 10:20:21 -0800 Subject: [PATCH 09/13] test_helper: make lib loading default Make library loading overridable default for all tests, up through "seach". --- test/test_helper.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index bffb59edd6..7d62212630 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -66,7 +66,7 @@ function setup_libs() { } function local_setup_file() { - true + setup_libs "search" # overridable default } function local_setup() { From 810c52f91a97325813a29fb59de241a45faf3d34 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 14:25:22 -0800 Subject: [PATCH 10/13] test: add new lib files to `setup_libs()` --- test/test_helper.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index 7d62212630..9728801681 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -57,7 +57,7 @@ function common_setup_file() { function setup_libs() { local lib # Use a loop to allow convenient short-circuiting for some test files - for lib in "log" "utilities" "helpers" "search" "preexec" "colors" "command_duration"; do + for lib in "log" "utilities" "helpers" "search" "colors" "preview" "preexec" "history" "command_duration"; do load "${BASH_IT?}/lib/${lib}.bash" || return # shellcheck disable=SC2015 # short-circuit if we've reached the requested library [[ "${lib}" == "${1:-}" ]] && return 0 || true @@ -66,7 +66,7 @@ function setup_libs() { } function local_setup_file() { - setup_libs "search" # overridable default + setup_libs "colors" # overridable default } function local_setup() { From d37505b636ca7bc95301d8daaf9c58a3186ce57a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 14:21:24 -0800 Subject: [PATCH 11/13] test: `shfmt` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My apologies to future `git blame` hunters ♥ --- .pre-commit-config.yaml | 1 - test/bash_it/bash_it.bats | 446 ++++----- test/completion/aliases.completion.bats | 24 +- test/completion/bash-it.completion.bats | 356 ++++---- test/install/install.bats | 90 +- test/install/uninstall.bats | 70 +- test/lib/composure.bats | 8 +- test/lib/helpers.bats | 899 +++++++++---------- test/lib/log.bats | 77 +- test/lib/search.bats | 122 ++- test/lib/utilities.bats | 88 +- test/plugins/base.plugin.bats | 94 +- test/plugins/battery.plugin.bats | 311 ++++--- test/plugins/cmd-returned-notify.plugin.bats | 4 +- test/plugins/go.plugin.bats | 81 +- test/plugins/ruby.plugin.bats | 32 +- test/plugins/xterm.plugin.bats | 42 +- test/themes/base.theme.bats | 78 +- test/themes/base.theme.git.bats | 498 +++++----- test/themes/base.theme.svn.bats | 136 +-- 20 files changed, 1725 insertions(+), 1732 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8c3f35253f..52a7795885 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,7 +20,6 @@ repos: - id: git-check # Configure in .gitattributes - id: shellcheck - id: shfmt - exclude: ".bats$" - repo: https://github.com/Lucas-C/pre-commit-hooks rev: v1.1.7 hooks: diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index dc9d28112a..e43ab988cd 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -3,305 +3,305 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - # Copy the test fixture to the Bash-it folder - cp -fRP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" || true - # don't load any libraries as the tests here test the *whole* kit + # Copy the test fixture to the Bash-it folder + cp -fRP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" || true + # don't load any libraries as the tests here test the *whole* kit } @test "bash-it: verify that the test fixture is available" { - assert_file_exist "${BASH_IT?}/aliases/available/a.aliases.bash" - assert_file_exist "${BASH_IT?}/aliases/available/b.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/a.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/b.aliases.bash" } @test "bash-it: load aliases in order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias test_alias &> /dev/null - assert_success - assert_line -n 0 "alias test_alias='b'" + run alias test_alias &> /dev/null + assert_success + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load aliases in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias test_alias &> /dev/null - assert_success - assert_line -n 0 "alias test_alias='a'" + run alias test_alias &> /dev/null + assert_success + assert_line -n 0 "alias test_alias='a'" } @test "bash-it: load aliases and plugins in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias test_alias &> /dev/null - assert_success - assert_line -n 0 "alias test_alias='c'" + run alias test_alias &> /dev/null + assert_success + assert_line -n 0 "alias test_alias='c'" } @test "bash-it: load aliases, plugins and completions in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" - assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" - - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure - - load "${BASH_IT?}/bash_it.sh" - - run alias test_alias &> /dev/null - assert_success - # "b" wins since completions are loaded last in the old directory structure - assert_line -n 0 "alias test_alias='b'" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "${BASH_IT?}/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # "b" wins since completions are loaded last in the old directory structure + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" - assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" - - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure - - load "${BASH_IT?}/bash_it.sh" - - run alias test_alias &> /dev/null - assert_success - # "b" wins since completions are loaded last in the old directory structure - assert_line -n 0 "alias test_alias='b'" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "${BASH_IT?}/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # "b" wins since completions are loaded last in the old directory structure + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" - - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure - - load "${BASH_IT?}/bash_it.sh" - - run alias test_alias &> /dev/null - assert_success - # This will be c, loaded from the c plugin, since the individual directories - # are loaded one by one. - assert_line -n 0 "alias test_alias='c'" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "${BASH_IT?}/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # This will be c, loaded from the c plugin, since the individual directories + # are loaded one by one. + assert_line -n 0 "alias test_alias='c'" } @test "bash-it: load global aliases in order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias test_alias &> /dev/null - assert_success - assert_line -n 0 "alias test_alias='b'" + run alias test_alias &> /dev/null + assert_success + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load global aliases in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/175---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias test_alias &> /dev/null - assert_success - assert_line -n 0 "alias test_alias='a'" + run alias test_alias &> /dev/null + assert_success + assert_line -n 0 "alias test_alias='a'" } @test "bash-it: load global aliases and plugins in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias test_alias &> /dev/null - assert_success - assert_line -n 0 "alias test_alias='c'" + run alias test_alias &> /dev/null + assert_success + assert_line -n 0 "alias test_alias='c'" } @test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" - - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure - - load "${BASH_IT?}/bash_it.sh" - - run alias test_alias &> /dev/null - assert_success - # This will be a, loaded from the a aliases, since the global directory - # loads all component types at once - assert_line -n 0 "alias test_alias='a'" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "${BASH_IT?}/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # This will be a, loaded from the a aliases, since the global directory + # loads all component types at once + assert_line -n 0 "alias test_alias='a'" } @test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" - # Add one file in the old directory structure - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - - # The `test_alias` alias should not exist - run alias test_alias &> /dev/null - assert_failure - - load "${BASH_IT?}/bash_it.sh" - - run alias test_alias &> /dev/null - assert_success - # This will be "b", loaded from the b aliases in the individual directory, since - # the individual directories are loaded after the global one. - assert_line -n 0 "alias test_alias='b'" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" + # Add one file in the old directory structure + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "${BASH_IT?}/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # This will be "b", loaded from the b aliases in the individual directory, since + # the individual directories are loaded after the global one. + assert_line -n 0 "alias test_alias='b'" } @test "bash-it: load enabled aliases from new structure, priority-based" { - ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---atom.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - # The `ah` alias should not exist - run alias ah &> /dev/null - assert_failure + # The `ah` alias should not exist + run alias ah &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias ah &> /dev/null - assert_success + run alias ah &> /dev/null + assert_success } @test "bash-it: load enabled aliases from old structure, priority-based" { - ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - # The `ah` alias should not exist - run alias ah &> /dev/null - assert_failure + # The `ah` alias should not exist + run alias ah &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias ah &> /dev/null - assert_success + run alias ah &> /dev/null + assert_success } @test "bash-it: load enabled aliases from old structure, without priorities" { - ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/atom.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/base.plugin.bash" - # The `ah` alias should not exist - run alias ah &> /dev/null - assert_failure + # The `ah` alias should not exist + run alias ah &> /dev/null + assert_failure - load "${BASH_IT?}/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" - run alias ah &> /dev/null - assert_success + run alias ah &> /dev/null + assert_success } diff --git a/test/completion/aliases.completion.bats b/test/completion/aliases.completion.bats index 2367e6154b..ec5ddac6a4 100644 --- a/test/completion/aliases.completion.bats +++ b/test/completion/aliases.completion.bats @@ -3,28 +3,28 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" - # Load something, anything... - load ../../completion/available/capistrano.completion + setup_libs "helpers" + # Load something, anything... + load ../../completion/available/capistrano.completion } @test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" { - alias gtest="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative" - run load "${BASH_IT?}/completion/available/aliases.completion.bash" + alias gtest="git log --graph --pretty=format:'%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset' --abbrev-commit --date=relative" + run load "${BASH_IT?}/completion/available/aliases.completion.bash" - assert_success + assert_success } @test "alias-completion: See that aliases with single quotes and brackets do not break the plugin" { - alias gtest='git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative' - run load "${BASH_IT?}/completion/available/aliases.completion.bash" + alias gtest='git log --graph --pretty=format:"%C(bold)%h%Creset%C(magenta)%d%Creset %s %C(yellow)<%an> %C(cyan)(%cr)%Creset" --abbrev-commit --date=relative' + run load "${BASH_IT?}/completion/available/aliases.completion.bash" - assert_success + assert_success } @test "alias-completion: See that having aliased rm command does not output unnecessary output" { - alias rm='rm -v' - run load "${BASH_IT?}/completion/available/aliases.completion.bash" + alias rm='rm -v' + run load "${BASH_IT?}/completion/available/aliases.completion.bash" - assert_output "" + assert_output "" } diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 7fe60e3e19..8ee9ef0722 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -3,361 +3,361 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" - load "${BASH_IT?}/completion/available/bash-it.completion.bash" + setup_libs "helpers" + load "${BASH_IT?}/completion/available/bash-it.completion.bash" } @test "completion bash-it: ensure that the _bash-it function is available" { - run type -t _bash-it - assert_success - assert_output "function" + run type -t _bash-it + assert_success + assert_output "function" } function __check_completion() { - # Get the parameters as a single value - COMP_LINE=$* + # Get the parameters as a single value + COMP_LINE=$* - # Get the parameters as an array - # shellcheck disable=SC2294 - eval set -- "$@" - COMP_WORDS=("$@") + # Get the parameters as an array + # shellcheck disable=SC2294 + eval set -- "$@" + COMP_WORDS=("$@") - # Index of the cursor in the line - COMP_POINT=${#COMP_LINE} + # Index of the cursor in the line + COMP_POINT=${#COMP_LINE} - # Get the last character of the line that was entered - COMP_LAST=$((COMP_POINT - 1)) + # Get the last character of the line that was entered + COMP_LAST=$((COMP_POINT - 1)) - # If the last character was a space... - if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then - # ...then add an empty array item - COMP_WORDS+=('') - fi + # If the last character was a space... + if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then + # ...then add an empty array item + COMP_WORDS+=('') + fi - # Word index of the last word - COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 )) + # Word index of the last word + COMP_CWORD=$((${#COMP_WORDS[@]} - 1)) - # Run the Bash-it completion function - _bash-it + # Run the Bash-it completion function + _bash-it - # Return the completion output - echo "${COMPREPLY[@]}" + # Return the completion output + echo "${COMPREPLY[@]}" } @test "completion bash-it: doctor - show options" { - run __check_completion 'bash-it doctor ' - assert_output "errors warnings all" + run __check_completion 'bash-it doctor ' + assert_output "errors warnings all" } @test "completion bash-it: help - show options" { - run __check_completion 'bash-it help ' - assert_output "aliases completions migrate plugins update" + run __check_completion 'bash-it help ' + assert_output "aliases completions migrate plugins update" } @test "completion bash-it: help - aliases v" { - run __check_completion 'bash-it help aliases v' - assert_output "vagrant vault vim" + run __check_completion 'bash-it help aliases v' + assert_output "vagrant vault vim" } @test "completion bash-it: update - show options" { - run __check_completion 'bash-it update ' - assert_output "stable dev" + run __check_completion 'bash-it update ' + assert_output "stable dev" } @test "completion bash-it: update - show optional flags" { - run __check_completion 'bash-it update -' - assert_output "-s --silent" + run __check_completion 'bash-it update -' + assert_output "-s --silent" } @test "completion bash-it: search - show no options" { - run __check_completion 'bash-it search ' - assert_output "" + run __check_completion 'bash-it search ' + assert_output "" } @test "completion bash-it: migrate - show no options" { - run __check_completion 'bash-it migrate ' - assert_output "" + run __check_completion 'bash-it migrate ' + assert_output "" } @test "completion bash-it: show options" { - run __check_completion 'bash-it ' - assert_output "disable enable help migrate reload restart preview profile doctor search show update version" + run __check_completion 'bash-it ' + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash-ti - show options" { - run __check_completion 'bash-ti ' - assert_output "disable enable help migrate reload restart preview profile doctor search show update version" + run __check_completion 'bash-ti ' + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: shit - show options" { - run __check_completion 'shit ' - assert_output "disable enable help migrate reload restart preview profile doctor search show update version" + run __check_completion 'shit ' + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bashit - show options" { - run __check_completion 'bashit ' - assert_output "disable enable help migrate reload restart preview profile doctor search show update version" + run __check_completion 'bashit ' + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: batshit - show options" { - run __check_completion 'batshit ' - assert_output "disable enable help migrate reload restart preview profile doctor search show update version" + run __check_completion 'batshit ' + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash_it - show options" { - run __check_completion 'bash_it ' - assert_output "disable enable help migrate reload restart preview profile doctor search show update version" + run __check_completion 'bash_it ' + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: profile - show options" { - run __check_completion 'bash-it profile ' - assert_output "load save list rm" + run __check_completion 'bash-it profile ' + assert_output "load save list rm" } @test "completion bash-it: profile load - show options" { - run __check_completion 'bash-it profile load ' - assert_output "default" + run __check_completion 'bash-it profile load ' + assert_output "default" } @test "completion bash-it: show - show options" { - run __check_completion 'bash-it show ' - assert_output "aliases completions plugins" + run __check_completion 'bash-it show ' + assert_output "aliases completions plugins" } @test "completion bash-it: enable - show options" { - run __check_completion 'bash-it enable ' - assert_output "alias completion plugin" + run __check_completion 'bash-it enable ' + assert_output "alias completion plugin" } @test "completion bash-it: enable - show options a" { - run __check_completion 'bash-it enable a' - assert_output "alias" + run __check_completion 'bash-it enable a' + assert_output "alias" } @test "completion bash-it: disable - show options" { - run __check_completion 'bash-it disable ' - assert_output "alias completion plugin" + run __check_completion 'bash-it disable ' + assert_output "alias completion plugin" } @test "completion bash-it: disable - show options a" { - run __check_completion 'bash-it disable a' - assert_output "alias" + run __check_completion 'bash-it disable a' + assert_output "alias" } @test "completion bash-it: disable - provide nothing when atom is not enabled" { - run __check_completion 'bash-it disable alias ato' - assert_output "" + run __check_completion 'bash-it disable alias ato' + assert_output "" } @test "completion bash-it: disable - provide 'all' when atom is not enabled" { - run __check_completion 'bash-it disable alias a' - assert_output "all" + run __check_completion 'bash-it disable alias a' + assert_output "all" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" - assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" + assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash" - run _bash-it-component-item-is-enabled "alias" "atom" - assert_success + run _bash-it-component-item-is-enabled "alias" "atom" + assert_success - run __check_completion 'bash-it disable alias a' - assert_output "all atom" + run __check_completion 'bash-it disable alias a' + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" - assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" + assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" - run __check_completion 'bash-it disable alias a' - assert_output "all atom" + run __check_completion 'bash-it disable alias a' + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" - assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" + assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" - run __check_completion 'bash-it disable alias a' - assert_output "all atom" + run __check_completion 'bash-it disable alias a' + assert_output "all atom" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" - assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" - run __check_completion 'bash-it disable plugin docker' - assert_output "docker-machine" + run __check_completion 'bash-it disable plugin docker' + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" - assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" - run __check_completion 'bash-it disable plugin docker' - assert_output "docker-machine" + run __check_completion 'bash-it disable plugin docker' + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" - run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" - assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" + assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" - run __check_completion 'bash-it disable plugin docker' - assert_output "docker-machine" + run __check_completion 'bash-it disable plugin docker' + assert_output "docker-machine" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" - run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" - assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" - run __check_completion 'bash-it disable alias to' - assert_output "todo.txt-cli" + run __check_completion 'bash-it disable alias to' + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" - run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" - assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" - run __check_completion 'bash-it disable alias to' - assert_output "todo.txt-cli" + run __check_completion 'bash-it disable alias to' + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" - assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" - run __check_completion 'bash-it disable alias to' - assert_output "todo.txt-cli" + run __check_completion 'bash-it disable alias to' + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the atom aliases when not enabled" { - run __check_completion 'bash-it enable alias ato' - assert_output "atom" + run __check_completion 'bash-it enable alias ato' + assert_output "atom" } @test "completion bash-it: enable - provide the a* aliases when not enabled" { - run __check_completion 'bash-it enable alias a' - assert_output "all ag ansible apt atom" + run __check_completion 'bash-it enable alias a' + assert_output "all ag ansible apt atom" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - run __check_completion 'bash-it enable alias a' - assert_output "all ag ansible apt" + run __check_completion 'bash-it enable alias a' + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - run __check_completion 'bash-it enable alias a' - assert_output "all ag ansible apt" + run __check_completion 'bash-it enable alias a' + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - run __check_completion 'bash-it enable alias a' - assert_output "all ag ansible apt" + run __check_completion 'bash-it enable alias a' + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the docker* plugins when docker-compose is enabled with the old location and name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - run __check_completion 'bash-it enable plugin docker' - assert_output "docker docker-compose docker-machine" + run __check_completion 'bash-it enable plugin docker' + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - run __check_completion 'bash-it enable plugin docker' - assert_output "docker docker-compose docker-machine" + run __check_completion 'bash-it enable plugin docker' + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" - run __check_completion 'bash-it enable plugin docker' - assert_output "docker docker-compose docker-machine" + run __check_completion 'bash-it enable plugin docker' + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - run __check_completion 'bash-it enable completion docker' - assert_output "docker docker-compose docker-machine" + run __check_completion 'bash-it enable completion docker' + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - run __check_completion 'bash-it enable completion docker' - assert_output "docker docker-compose docker-machine" + run __check_completion 'bash-it enable completion docker' + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" - run __check_completion 'bash-it enable completion docker' - assert_output "docker docker-compose docker-machine" + run __check_completion 'bash-it enable completion docker' + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" - assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" - run __check_completion 'bash-it enable alias to' - assert_output "todo.txt-cli" + run __check_completion 'bash-it enable alias to' + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" - assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" - run __check_completion 'bash-it enable alias to' - assert_output "todo.txt-cli" + run __check_completion 'bash-it enable alias to' + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" - assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" - run __check_completion 'bash-it enable alias to' - assert_output "todo.txt-cli" + run __check_completion 'bash-it enable alias to' + assert_output "todo.txt-cli" } diff --git a/test/install/install.bats b/test/install/install.bats index c5e3187524..5288907e8f 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -3,87 +3,87 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="${BATS_TEST_TMPDIR?}" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { - # Determine which config file to use based on OS. - case $OSTYPE in - darwin*) - export BASH_IT_CONFIG_FILE=.bash_profile - ;; - *) - export BASH_IT_CONFIG_FILE=.bashrc - ;; - esac - # don't load any libraries as the tests here test the *whole* kit + # Determine which config file to use based on OS. + case $OSTYPE in + darwin*) + export BASH_IT_CONFIG_FILE=.bash_profile + ;; + *) + export BASH_IT_CONFIG_FILE=.bashrc + ;; + esac + # don't load any libraries as the tests here test the *whole* kit } @test "install: verify that the install script exists" { - assert_file_exist "${BASH_IT?}/install.sh" + assert_file_exist "${BASH_IT?}/install.sh" } @test "install: run the install script silently" { - cd "$BASH_IT" + cd "$BASH_IT" - ./install.sh --silent + ./install.sh --silent - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" - assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" - assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "install: verify that a backup file is created" { - local md5_orig md5_bak - cd "${BASH_IT?}" + local md5_orig md5_bak + cd "${BASH_IT?}" - touch "$HOME/$BASH_IT_CONFIG_FILE" - echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" - md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + touch "$HOME/$BASH_IT_CONFIG_FILE" + echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') - ./install.sh --silent + ./install.sh --silent - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') - assert_equal "$md5_orig" "$md5_bak" + assert_equal "$md5_orig" "$md5_bak" } @test "install: verify that silent and interactive can not be used at the same time" { - cd "$BASH_IT" + cd "$BASH_IT" - run ./install.sh --silent --interactive + run ./install.sh --silent --interactive - assert_failure + assert_failure } @test "install: verify that no-modify-config and append-to-config can not be used at the same time" { - cd "$BASH_IT" + cd "$BASH_IT" - run ./install.sh --silent --no-modify-config --append-to-config + run ./install.sh --silent --no-modify-config --append-to-config - assert_failure + assert_failure } @test "install: verify that the template is appended" { - cd "$BASH_IT" + cd "$BASH_IT" - touch "$HOME/$BASH_IT_CONFIG_FILE" - echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" + touch "$HOME/$BASH_IT_CONFIG_FILE" + echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" - ./install.sh --silent --append-to-config + ./install.sh --silent --append-to-config - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - run cat "$HOME/$BASH_IT_CONFIG_FILE" + run cat "$HOME/$BASH_IT_CONFIG_FILE" - assert_line "test file content" - assert_line "source \"\$BASH_IT\"/bash_it.sh" + assert_line "test file content" + assert_line "source \"\$BASH_IT\"/bash_it.sh" } diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index 849e01d2d6..48ad21623f 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -3,61 +3,61 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="${BATS_TEST_TMPDIR?}" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { - # Determine which config file to use based on OS. - case $OSTYPE in - darwin*) - export BASH_IT_CONFIG_FILE=.bash_profile - ;; - *) - export BASH_IT_CONFIG_FILE=.bashrc - ;; - esac - # don't load any libraries as the tests here test the *whole* kit + # Determine which config file to use based on OS. + case $OSTYPE in + darwin*) + export BASH_IT_CONFIG_FILE=.bash_profile + ;; + *) + export BASH_IT_CONFIG_FILE=.bashrc + ;; + esac + # don't load any libraries as the tests here test the *whole* kit } @test "uninstall: verify that the uninstall script exists" { - assert_file_exist "${BASH_IT?}/uninstall.sh" + assert_file_exist "${BASH_IT?}/uninstall.sh" } @test "uninstall: run the uninstall script with an existing backup file" { - local md5_bak md5_conf - cd "${BASH_IT?}" + local md5_bak md5_conf + cd "${BASH_IT?}" - echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" - echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" + echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') - run ./uninstall.sh - assert_success + run ./uninstall.sh + assert_success - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') - assert_equal "$md5_bak" "$md5_conf" + assert_equal "$md5_bak" "$md5_conf" } @test "uninstall: run the uninstall script without an existing backup file" { - local md5_orig md5_uninstall - cd "${BASH_IT?}" + local md5_orig md5_uninstall + cd "${BASH_IT?}" - echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') - run ./uninstall.sh - assert_success + run ./uninstall.sh + assert_success - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" + assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" - md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') - assert_equal "$md5_orig" "$md5_uninstall" + assert_equal "$md5_orig" "$md5_uninstall" } diff --git a/test/lib/composure.bats b/test/lib/composure.bats index 01bfd9679c..fdff4404e4 100644 --- a/test/lib/composure.bats +++ b/test/lib/composure.bats @@ -3,11 +3,11 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - true - # don't load any libraries as the tests here test the *whole* kit + true + # don't load any libraries as the tests here test the *whole* kit } @test "lib composure: _composure_keywords()" { - run _composure_keywords - assert_output "about author example group param version" + run _composure_keywords + assert_output "about author example group param version" } diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index b27e775e0a..5806ac552d 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -3,758 +3,757 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "colors" + setup_libs "colors" } function local_setup() { - # Copy the test fixture to the Bash-it folder - cp -RP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" + # Copy the test fixture to the Bash-it folder + cp -RP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" } # TODO Create global __is_enabled function # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function @test "bash-it: verify that the test fixture is available" { - assert_file_exist "${BASH_IT?}/profiles/test-bad-component.bash_it" - assert_file_exist "${BASH_IT?}/profiles/test-bad-type.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-component.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-type.bash_it" } @test "helpers: _command_exists function exists" { - run type -t _command_exists - assert_success - assert_output "function" + run type -t _command_exists + assert_success + assert_output "function" } @test "helpers: _command_exists function positive test ls" { - run _command_exists ls - assert_success + run _command_exists ls + assert_success } @test "helpers: _command_exists function positive test bash-it" { - run _command_exists bash-it - assert_success + run _command_exists bash-it + assert_success } @test "helpers: _command_exists function negative test" { - run _command_exists __addfkds_dfdsjdf - assert_failure + run _command_exists __addfkds_dfdsjdf + assert_failure } @test "helpers: _binary_exists function exists" { - run type -t _binary_exists - assert_success - assert_output "function" + run type -t _binary_exists + assert_success + assert_output "function" } @test "helpers: _binary_exists function positive test ls" { - run _binary_exists ls - assert_success + run _binary_exists ls + assert_success } @test "helpers: _binary_exists function negative test function" { - run _binary_exists _binary_exists - assert_failure + run _binary_exists _binary_exists + assert_failure } @test "helpers: _binary_exists function negative test" { - run _binary_exists __addfkds_dfdsjdf - assert_failure + run _binary_exists __addfkds_dfdsjdf + assert_failure } @test "helpers: bash-it help aliases ag" { - run bash-it help aliases "ag" - assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'" + run bash-it help aliases "ag" + assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'" } @test "helpers: bash-it help aliases without any aliases enabled" { - run bash-it help aliases - assert_output "" + run bash-it help aliases + assert_output "" } @test "helpers: bash-it help plugins" { - run bash-it help plugins - assert_line -n 1 "composure:" + run bash-it help plugins + assert_line -n 1 "composure:" } @test "helpers: bash-it help list aliases without any aliases enabled" { - run _help-list-aliases "${BASH_IT?}/aliases/available/ag.aliases.bash" - assert_line -n 0 "ag:" + run _help-list-aliases "${BASH_IT?}/aliases/available/ag.aliases.bash" + assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with ag aliases enabled" { - ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - assert_line -n 0 "ag:" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { - ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" - run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" - assert_line -n 0 "todo.txt-cli:" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + assert_line -n 0 "todo.txt-cli:" } @test "helpers: bash-it help list aliases with docker-compose aliases enabled" { - ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" - run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" - assert_line -n 0 "docker-compose:" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + assert_line -n 0 "docker-compose:" } @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { - ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/150---ag.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _help-list-aliases "${BASH_IT?}/enabled/150---ag.aliases.bash" - assert_line -n 0 "ag:" + run _help-list-aliases "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in the old directory" { - ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - run bash-it help aliases - assert_line -n 0 "ag:" + run bash-it help aliases + assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in global directory" { - run bash-it enable alias "ag" - assert_line -n 0 'ag enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run bash-it enable alias "ag" + assert_line -n 0 'ag enabled with priority 150.' + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run bash-it enable plugin "aws" - assert_line -n 0 'aws enabled with priority 250.' - assert_link_exist "${BASH_IT?}/enabled/250---aws.plugin.bash" + run bash-it enable plugin "aws" + assert_line -n 0 'aws enabled with priority 250.' + assert_link_exist "${BASH_IT?}/enabled/250---aws.plugin.bash" - run bash-it help aliases - assert_line -n 0 "ag:" - assert_line -n 1 "ag='ag --smart-case --pager=\"less -MIRFX'" + run bash-it help aliases + assert_line -n 0 "ag:" + assert_line -n 1 "ag='ag --smart-case --pager=\"less -MIRFX'" } @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { - run bash-it enable alias "todo.txt-cli" - assert_line -n 0 'todo.txt-cli enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + run bash-it enable alias "todo.txt-cli" + assert_line -n 0 'todo.txt-cli enabled with priority 150.' + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" } @test "helpers: enable the curl aliases" { - run _enable-alias "curl" - assert_line -n 0 'curl enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---curl.aliases.bash" + run _enable-alias "curl" + assert_line -n 0 'curl enabled with priority 150.' + assert_link_exist "${BASH_IT?}/enabled/150---curl.aliases.bash" } @test "helpers: enable the apm completion through the bash-it function" { - run bash-it enable completion "apm" - assert_line -n 0 'apm enabled with priority 350.' - assert_link_exist "${BASH_IT?}/enabled/350---apm.completion.bash" + run bash-it enable completion "apm" + assert_line -n 0 'apm enabled with priority 350.' + assert_link_exist "${BASH_IT?}/enabled/350---apm.completion.bash" } @test "helpers: enable the brew completion" { - run _enable-completion "brew" - assert_line -n 0 'brew enabled with priority 375.' - assert_link_exist "${BASH_IT?}/enabled/375---brew.completion.bash" + run _enable-completion "brew" + assert_line -n 0 'brew enabled with priority 375.' + assert_link_exist "${BASH_IT?}/enabled/375---brew.completion.bash" } @test "helpers: enable the node plugin" { - run _enable-plugin "node" - assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" + run _enable-plugin "node" + assert_line -n 0 'node enabled with priority 250.' + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" } @test "helpers: enable the node plugin through the bash-it function" { - run bash-it enable plugin "node" - assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + run bash-it enable plugin "node" + assert_line -n 0 'node enabled with priority 250.' + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: enable the node and nvm plugins through the bash-it function" { - run bash-it enable plugin "node" "nvm" - assert_line -n 0 'node enabled with priority 250.' - assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + run bash-it enable plugin "node" "nvm" + assert_line -n 0 'node enabled with priority 250.' + assert_line -n 1 'nvm enabled with priority 225.' + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { - run bash-it enable plugin "foo-unknown" "nvm" - assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' - assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + run bash-it enable plugin "foo-unknown" "nvm" + assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' + assert_line -n 1 'nvm enabled with priority 225.' + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the nvm plugin" { - run _enable-plugin "nvm" - assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + run _enable-plugin "nvm" + assert_line -n 0 'nvm enabled with priority 225.' + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable an unknown plugin" { - run _enable-plugin "unknown-foo" - assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' + run _enable-plugin "unknown-foo" + assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' - # Check for both old an new structure - assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] + # Check for both old an new structure + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: enable an unknown plugin through the bash-it function" { - run bash-it enable plugin "unknown-foo" - echo "${lines[@]}" - assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' + run bash-it enable plugin "unknown-foo" + echo "${lines[@]}" + assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' - # Check for both old an new structure - assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] + # Check for both old an new structure + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: disable a plugin that is not enabled" { - run _disable-plugin "sdkman" - assert_line -n 0 'sorry, sdkman does not appear to be an enabled plugin.' + run _disable-plugin "sdkman" + assert_line -n 0 'sorry, sdkman does not appear to be an enabled plugin.' } @test "helpers: enable and disable the nvm plugin" { - run _enable-plugin "nvm" - assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" - assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + run _enable-plugin "nvm" + assert_line -n 0 'nvm enabled with priority 225.' + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] - run _disable-plugin "nvm" - assert_line -n 0 'nvm disabled.' - assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] + run _disable-plugin "nvm" + assert_line -n 0 'nvm disabled.' + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] - run _disable-plugin "nvm" - assert_line -n 0 'nvm disabled.' - assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] + run _disable-plugin "nvm" + assert_line -n 0 'nvm disabled.' + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled without a priority" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - run _disable-plugin "nvm" - assert_line -n 0 'nvm disabled.' - assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + run _disable-plugin "nvm" + assert_line -n 0 'nvm disabled.' + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled without a priority" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - run _enable-plugin "nvm" - assert_line -n 0 'nvm is already enabled.' - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] + run _enable-plugin "nvm" + assert_line -n 0 'nvm is already enabled.' + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - run _enable-plugin "nvm" - assert_line -n 0 'nvm is already enabled.' - assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] + run _enable-plugin "nvm" + assert_line -n 0 'nvm is already enabled.' + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin twice" { - run _enable-plugin "nvm" - assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + run _enable-plugin "nvm" + assert_line -n 0 'nvm enabled with priority 225.' + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" - run _enable-plugin "nvm" - assert_line -n 0 'nvm is already enabled.' - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + run _enable-plugin "nvm" + assert_line -n 0 'nvm is already enabled.' + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: profile load command sanity" { - run _bash-it-profile-load "default" - assert_success + 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" - assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" - assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" - assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save command sanity" { - run _enable-plugin "nvm" + run _enable-plugin "nvm" - run _bash-it-profile-save "test" - assert_line -n 0 "Saving plugins configuration..." - assert_line -n 1 "Saving completion configuration..." - assert_line -n 2 "Saving aliases configuration..." - assert_line -n 3 "All done!" - assert_file_exist "${BASH_IT?}/profiles/test.bash_it" + run _bash-it-profile-save "test" + assert_line -n 0 "Saving plugins configuration..." + assert_line -n 1 "Saving completion configuration..." + assert_line -n 2 "Saving aliases configuration..." + assert_line -n 3 "All done!" + assert_file_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile save creates valid file with only plugin enabled" { - run _enable-plugin "nvm" + run _enable-plugin "nvm" - run _bash-it-profile-save "test" - run cat "${BASH_IT?}/profiles/test.bash_it" - assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" - assert_line -n 1 "# plugins" - assert_line -n 2 "plugins nvm" + run _bash-it-profile-save "test" + run cat "${BASH_IT?}/profiles/test.bash_it" + assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" + assert_line -n 1 "# plugins" + assert_line -n 2 "plugins nvm" } @test "helpers: profile save creates valid file with only completion enabled" { - run _enable-completion "bash-it" + run _enable-completion "bash-it" - run _bash-it-profile-save "test" - run cat "${BASH_IT?}/profiles/test.bash_it" - assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" - assert_line -n 1 "# completion" - assert_line -n 2 "completion bash-it" + run _bash-it-profile-save "test" + run cat "${BASH_IT?}/profiles/test.bash_it" + assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" + assert_line -n 1 "# completion" + assert_line -n 2 "completion bash-it" } @test "helpers: profile save creates valid file with only aliases enabled" { - run _enable-alias "general" + run _enable-alias "general" - run _bash-it-profile-save "test" - run cat "${BASH_IT?}/profiles/test.bash_it" - assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" - assert_line -n 1 "# aliases" - assert_line -n 2 "aliases general" + run _bash-it-profile-save "test" + run cat "${BASH_IT?}/profiles/test.bash_it" + assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" + assert_line -n 1 "# aliases" + assert_line -n 2 "aliases general" } @test "helpers: profile edge case, empty configuration" { - run _bash-it-profile-save "test" - assert_success - 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." - - run _enable-alias "general" - assert_success - run _enable-plugin "base" - assert_success - run _enable-completion "aliases" - assert_success - run _enable-completion "bash-it" - assert_success - run _enable-completion "system" - assert_success - - run _bash-it-profile-load "test" - assert_success - assert_line -n 0 "Trying to parse profile 'test'..." - assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" - assert_link_not_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - assert_link_not_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" - assert_link_not_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" - assert_link_not_exist "${BASH_IT?}/enabled/325---system.completion.bash" + run _bash-it-profile-save "test" + assert_success + 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." + + run _enable-alias "general" + assert_success + run _enable-plugin "base" + assert_success + run _enable-completion "aliases" + assert_success + run _enable-completion "bash-it" + assert_success + run _enable-completion "system" + assert_success + + run _bash-it-profile-load "test" + assert_success + assert_line -n 0 "Trying to parse profile 'test'..." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_not_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_not_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save and load" { - run _enable-alias "general" - assert_success - run _enable-plugin "base" - assert_success - run _enable-plugin "alias-completion" - assert_success - run _enable-completion "bash-it" - assert_success - run _enable-completion "system" - assert_success - - run _bash-it-profile-save "test" - assert_success - - run _disable-alias "general" - assert_success - assert_output "general disabled." - assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" - run _bash-it-profile-load "test" - assert_success - assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + run _enable-alias "general" + assert_success + run _enable-plugin "base" + assert_success + run _enable-plugin "alias-completion" + assert_success + run _enable-completion "bash-it" + assert_success + run _enable-completion "system" + assert_success + + run _bash-it-profile-save "test" + assert_success + + run _disable-alias "general" + assert_success + assert_output "general disabled." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + run _bash-it-profile-load "test" + assert_success + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" } @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..." + run _bash-it-profile-load "test-bad-component" + assert_line -n 1 -p "Bad line(#12) in profile, aborting load..." } @test "helpers: profile load corrupted profile file: bad subdirectory" { - run _bash-it-profile-load "test-bad-type" - assert_line -n 1 -p "Bad line(#4) in profile, aborting load..." + run _bash-it-profile-load "test-bad-type" + assert_line -n 1 -p "Bad line(#4) in profile, aborting load..." } @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_file_not_exist "${BASH_IT?}/profiles/test.bash_it" + 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_file_not_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile rm no params" { - run _bash-it-profile-rm "" - assert_line -n 0 -p "Please specify profile name to remove..." + run _bash-it-profile-rm "" + assert_line -n 0 -p "Please specify profile name to remove..." } @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..." + run _bash-it-profile-load "" + assert_line -n 0 -p "Please specify profile name to load, not changing configuration..." } @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" + 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 "helpers: profile rm bad profile name" { - run _bash-it-profile-rm "notexisting" - assert_line -n 0 -p "Could not find profile 'notexisting'..." + run _bash-it-profile-rm "notexisting" + assert_line -n 0 -p "Could not find profile 'notexisting'..." } @test "helpers: profile list sanity" { - run _bash-it-profile-list - assert_line -n 0 "Available profiles:" - assert_line -n 1 "default" + run _bash-it-profile-list + assert_line -n 0 "Available profiles:" + assert_line -n 1 "default" } @test "helpers: profile list more profiles" { - run _bash-it-profile-save "cactus" - run _bash-it-profile-save "another" - run _bash-it-profile-save "brother" - run _bash-it-profile-list - assert_line -n 0 "Available profiles:" - assert_line -n 4 "default" - assert_line -n 3 "cactus" - assert_line -n 1 "another" - assert_line -n 2 "brother" + run _bash-it-profile-save "cactus" + run _bash-it-profile-save "another" + run _bash-it-profile-save "brother" + run _bash-it-profile-list + assert_line -n 0 "Available profiles:" + assert_line -n 4 "default" + assert_line -n 3 "cactus" + assert_line -n 1 "another" + assert_line -n 2 "brother" } @test "helpers: migrate plugins and completions that share the same name" { - ln -s "${BASH_IT?}/completion/available/dirs.completion.bash" "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" - assert_link_exist "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" + ln -s "${BASH_IT?}/completion/available/dirs.completion.bash" "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" - ln -s "${BASH_IT?}/plugins/available/dirs.plugin.bash" "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/dirs.plugin.bash" "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" - run _bash-it-migrate - assert_line -n 0 'Migrating plugin dirs.' - assert_line -n 1 'dirs disabled.' - assert_line -n 2 'dirs enabled with priority 250.' - assert_line -n 3 'Migrating completion dirs.' - assert_line -n 4 'dirs disabled.' - assert_line -n 5 'dirs enabled with priority 350.' - assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' + run _bash-it-migrate + assert_line -n 0 'Migrating plugin dirs.' + assert_line -n 1 'dirs disabled.' + assert_line -n 2 'dirs enabled with priority 250.' + assert_line -n 3 'Migrating completion dirs.' + assert_line -n 4 'dirs disabled.' + assert_line -n 5 'dirs enabled with priority 350.' + assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_link_exist "${BASH_IT?}/enabled/350---dirs.completion.bash" - assert_link_exist "${BASH_IT?}/enabled/250---dirs.plugin.bash" - assert [ ! -L "${BASH_IT?}/completion/enabled/350----dirs.completion.bash" ] - assert [ ! -L "${BASH_IT?}/plugins/enabled/250----dirs.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/250---dirs.plugin.bash" + assert [ ! -L "${BASH_IT?}/completion/enabled/350----dirs.completion.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----dirs.plugin.bash" ] } @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" - run _enable-plugin "ssh" - assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + run _enable-plugin "ssh" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" - run _bash-it-migrate - assert_line -n 0 'Migrating alias todo.txt-cli.' - assert_line -n 1 'todo.txt-cli disabled.' - assert_line -n 2 'todo.txt-cli enabled with priority 150.' + run _bash-it-migrate + assert_line -n 0 'Migrating alias todo.txt-cli.' + assert_line -n 1 'todo.txt-cli disabled.' + assert_line -n 2 'todo.txt-cli enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "${BASH_IT?}/plugins/enabled/node.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" ] } @test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" - run _enable-plugin "ssh" - assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + run _enable-plugin "ssh" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" - run _bash-it-migrate - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "${BASH_IT?}/plugins/enabled/225----node.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/plugins/enabled/250----nvm.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/aliases/enabled/250----todo.txt-cli.aliases.bash" ] + run _bash-it-migrate + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225----node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/250----todo.txt-cli.aliases.bash" ] } @test "helpers: run the migrate command without anything to migrate and nothing enabled" { - run _bash-it-migrate + run _bash-it-migrate } @test "helpers: run the migrate command without anything to migrate" { - run _enable-plugin "ssh" - assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + run _enable-plugin "ssh" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" - run _bash-it-migrate - assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + run _bash-it-migrate + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" } function __migrate_all_components() { - subdirectory="${1:-}" - one_type="${2:-}" - priority="${3:-}" + subdirectory="${1:-}" + one_type="${2:-}" + priority="${3:-}" - for f in "${BASH_IT}/$subdirectory/available/"*.bash - do - to_enable=$(basename "$f") - if [[ -z "$priority" ]]; then - ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable" - else - ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable" - fi - done + for f in "${BASH_IT}/$subdirectory/available/"*.bash; do + to_enable=$(basename "$f") + if [[ -z "$priority" ]]; then + ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable" + else + ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable" + fi + done - ls "${BASH_IT?}/${subdirectory}/enabled" + ls "${BASH_IT?}/${subdirectory}/enabled" - all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs) - all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) + all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs) + all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) - assert_equal "$all_available" "$all_enabled_old" + assert_equal "$all_available" "$all_enabled_old" - run bash-it migrate + run bash-it migrate - all_enabled_old_after=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) - assert_equal "0" "$all_enabled_old_after" + all_enabled_old_after=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) + assert_equal "0" "$all_enabled_old_after" - all_enabled_new_after=$(compgen -G "${BASH_IT}/enabled/*.$one_type.bash" | wc -l | xargs) - assert_equal "$all_enabled_old" "$all_enabled_new_after" + all_enabled_new_after=$(compgen -G "${BASH_IT}/enabled/*.$one_type.bash" | wc -l | xargs) + assert_equal "$all_enabled_old" "$all_enabled_new_after" } @test "helpers: migrate all plugins" { - subdirectory="plugins" - one_type="plugin" + subdirectory="plugins" + one_type="plugin" - run __migrate_all_components "$subdirectory" "$one_type" - assert_success + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all aliases" { - subdirectory="aliases" - one_type="aliases" + subdirectory="aliases" + one_type="aliases" - run __migrate_all_components "$subdirectory" "$one_type" - assert_success + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all completions" { - subdirectory="completion" - one_type="completion" + subdirectory="completion" + one_type="completion" - run __migrate_all_components "$subdirectory" "$one_type" - assert_success + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all plugins with previous priority" { - subdirectory="plugins" - one_type="plugin" + subdirectory="plugins" + one_type="plugin" - run __migrate_all_components "$subdirectory" "$one_type" "100" - assert_success + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all aliases with previous priority" { - subdirectory="aliases" - one_type="aliases" + subdirectory="aliases" + one_type="aliases" - run __migrate_all_components "$subdirectory" "$one_type" "100" - assert_success + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all completions with previous priority" { - subdirectory="completion" - one_type="completion" + subdirectory="completion" + one_type="completion" - run __migrate_all_components "$subdirectory" "$one_type" "100" - assert_success + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: verify that existing components are automatically migrated when something is enabled" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - run bash-it enable plugin "node" - assert_line -n 0 'Migrating plugin nvm.' - assert_line -n 1 'nvm disabled.' - assert_line -n 2 'nvm enabled with priority 225.' - assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_line -n 4 'node enabled with priority 250.' - assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + run bash-it enable plugin "node" + assert_line -n 0 'Migrating plugin nvm.' + assert_line -n 1 'nvm disabled.' + assert_line -n 2 'nvm enabled with priority 225.' + assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' + assert_line -n 4 'node enabled with priority 250.' + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: verify that existing components are automatically migrated when something is disabled" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - - run bash-it disable plugin "node" - assert_line -n 0 'Migrating plugin node.' - assert_line -n 1 'node disabled.' - assert_line -n 2 'node enabled with priority 250.' - assert_line -n 3 'Migrating plugin nvm.' - assert_line -n 4 'nvm disabled.' - assert_line -n 5 'nvm enabled with priority 225.' - assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_line -n 7 'node disabled.' - assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" - assert [ ! -L "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" ] - assert [ ! -L "${BASH_IT?}/enabled/250---node.plugin.bash" ] + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + + run bash-it disable plugin "node" + assert_line -n 0 'Migrating plugin node.' + assert_line -n 1 'node disabled.' + assert_line -n 2 'node enabled with priority 250.' + assert_line -n 3 'Migrating plugin nvm.' + assert_line -n 4 'nvm disabled.' + assert_line -n 5 'nvm enabled with priority 225.' + assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' + assert_line -n 7 'node disabled.' + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---node.plugin.bash" ] } @test "helpers: enable all plugins" { - local available enabled - run _enable-plugin "all" - available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) - enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) - assert_equal "$available" "$enabled" + local available enabled + run _enable-plugin "all" + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) + assert_equal "$available" "$enabled" } @test "helpers: disable all plugins" { - local available enabled enabled2 - run _enable-plugin "all" - available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) - enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) - assert_equal "$available" "$enabled" + local available enabled enabled2 + run _enable-plugin "all" + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) + assert_equal "$available" "$enabled" - run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _enable-alias "ag" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _disable-plugin "all" - enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) - assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _disable-plugin "all" + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) + assert_equal "0" "$enabled2" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure" { - local enabled enabled2 - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" - enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) - assert_equal "2" "$enabled" + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) + assert_equal "2" "$enabled" - run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _enable-alias "ag" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _disable-plugin "all" - enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) - assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _disable-plugin "all" + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) + assert_equal "0" "$enabled2" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure with priority" { - local enabled enabled2 - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" - ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) - assert_equal "2" "$enabled" + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) + assert_equal "2" "$enabled" - run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _enable-alias "ag" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _disable-plugin "all" - enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) - assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _disable-plugin "all" + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) + assert_equal "0" "$enabled2" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins without anything enabled" { - local enabled enabled2 - enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) - assert_equal "0" "$enabled" + local enabled enabled2 + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) + assert_equal "0" "$enabled" - run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _enable-alias "ag" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _disable-plugin "all" - enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) - assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _disable-plugin "all" + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) + assert_equal "0" "$enabled2" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: enable the ansible aliases through the bash-it function" { - run bash-it enable alias "ansible" - assert_line -n 0 'ansible enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---ansible.aliases.bash" + run bash-it enable alias "ansible" + assert_line -n 0 'ansible enabled with priority 150.' + assert_link_exist "${BASH_IT?}/enabled/150---ansible.aliases.bash" } @test "helpers: describe the nvm plugin without enabling it" { - _bash-it-plugins | grep "nvm" | grep "\[ \]" + _bash-it-plugins | grep "nvm" | grep "\[ \]" } @test "helpers: describe the nvm plugin after enabling it" { - run _enable-plugin "nvm" - assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + run _enable-plugin "nvm" + assert_line -n 0 'nvm enabled with priority 225.' + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" - _bash-it-plugins | grep "nvm" | grep "\[x\]" + _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - _bash-it-plugins | grep "nvm" | grep "\[x\]" + _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory with priority" { - ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - _bash-it-plugins | grep "nvm" | grep "\[x\]" + _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the todo.txt-cli aliases without enabling them" { - run _bash-it-aliases - assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations" + run _bash-it-aliases + assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations" } diff --git a/test/lib/log.bats b/test/lib/log.bats index 906d5fa22c..017558efc0 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -4,82 +4,81 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "log" + setup_libs "log" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} - run _log_debug "test test test" - assert_output "DEBUG: default: test test test" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} + run _log_debug "test test test" + assert_output "DEBUG: default: test test test" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} - run _log_warning "test test test" - assert_output " WARN: default: test test test" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} + run _log_warning "test test test" + assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} - run _log_error "test test test" - assert_output "ERROR: default: test test test" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} + run _log_error "test test test" + assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} - run _log_debug "test test test" - assert_output "" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} + run _log_debug "test test test" + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} - run _log_warning "test test test" - assert_output " WARN: default: test test test" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} + run _log_warning "test test test" + assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} - run _log_error "test test test" - assert_output "ERROR: default: test test test" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} + run _log_error "test test test" + assert_output "ERROR: default: test test test" } - @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} - run _log_debug "test test test" - assert_output "" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} + run _log_debug "test test test" + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} - run _log_warning "test test test" - assert_output "" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} + run _log_warning "test test test" + assert_output "" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} - run _log_error "test test test" - assert_output "ERROR: default: test test test" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} + run _log_error "test test test" + assert_output "ERROR: default: test test test" } @test "lib log: basic debug silent logging" { - run _log_debug "test test test" - assert_output "" + run _log_debug "test test test" + assert_output "" } @test "lib log: basic warning silent logging" { - run _log_warning "test test test" - assert_output "" + run _log_warning "test test test" + assert_output "" } @test "lib log: basic error silent logging" { - run _log_error "test test test" - assert_output "" + run _log_error "test test test" + assert_output "" } @test "lib log: logging with prefix" { - BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} - BASH_IT_LOG_PREFIX="nice: prefix: " - run _log_debug "test test test" - assert_output "DEBUG: nice: prefix: test test test" + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} + BASH_IT_LOG_PREFIX="nice: prefix: " + run _log_debug "test test test" + assert_output "DEBUG: nice: prefix: test test test" } diff --git a/test/lib/search.bats b/test/lib/search.bats index 99b7cc39c6..bcd67168f0 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -3,92 +3,90 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "search" + setup_libs "search" } function local_setup() { - # shellcheck disable=SC2034 - BASH_IT_SEARCH_USE_COLOR=false + # shellcheck disable=SC2034 + BASH_IT_SEARCH_USE_COLOR=false } @test "search: plugin base" { - run _bash-it-search-component 'plugins' 'base' - assert_success - assert_line -n 0 ' plugins: base ' + run _bash-it-search-component 'plugins' 'base' + assert_success + assert_line -n 0 ' plugins: base ' } @test "search: git" { - local plugin completion - run _bash-it-search 'git' --no-color - assert_success - assert_line -n 0 ' aliases: git gitsvn ' - assert_line -n 1 -p ' plugins:' - for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump" - do - assert_line -n 1 -p "$plugin" - done - for completion in "git" "git_flow" "git_flow_avh" "github-cli" - do - assert_line -n 2 -p "$completion" - done + local plugin completion + run _bash-it-search 'git' --no-color + assert_success + assert_line -n 0 ' aliases: git gitsvn ' + assert_line -n 1 -p ' plugins:' + for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump"; do + assert_line -n 1 -p "$plugin" + done + for completion in "git" "git_flow" "git_flow_avh" "github-cli"; do + assert_line -n 2 -p "$completion" + done } @test "search: ruby gem bundle rake rails" { - run _bash-it-search rails ruby gem bundler rake --no-color - assert_success + run _bash-it-search rails ruby gem bundler rake --no-color + assert_success - assert_line -n 0 ' aliases: bundler rails ' - assert_line -n 1 ' plugins: chruby chruby-auto rails ruby ' - assert_line -n 2 ' completions: bundler gem rake ' + assert_line -n 0 ' aliases: bundler rails ' + assert_line -n 1 ' plugins: chruby chruby-auto rails ruby ' + assert_line -n 2 ' completions: bundler gem rake ' } @test "search: rails ruby gem bundler rake -chruby" { - run _bash-it-search rails ruby gem bundler rake -chruby --no-color - assert_success + run _bash-it-search rails ruby gem bundler rake -chruby --no-color + assert_success - assert_line -n 0 ' aliases: bundler rails ' - assert_line -n 1 ' plugins: rails ruby ' - assert_line -n 2 ' completions: bundler gem rake ' + assert_line -n 0 ' aliases: bundler rails ' + assert_line -n 1 ' plugins: rails ruby ' + assert_line -n 2 ' completions: bundler gem rake ' } @test "search: @git" { - run _bash-it-search '@git' --no-color - assert_success - assert_line -n 0 ' aliases: git ' - assert_line -n 1 ' plugins: git ' - assert_line -n 2 ' completions: git ' + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 ' aliases: git ' + assert_line -n 1 ' plugins: git ' + assert_line -n 2 ' completions: git ' } @test "search: @git --enable / --disable" { - run _bash-it-search '@git' --enable --no-color - assert_success - run _bash-it-search '@git' --no-color - assert_success - assert_line -n 0 -p '✓' - - run _bash-it-search '@git' --disable --no-color - assert_success - run _bash-it-search '@git' --no-color - assert_success - - assert_line -n 0 ' aliases: git ' - assert_line -n 1 ' plugins: git ' - assert_line -n 2 ' completions: git ' + run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p '✓' + + run _bash-it-search '@git' --disable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + + assert_line -n 0 ' aliases: git ' + assert_line -n 1 ' plugins: git ' + assert_line -n 2 ' completions: git ' } @test "search: @git --disable / --enable" { - run _bash-it-search '@git' --disable --no-color - assert_success - run _bash-it-search '@git' --no-color - assert_success - - assert_line -n 0 ' aliases: git ' - assert_line -n 1 ' plugins: git ' - assert_line -n 2 ' completions: git ' - - run _bash-it-search '@git' --enable --no-color - assert_success - run _bash-it-search '@git' --no-color - assert_success - assert_line -n 0 -p '✓' + run _bash-it-search '@git' --disable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + + assert_line -n 0 ' aliases: git ' + assert_line -n 1 ' plugins: git ' + assert_line -n 2 ' completions: git ' + + run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p '✓' } diff --git a/test/lib/utilities.bats b/test/lib/utilities.bats index 78913870e5..7d8284e6a4 100644 --- a/test/lib/utilities.bats +++ b/test/lib/utilities.bats @@ -3,81 +3,81 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" + setup_libs "helpers" } @test "_bash-it-component-item-is-enabled() - for a disabled item" { - run _bash-it-component-item-is-enabled aliases svn - assert_failure + run _bash-it-component-item-is-enabled aliases svn + assert_failure } @test "_bash-it-component-item-is-enabled() - for an enabled/disabled item" { - run bash-it enable alias svn - assert_line -n 0 'svn enabled with priority 150.' + run bash-it enable alias svn + assert_line -n 0 'svn enabled with priority 150.' - run _bash-it-component-item-is-enabled alias svn - assert_success - run _bash-it-component-item-is-disabled alias svn - assert_failure + run _bash-it-component-item-is-enabled alias svn + assert_success + run _bash-it-component-item-is-disabled alias svn + assert_failure - run bash-it disable alias svn - assert_line -n 0 'svn disabled.' + run bash-it disable alias svn + assert_line -n 0 'svn disabled.' - run _bash-it-component-item-is-enabled alias svn - assert_failure - run _bash-it-component-item-is-disabled alias svn - assert_success + run _bash-it-component-item-is-enabled alias svn + assert_failure + run _bash-it-component-item-is-disabled alias svn + assert_success } @test "_bash-it-component-item-is-disabled() - for a disabled item" { - run _bash-it-component-item-is-disabled alias svn - assert_success + run _bash-it-component-item-is-disabled alias svn + assert_success } @test "_bash-it-component-item-is-disabled() - for an enabled/disabled item" { - run bash-it enable alias svn - assert_line -n 0 'svn enabled with priority 150.' + run bash-it enable alias svn + assert_line -n 0 'svn enabled with priority 150.' - run _bash-it-component-item-is-disabled alias svn - assert_failure - run _bash-it-component-item-is-enabled alias svn - assert_success + run _bash-it-component-item-is-disabled alias svn + assert_failure + run _bash-it-component-item-is-enabled alias svn + assert_success - run bash-it disable alias svn - assert_line -n 0 'svn disabled.' + run bash-it disable alias svn + assert_line -n 0 'svn disabled.' - run _bash-it-component-item-is-disabled alias svn - assert_success - run _bash-it-component-item-is-enabled alias svn - assert_failure + run _bash-it-component-item-is-disabled alias svn + assert_success + run _bash-it-component-item-is-enabled alias svn + assert_failure } @test "_bash-it-array-contains-element() - when match is found, and is the first" { - declare -a fruits=(apple pear orange mandarin) - run _bash-it-array-contains-element apple "${fruits[@]}" - assert_success + declare -a fruits=(apple pear orange mandarin) + run _bash-it-array-contains-element apple "${fruits[@]}" + assert_success } @test "_bash-it-array-contains-element() - when match is found, and is the last" { - declare -a fruits=(apple pear orange mandarin) - run _bash-it-array-contains-element mandarin "${fruits[@]}" - assert_success + declare -a fruits=(apple pear orange mandarin) + run _bash-it-array-contains-element mandarin "${fruits[@]}" + assert_success } @test "_bash-it-array-contains-element() - when match is found, and is in the middle" { - declare -a fruits=(apple pear orange mandarin) - run _bash-it-array-contains-element pear "${fruits[@]}" - assert_success + declare -a fruits=(apple pear orange mandarin) + run _bash-it-array-contains-element pear "${fruits[@]}" + assert_success } @test "_bash-it-array-contains-element() - when match is found, and it has spaces" { - declare -a fruits=(apple pear orange mandarin "yellow watermelon") - run _bash-it-array-contains-element "yellow watermelon" "${fruits[@]}" - assert_success + declare -a fruits=(apple pear orange mandarin "yellow watermelon") + run _bash-it-array-contains-element "yellow watermelon" "${fruits[@]}" + assert_success } @test "_bash-it-array-contains-element() - when match is not found" { - declare -a fruits=(apple pear orange mandarin) - run _bash-it-array-contains-element xyz "${fruits[@]}" - assert_failure + declare -a fruits=(apple pear orange mandarin) + run _bash-it-array-contains-element xyz "${fruits[@]}" + assert_failure } diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 11b8ee0cf5..b45ae07999 100644 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -3,76 +3,76 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" - load "${BASH_IT?}/plugins/available/base.plugin.bash" + setup_libs "helpers" + load "${BASH_IT?}/plugins/available/base.plugin.bash" } @test 'plugins base: ips()' { - readonly localhost='127.0.0.1' - run ips - assert_success - assert_line "$localhost" + readonly localhost='127.0.0.1' + run ips + assert_success + assert_line "$localhost" } @test 'plugins base: myip()' { - local mask_ip - run myip - assert_success - shopt -s extglob - mask_ip="${output//+([[:digit:]]|[[:digit:]][[:digit:]]|[[:digit:]][[:digit:]][[:digit:]])/?}" #$(echo "$output" | tr -s '0-9' '?') - [[ $mask_ip == 'Your public IP is: ?.?.?.? ' ]] + local mask_ip + run myip + assert_success + shopt -s extglob + mask_ip="${output//+([[:digit:]]|[[:digit:]][[:digit:]]|[[:digit:]][[:digit:]][[:digit:]])/?}" #$(echo "$output" | tr -s '0-9' '?') + [[ $mask_ip == 'Your public IP is: ?.?.?.? ' ]] } @test 'plugins base: pickfrom()' { - stub_file="${BATS_TEST_TMPDIR?}/stub_file" - printf "l1\nl2\nl3" > "$stub_file" - run pickfrom "$stub_file" - assert_success - [[ $output == l? ]] + stub_file="${BATS_TEST_TMPDIR?}/stub_file" + printf "l1\nl2\nl3" > "$stub_file" + run pickfrom "$stub_file" + assert_success + [[ $output == l? ]] } @test 'plugins base: mkcd()' { - cd "${BATS_TEST_TMPDIR?}" - declare -r dir_name="-dir_with_dash" + cd "${BATS_TEST_TMPDIR?}" + declare -r dir_name="-dir_with_dash" - # Make sure that the directory does not exist prior to the test - rm -rf "${BATS_TEST_TMPDIR:?}/${dir_name}" + # Make sure that the directory does not exist prior to the test + rm -rf "${BATS_TEST_TMPDIR:?}/${dir_name}" - run mkcd "${dir_name}" - assert_success - assert_dir_exist "${BATS_TEST_TMPDIR?}/${dir_name}" + run mkcd "${dir_name}" + assert_success + assert_dir_exist "${BATS_TEST_TMPDIR?}/${dir_name}" - mkcd "${dir_name}" - assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}" + mkcd "${dir_name}" + assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}" } @test 'plugins base: lsgrep()' { - for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done - cd "${BASH_IT?}" - run lsgrep 2 - assert_success - assert_equal "$output" 2 + for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done + cd "${BASH_IT?}" + run lsgrep 2 + assert_success + assert_equal "$output" 2 } @test 'plugins base: buf()' { - declare -r file="${BATS_TEST_TMPDIR?}/file" - touch "$file" + declare -r file="${BATS_TEST_TMPDIR?}/file" + touch "$file" - # Take one timestamp before running the `buf` function - declare -r stamp1=$(date +%Y%m%d_%H%M%S) + # Take one timestamp before running the `buf` function + declare -r stamp1=$(date +%Y%m%d_%H%M%S) - run buf "$file" + run buf "$file" - # Take another timestamp after running `buf`. - declare -r stamp2=$(date +%Y%m%d_%H%M%S) + # Take another timestamp after running `buf`. + declare -r stamp2=$(date +%Y%m%d_%H%M%S) - # Verify that the backup file ends with one of the two timestamps. - # This is done to avoid race conditions where buf is run close to the end - # of a second, in which case the second timestamp might be in the next second, - # causing the test to fail. - # By using `or` for the two checks, we can verify that one of the two files is present. - # In most cases, it's going to have the same timestamp anyway. - # We can't use `assert_file_exist` here, since it only checks for a single file name. - assert [ -e "${file}_${stamp1}" \ - -o -e "${file}_${stamp2}" ] + # Verify that the backup file ends with one of the two timestamps. + # This is done to avoid race conditions where buf is run close to the end + # of a second, in which case the second timestamp might be in the next second, + # causing the test to fail. + # By using `or` for the two checks, we can verify that one of the two files is present. + # In most cases, it's going to have the same timestamp anyway. + # We can't use `assert_file_exist` here, since it only checks for a single file name. + assert [ -e "${file}_${stamp1}" \ + -o -e "${file}_${stamp2}" ] } diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 49199ef27c..9fbcb24fbc 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -3,8 +3,8 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" - load "${BASH_IT?}/plugins/available/battery.plugin.bash" + setup_libs "helpers" + load "${BASH_IT?}/plugins/available/battery.plugin.bash" } # Sets up the `_command_exists` function so that it only responds `true` if called with @@ -20,18 +20,18 @@ function local_setup_file() { # It's cool that Bash allows to define functions within functions, works almost like # a closure in JavaScript. function setup_command_exists { - success_command="$1" - - function _command_exists { - case "$1" in - "${success_command}") - true - ;; - *) - false - ;; - esac - } + success_command="$1" + + function _command_exists { + case "$1" in + "${success_command}") + true + ;; + *) + false + ;; + esac + } } ####################### @@ -40,10 +40,10 @@ function setup_command_exists { # @test 'plugins battery: battery-percentage with no tool' { - setup_command_exists "fooooo" + setup_command_exists "fooooo" - run battery_percentage - assert_output "no" + run battery_percentage + assert_output "no" } ####################### @@ -54,56 +54,56 @@ function setup_command_exists { # Creates a `pmset` function that simulates output like the real `pmset` command. # The passed in parameter is used for the remaining battery percentage. function setup_pmset { - percent="$1" + percent="$1" - function pmset { - printf "\-InternalBattery-0 (id=12345) %s; discharging; 16:00 remaining present: true" "${percent}" - } + function pmset { + printf "\-InternalBattery-0 (id=12345) %s; discharging; 16:00 remaining present: true" "${percent}" + } } @test 'plugins battery: battery-percentage with pmset, 100%' { - setup_command_exists "pmset" + setup_command_exists "pmset" - setup_pmset "100%" + setup_pmset "100%" - run battery_percentage - assert_output "100" + run battery_percentage + assert_output "100" } @test 'plugins battery: battery-percentage with pmset, 98%' { - setup_command_exists "pmset" + setup_command_exists "pmset" - setup_pmset "98%" + setup_pmset "98%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with pmset, 98.5%' { - setup_command_exists "pmset" + setup_command_exists "pmset" - setup_pmset "98.5%" + setup_pmset "98.5%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with pmset, 4%' { - setup_command_exists "pmset" + setup_command_exists "pmset" - setup_pmset "4%" + setup_pmset "4%" - run battery_percentage - assert_output "04" + run battery_percentage + assert_output "04" } @test 'plugins battery: battery-percentage with pmset, no status' { - setup_command_exists "pmset" + setup_command_exists "pmset" - setup_pmset "" + setup_pmset "" - run battery_percentage - assert_output "-1" + run battery_percentage + assert_output "-1" } ####################### @@ -116,75 +116,75 @@ function setup_pmset { # 1) the remaining battery percentage. # 2) the battery status function setup_acpi { - percent="$1" - status="$2" + percent="$1" + status="$2" - function acpi { - printf "Battery 0: %s, %s, 01:02:48 until charged" "${status}" "${percent}" - } + function acpi { + printf "Battery 0: %s, %s, 01:02:48 until charged" "${status}" "${percent}" + } } @test 'plugins battery: battery-percentage with acpi, 100% Full' { - setup_command_exists "acpi" + setup_command_exists "acpi" - setup_acpi "100%" "Full" + setup_acpi "100%" "Full" - run battery_percentage - assert_output "100" + run battery_percentage + assert_output "100" } @test 'plugins battery: battery-percentage with acpi, 98% Charging' { - setup_command_exists "acpi" + setup_command_exists "acpi" - setup_acpi "98%" "Charging" + setup_acpi "98%" "Charging" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with acpi, 98% Discharging' { - setup_command_exists "acpi" + setup_command_exists "acpi" - setup_acpi "98%" "Discharging" + setup_acpi "98%" "Discharging" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with acpi, 98% Unknown' { - setup_command_exists "acpi" + setup_command_exists "acpi" - setup_acpi "98%" "Unknown" + setup_acpi "98%" "Unknown" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with acpi, 4% Charging' { - setup_command_exists "acpi" + setup_command_exists "acpi" - setup_acpi "4%" "Charging" + setup_acpi "4%" "Charging" - run battery_percentage - assert_output "04" + run battery_percentage + assert_output "04" } @test 'plugins battery: battery-percentage with acpi, 4% no status' { - setup_command_exists "acpi" + setup_command_exists "acpi" - setup_acpi "4%" "" + setup_acpi "4%" "" - run battery_percentage - assert_output "04" + run battery_percentage + assert_output "04" } @test 'plugins battery: battery-percentage with acpi, no status' { - setup_command_exists "acpi" + setup_command_exists "acpi" - setup_acpi "" "" + setup_acpi "" "" - run battery_percentage - assert_output "-1" + run battery_percentage + assert_output "-1" } ####################### @@ -200,64 +200,63 @@ function setup_upower { function upower { case $1 in - '-e'|'--enumerate') - printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" - ;; - '-i'|'--show-info') - if [[ $2 == "$BAT0" ]] - then - printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" - else - false - fi - ;; + '-e' | '--enumerate') + printf '%s\n' "$BAT0" "/org/freedesktop/UPower/devices/mouse_hid_${RANDOM}_battery" + ;; + '-i' | '--show-info') + if [[ $2 == "$BAT0" ]]; then + printf "voltage: 12.191 V\n time to full: 57.3 minutes\n percentage: %s\n capacity: 84.6964" "${percent}" + else + false + fi + ;; esac } } @test 'plugins battery: battery-percentage with upower, 100%' { - setup_command_exists "upower" + setup_command_exists "upower" - setup_upower "100.00%" + setup_upower "100.00%" - run battery_percentage - assert_output "100" + run battery_percentage + assert_output "100" } @test 'plugins battery: battery-percentage with upower, 98%' { - setup_command_exists "upower" + setup_command_exists "upower" - setup_upower "98.4567%" + setup_upower "98.4567%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with upower, 98.5%' { - setup_command_exists "upower" + setup_command_exists "upower" - setup_upower "98.5%" + setup_upower "98.5%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with upower, 4%' { - setup_command_exists "upower" + setup_command_exists "upower" - setup_upower "4.2345%" + setup_upower "4.2345%" - run battery_percentage - assert_output "04" + run battery_percentage + assert_output "04" } @test 'plugins battery: battery-percentage with upower, no output' { - setup_command_exists "upower" + setup_command_exists "upower" - setup_upower "" + setup_upower "" - run battery_percentage - assert_output "-1" + run battery_percentage + assert_output "-1" } ####################### @@ -268,59 +267,59 @@ function setup_upower { # Creates a `ioreg` function that simulates output like the real `ioreg` command. # The passed in parameter is used for the remaining battery percentage. function setup_ioreg { - percent="$1" + percent="$1" - function ioreg { - printf "\"MaxCapacity\" = 100\n\"CurrentCapacity\" = %s" "${percent}" - } + function ioreg { + printf "\"MaxCapacity\" = 100\n\"CurrentCapacity\" = %s" "${percent}" + } } @test 'plugins battery: battery-percentage with ioreg, 100%' { - setup_command_exists "ioreg" + setup_command_exists "ioreg" - setup_ioreg "100%" + setup_ioreg "100%" - run battery_percentage - assert_output "100" + run battery_percentage + assert_output "100" } @test 'plugins battery: battery-percentage with ioreg, 98%' { - setup_command_exists "ioreg" + setup_command_exists "ioreg" - setup_ioreg "98%" + setup_ioreg "98%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with ioreg, 98.5%' { - setup_command_exists "ioreg" + setup_command_exists "ioreg" - setup_ioreg "98.5%" + setup_ioreg "98.5%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with ioreg, 4%' { - setup_command_exists "ioreg" + setup_command_exists "ioreg" - setup_ioreg "4%" + setup_ioreg "4%" - run battery_percentage - assert_output "04" + run battery_percentage + assert_output "04" } @test 'plugins battery: battery-percentage with ioreg, no status' { - setup_command_exists "ioreg" + setup_command_exists "ioreg" - # Simulate that no battery is present - function ioreg { - printf "" - } + # Simulate that no battery is present + function ioreg { + printf "" + } - run battery_percentage - assert_output "-1" + run battery_percentage + assert_output "-1" } ####################### @@ -331,54 +330,54 @@ function setup_ioreg { # Creates a `WMIC` function that simulates output like the real `WMIC` command. # The passed in parameter is used for the remaining battery percentage. function setup_WMIC { - percent="$1" + percent="$1" - function WMIC { - printf "Charge: %s" "${percent}" - } + function WMIC { + printf "Charge: %s" "${percent}" + } } @test 'plugins battery: battery-percentage with WMIC, 100%' { - setup_command_exists "WMIC" + setup_command_exists "WMIC" - setup_WMIC "100%" + setup_WMIC "100%" - run battery_percentage - assert_output "100" + run battery_percentage + assert_output "100" } @test 'plugins battery: battery-percentage with WMIC, 98%' { - setup_command_exists "WMIC" + setup_command_exists "WMIC" - setup_WMIC "98%" + setup_WMIC "98%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with WMIC, 98.5%' { - setup_command_exists "WMIC" + setup_command_exists "WMIC" - setup_WMIC "98.5%" + setup_WMIC "98.5%" - run battery_percentage - assert_output "98" + run battery_percentage + assert_output "98" } @test 'plugins battery: battery-percentage with WMIC, 4%' { - setup_command_exists "WMIC" + setup_command_exists "WMIC" - setup_WMIC "4%" + setup_WMIC "4%" - run battery_percentage - assert_output "04" + run battery_percentage + assert_output "04" } @test 'plugins battery: battery-percentage with WMIC, no status' { - setup_command_exists "WMIC" + setup_command_exists "WMIC" - setup_WMIC "" + setup_WMIC "" - run battery_percentage - assert_output "-1" + run battery_percentage + assert_output "-1" } diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index e120e9ef6b..a849dca8f8 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -4,8 +4,8 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "command_duration" - load "${BASH_IT?}/plugins/available/cmd-returned-notify.plugin.bash" + setup_libs "command_duration" + load "${BASH_IT?}/plugins/available/cmd-returned-notify.plugin.bash" } @test "plugins cmd-returned-notify: notify after elapsed time" { diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index b8fb779a4b..69cb8fef61 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -4,72 +4,71 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" + setup_libs "helpers" } -function setup_go_path() -{ - local go_path="$1" +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 available + assert_dir_exist "$go_path/bin" - # Make sure that the requested GO folder is on the path - export GOPATH="$go_path:${GOPATH:-}" + # 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 "${BASH_IT?}/plugins/available/go.plugin.bash" - run type -t _bash-it-gopath-pathmunge - assert_line 'function' + { _command_exists go && go version &> /dev/null; } || skip 'golang not found' + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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 "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin" + { _command_exists go && go version &> /dev/null; } || skip 'golang not found' + setup_go_path "$BASH_IT/test/fixtures/go/gopath" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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 "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin" + { _command_exists go && go version &> /dev/null; } || skip 'golang not found' + setup_go_path "$BASH_IT/test/fixtures/go/go path" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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 "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin" + skip 'huh?' + { _command_exists go && go version &> /dev/null; } || skip 'golang not found' + setup_go_path "$BASH_IT/test/fixtures/go/go\ path" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + 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 "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" + { _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 "${BASH_IT?}/plugins/available/go.plugin.bash" + 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 "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + { _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 "${BASH_IT?}/plugins/available/go.plugin.bash" + 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 "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + 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 "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" } diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index a6ff87c4f3..fbdce6cde7 100644 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -3,30 +3,30 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" + setup_libs "helpers" } @test "plugins ruby: remove_gem is defined" { - run load "${BASH_IT?}/plugins/available/ruby.plugin.bash" - assert_success - load "${BASH_IT?}/plugins/available/ruby.plugin.bash" + run load "${BASH_IT?}/plugins/available/ruby.plugin.bash" + assert_success + load "${BASH_IT?}/plugins/available/ruby.plugin.bash" - run type remove_gem - assert_line -n 1 "remove_gem () " + run type remove_gem + assert_line -n 1 "remove_gem () " } @test "plugins ruby: PATH includes ~/.gem/ruby/bin" { - local last_path_entry - if ! type ruby >/dev/null; then - skip 'ruby not installed' - fi + local last_path_entry + if ! type ruby > /dev/null; then + skip 'ruby not installed' + fi - mkdir -p "$(ruby -e 'print Gem.user_dir')/bin" + mkdir -p "$(ruby -e 'print Gem.user_dir')/bin" - run load "${BASH_IT?}/plugins/available/ruby.plugin.bash" - assert_success - load "${BASH_IT?}/plugins/available/ruby.plugin.bash" + run load "${BASH_IT?}/plugins/available/ruby.plugin.bash" + assert_success + load "${BASH_IT?}/plugins/available/ruby.plugin.bash" - last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" - [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] + last_path_entry="$(tail -1 <<< "${PATH//:/$'\n'}")" + [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] } diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index 0d2c629816..8427dd6a1d 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -4,40 +4,40 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "helpers" - load "${BASH_IT?}/plugins/available/xterm.plugin.bash" + setup_libs "helpers" + load "${BASH_IT?}/plugins/available/xterm.plugin.bash" } @test "plugins xterm: shorten command output" { - SHORT_TERM_LINE=true - run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* - assert_success - assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0" + SHORT_TERM_LINE=true + run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* + assert_success + assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0" } @test "plugins xterm: full command output" { - SHORT_TERM_LINE=false - run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* - assert_success - assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)" + SHORT_TERM_LINE=false + run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* + assert_success + assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)" } @test "plugins xterm: shorten dirname output" { - SHORT_TERM_LINE=true - run _short-dirname - assert_success - assert_output "$(basename "${PWD}")" + SHORT_TERM_LINE=true + run _short-dirname + assert_success + assert_output "$(basename "${PWD}")" } @test "plugins xterm: full dirname output" { - SHORT_TERM_LINE=false - run _short-dirname - assert_success - assert_output "${PWD}" + SHORT_TERM_LINE=false + run _short-dirname + assert_success + assert_output "${PWD}" } @test "plugins xterm: set xterm title" { - run set_xterm_title title - assert_success - assert_output $'\033]0;title\007' + run set_xterm_title title + assert_success + assert_output $'\033]0;title\007' } diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index dd2b9288ba..0cf93d6a97 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -3,71 +3,71 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "colors" #"theme" - load "${BASH_IT?}/themes/base.theme.bash" + setup_libs "colors" #"theme" + load "${BASH_IT?}/themes/base.theme.bash" } @test 'themes base: battery_percentage should not exist' { - run type -a battery_percentage &> /dev/null - assert_failure + run type -a battery_percentage &> /dev/null + assert_failure } @test 'themes base: battery_percentage should exist if battery plugin loaded' { - load "${BASH_IT?}/plugins/available/battery.plugin.bash" + load "${BASH_IT?}/plugins/available/battery.plugin.bash" - run type -a battery_percentage &> /dev/null - assert_success + run type -a battery_percentage &> /dev/null + assert_success } @test 'themes base: battery_char should exist' { - run type -t battery_char - assert_success - assert_line "function" + run type -t battery_char + assert_success + assert_line "function" - run battery_char - assert_output "" + run battery_char + assert_output "" } @test 'themes base: battery_char should exist if battery plugin loaded' { - unset -f battery_char + unset -f battery_char - load "${BASH_IT?}/plugins/available/battery.plugin.bash" - run type -t battery_percentage - assert_success - assert_line "function" + load "${BASH_IT?}/plugins/available/battery.plugin.bash" + run type -t battery_percentage + assert_success + assert_line "function" - load "${BASH_IT?}/themes/base.theme.bash" - run type -t battery_char - assert_success - assert_line "function" + load "${BASH_IT?}/themes/base.theme.bash" + run type -t battery_char + assert_success + assert_line "function" - run battery_char - assert_success + run battery_char + assert_success - run type -a battery_char - assert_output --partial 'THEME_BATTERY_PERCENTAGE_CHECK' + run type -a battery_char + assert_output --partial 'THEME_BATTERY_PERCENTAGE_CHECK' } @test 'themes base: battery_charge should exist' { - run type -a battery_charge &> /dev/null - assert_success + run type -a battery_charge &> /dev/null + assert_success - run battery_charge - assert_success - assert_output "" + run battery_charge + assert_success + assert_output "" } @test 'themes base: battery_charge should exist if battery plugin loaded' { - unset -f battery_charge - load "${BASH_IT?}/plugins/available/battery.plugin.bash" - load "${BASH_IT?}/themes/base.theme.bash" + unset -f battery_charge + load "${BASH_IT?}/plugins/available/battery.plugin.bash" + load "${BASH_IT?}/themes/base.theme.bash" - run type -a battery_charge &> /dev/null - assert_success + run type -a battery_charge &> /dev/null + assert_success - run battery_charge - assert_success + run battery_charge + assert_success - run type -a battery_charge - assert_line ' no)' + run type -a battery_charge + assert_line ' no)' } diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index 2d43414d4b..d73e505b95 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -5,383 +5,383 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "colors" #"theme" - load "${BASH_IT?}/themes/base.theme.bash" - load "${BASH_IT?}/themes/githelpers.theme.bash" + setup_libs "colors" #"theme" + load "${BASH_IT?}/themes/base.theme.bash" + load "${BASH_IT?}/themes/githelpers.theme.bash" } add_commit() { - local file_name="general-${RANDOM}" - touch "${file_name}" - echo "" >> "${file_name}" - git add "${file_name}" - git commit -m"message" + local file_name="general-${RANDOM}" + touch "${file_name}" + echo "" >> "${file_name}" + git add "${file_name}" + git commit -m"message" } enter_new_git_repo() { - repo="$(setup_repo)" - pushd "${repo}" || return + repo="$(setup_repo)" + pushd "${repo}" || return } setup_repo() { - upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null || return - git init . > /dev/null + upstream="$(mktemp -d)" + pushd "$upstream" > /dev/null || return + git init . > /dev/null - echo "$upstream" + echo "$upstream" } setup_repo_with_upstream() { - upstream="$(setup_repo)" - pushd "$upstream" > /dev/null || return - add_commit > /dev/null - git checkout -b branch-two - git checkout -b gone-branch - git checkout master - popd > /dev/null || return - - downstream="$(setup_repo)" - pushd "$downstream" > /dev/null || return - add_commit > /dev/null - git remote add my-remote "$upstream" - git fetch my-remote - git branch -u my-remote/master > /dev/null - popd > /dev/null || return - - pushd "$upstream" > /dev/null || return - git branch -d gone-branch > /dev/null - popd > /dev/null || return - - pushd "$downstream" > /dev/null || return - git fetch my-remote - popd > /dev/null || return - - echo "$downstream" + upstream="$(setup_repo)" + pushd "$upstream" > /dev/null || return + add_commit > /dev/null + git checkout -b branch-two + git checkout -b gone-branch + git checkout master + popd > /dev/null || return + + downstream="$(setup_repo)" + pushd "$downstream" > /dev/null || return + add_commit > /dev/null + git remote add my-remote "$upstream" + git fetch my-remote + git branch -u my-remote/master > /dev/null + popd > /dev/null || return + + pushd "$upstream" > /dev/null || return + git branch -d gone-branch > /dev/null + popd > /dev/null || return + + pushd "$downstream" > /dev/null || return + git fetch my-remote + popd > /dev/null || return + + echo "$downstream" } @test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' { - pre='$(_git-friendly-ref)' + pre='$(_git-friendly-ref)' - remote="$(setup_repo)" - pushd "$remote" || return - add_commit - add_commit - popd || return + remote="$(setup_repo)" + pushd "$remote" || return + add_commit + add_commit + popd || return - clone="$(mktemp -d)" - pushd "$clone" || return - git clone "$remote" clone - cd clone + clone="$(mktemp -d)" + pushd "$clone" || return + git clone "$remote" clone + cd clone - SCM_GIT_SHOW_COMMIT_COUNT=true + SCM_GIT_SHOW_COMMIT_COUNT=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}" - add_commit + add_commit - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ↑1" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ↑1" - add_commit + add_commit - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ↑2" - popd || return + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ↑2" + popd || return - pushd "$remote" || return - add_commit - add_commit - add_commit - popd || return + pushd "$remote" || return + add_commit + add_commit + add_commit + popd || return - pushd "$clone/clone" || return - git fetch + pushd "$clone/clone" || return + git fetch - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ↑2 ↓3" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ↑2 ↓3" - git reset HEAD~2 --hard + git reset HEAD~2 --hard - SCM_GIT_BEHIND_CHAR="↓" - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ↓3" + SCM_GIT_BEHIND_CHAR="↓" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ↓3" } @test 'themes base: Git: when stashes exist: it shows the number of stashes' { - pre='$(_git-friendly-ref)' + pre='$(_git-friendly-ref)' - enter_new_git_repo - add_commit + enter_new_git_repo + add_commit - touch file - git add file - git stash + touch file + git add file + git stash - SCM_GIT_SHOW_STASH_INFO=true + SCM_GIT_SHOW_STASH_INFO=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} {1}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} {1}" - touch file2 - git add file2 - git stash + touch file2 + git add file2 + git stash - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} {2}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} {2}" } @test 'themes base: Git: remote info: when there is no upstream remote: is empty' { - pre='$(_git-friendly-ref)' - post=" ↑1 ↓1" + pre='$(_git-friendly-ref)' + post=" ↑1 ↓1" - enter_new_git_repo - add_commit + enter_new_git_repo + add_commit - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' { - pre='$(_git-friendly-ref) → ' - eval_pre="master → " - post=" ↑1 ↓1" + pre='$(_git-friendly-ref) → ' + eval_pre="master → " + post=" ↑1 ↓1" - repo="$(setup_repo_with_upstream)" - pushd "${repo}" || return + repo="$(setup_repo_with_upstream)" + pushd "${repo}" || return - SCM_GIT_SHOW_REMOTE_INFO=true - SCM_GIT_SHOW_COMMIT_COUNT=true + SCM_GIT_SHOW_REMOTE_INFO=true + SCM_GIT_SHOW_COMMIT_COUNT=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" - git branch -u my-remote/branch-two + git branch -u my-remote/branch-two - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is auto: includes the remote when more than one remote' { - pre='$(_git-friendly-ref)' - eval_pre="master" - post=" ↑1 ↓1" + pre='$(_git-friendly-ref)' + eval_pre="master" + post=" ↑1 ↓1" - repo="$(setup_repo_with_upstream)" - pushd "${repo}" || return + repo="$(setup_repo_with_upstream)" + pushd "${repo}" || return - SCM_GIT_SHOW_REMOTE_INFO=auto - SCM_GIT_SHOW_COMMIT_COUNT=true + SCM_GIT_SHOW_REMOTE_INFO=auto + SCM_GIT_SHOW_COMMIT_COUNT=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}${post}" - pre="${pre} → " - eval_pre="${eval_pre} → " - git branch -u my-remote/branch-two + pre="${pre} → " + eval_pre="${eval_pre} → " + git branch -u my-remote/branch-two - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" - git remote add second-remote "$(mktemp -d)" - git branch -u my-remote/master + git remote add second-remote "$(mktemp -d)" + git branch -u my-remote/master - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" - git branch -u my-remote/branch-two + git branch -u my-remote/branch-two - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is false: never include the remote' { - pre='$(_git-friendly-ref)' - eval_pre="master" - post=" ↑1 ↓1" + pre='$(_git-friendly-ref)' + eval_pre="master" + post=" ↑1 ↓1" - repo="$(setup_repo_with_upstream)" - pushd "${repo}" || return - git remote add second-remote "$(mktemp -d)" - git remote add third-remote "$(mktemp -d)" + repo="$(setup_repo_with_upstream)" + pushd "${repo}" || return + git remote add second-remote "$(mktemp -d)" + git remote add third-remote "$(mktemp -d)" - SCM_GIT_SHOW_REMOTE_INFO=false - SCM_GIT_SHOW_COMMIT_COUNT=true + SCM_GIT_SHOW_REMOTE_INFO=false + SCM_GIT_SHOW_COMMIT_COUNT=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}${post}" - pre="${pre} → " - eval_pre="${eval_pre} → " - git branch -u my-remote/branch-two + pre="${pre} → " + eval_pre="${eval_pre} → " + git branch -u my-remote/branch-two - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" } @test 'themes base: Git: remote info: when showing remote info: show if upstream branch is gone' { - pre='$(_git-friendly-ref)' - post=" ↑1 ↓1" + pre='$(_git-friendly-ref)' + post=" ↑1 ↓1" - repo="$(setup_repo_with_upstream)" - pushd "${repo}" || return + repo="$(setup_repo_with_upstream)" + pushd "${repo}" || return - SCM_GIT_SHOW_REMOTE_INFO=true - SCM_GIT_SHOW_COMMIT_COUNT=true + SCM_GIT_SHOW_REMOTE_INFO=true + SCM_GIT_SHOW_COMMIT_COUNT=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} → my-remote${post}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} → my-remote${post}" - git checkout gone-branch - git fetch --prune --all + git checkout gone-branch + git fetch --prune --all - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ⇢ my-remote" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ⇢ my-remote" } @test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' { - enter_new_git_repo + enter_new_git_repo - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" - git checkout -b second-branch + git checkout -b second-branch - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when a branch is not checked out: shows that branch' { - enter_new_git_repo + enter_new_git_repo - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" - git checkout -b second-branch + git checkout -b second-branch - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and tag: show a tag' { - enter_new_git_repo - add_commit - git tag first-tag - git checkout -b second-branch - add_commit - git checkout HEAD~1 - - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "tag:first-tag" + enter_new_git_repo + add_commit + git tag first-tag + git checkout -b second-branch + add_commit + git checkout HEAD~1 + + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "tag:first-tag" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and no tag: show a branch' { - enter_new_git_repo - add_commit - git checkout -b second-branch - add_commit - git checkout HEAD~1 - - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master" + enter_new_git_repo + add_commit + git checkout -b second-branch + add_commit + git checkout HEAD~1 + + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is parent to a named ref: show relative name' { - enter_new_git_repo - add_commit - add_commit - git checkout HEAD~1 + enter_new_git_repo + add_commit + add_commit + git checkout HEAD~1 - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master~1" + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master~1" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is not parent to a named ref: show short sha' { - enter_new_git_repo - add_commit - add_commit - sha="$(git rev-parse --short HEAD)" - git reset --hard HEAD~1 - git checkout "$sha" - - git_prompt_vars - assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:$sha" + enter_new_git_repo + add_commit + add_commit + sha="$(git rev-parse --short HEAD)" + git reset --hard HEAD~1 + git checkout "$sha" + + git_prompt_vars + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:$sha" } @test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' { - pre='$(_git-friendly-ref)' + pre='$(_git-friendly-ref)' - enter_new_git_repo - echo "line1" > file1 - echo "line1" > file2 - echo "line1" > file3 - echo "line1" > file4 - git add . - git commit -m"commit1" + enter_new_git_repo + echo "line1" > file1 + echo "line1" > file2 + echo "line1" > file3 + echo "line1" > file4 + git add . + git commit -m"commit1" - git_prompt_vars - assert_equal "${SCM_STATE?}" " ✓" + git_prompt_vars + assert_equal "${SCM_STATE?}" " ✓" - echo "line2" >> file1 - git add file1 + echo "line2" >> file1 + git add file1 - SCM_GIT_SHOW_DETAILS=true + SCM_GIT_SHOW_DETAILS=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} S:1" - assert_equal "${SCM_STATE?}" " ✗" - assert_equal "${SCM_DIRTY?}" "3" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} S:1" + assert_equal "${SCM_STATE?}" " ✗" + assert_equal "${SCM_DIRTY?}" "3" - echo "line2" >> file2 - echo "line2" >> file3 - echo "line2" >> file4 + echo "line2" >> file2 + echo "line2" >> file3 + echo "line2" >> file4 - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3" - assert_equal "${SCM_DIRTY?}" "2" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3" + assert_equal "${SCM_DIRTY?}" "2" - echo "line1" > newfile5 - echo "line1" > newfile6 + echo "line1" > newfile5 + echo "line1" > newfile6 - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3 ?:2" - assert_equal "${SCM_DIRTY?}" "1" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3 ?:2" + assert_equal "${SCM_DIRTY?}" "1" - git config bash-it.hide-status 1 + git config bash-it.hide-status 1 - SCM_DIRTY='nope' - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}" - assert_equal "${SCM_DIRTY?}" "nope" + SCM_DIRTY='nope' + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}" + assert_equal "${SCM_DIRTY?}" "nope" } @test 'themes base: Git: git user info: shows user initials' { - pre='$(_git-friendly-ref)' + pre='$(_git-friendly-ref)' - enter_new_git_repo - git config user.name "Cool User" + enter_new_git_repo + git config user.name "Cool User" - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre}" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre}" - SCM_GIT_SHOW_CURRENT_USER=true + SCM_GIT_SHOW_CURRENT_USER=true - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ cu" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ cu" - git config user.name "Çool Üser" + git config user.name "Çool Üser" - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ çü" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ çü" - # show initials set by `git pair` + # show initials set by `git pair` - git config user.initials "ab cd" + git config user.initials "ab cd" - git_prompt_vars - assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ ab+cd" + git_prompt_vars + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ ab+cd" } diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index e2fc10135d..4a7c1ffd1a 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -3,114 +3,114 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { - setup_libs "colors" #"theme" - load "${BASH_IT?}/themes/base.theme.bash" + setup_libs "colors" #"theme" + load "${BASH_IT?}/themes/base.theme.bash" } function setup_repo { - upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null || return - # Create a dummy SVN folder - this will not work with an actual `svn` command, - # but will be enough to trigger the SVN check in the base theme. - mkdir .svn + upstream="$(mktemp -d)" + pushd "$upstream" > /dev/null || return + # Create a dummy SVN folder - this will not work with an actual `svn` command, + # but will be enough to trigger the SVN check in the base theme. + mkdir .svn - echo "$upstream" + echo "$upstream" } function setup_svn_path { - local svn_path="$1" + local svn_path="$1" - # Make sure that the requested SVN script is available - assert_file_exist "$svn_path/svn" + # Make sure that the requested SVN script is available + assert_file_exist "$svn_path/svn" - # Make sure that the requested SVN script is on the path - export PATH="$svn_path:$PATH" + # Make sure that the requested SVN script is on the path + export PATH="$svn_path:$PATH" } @test 'themes base: SVN: detect SVN repo' { - repo="$(setup_repo)" - pushd "$repo" || return + repo="$(setup_repo)" + pushd "$repo" || return - setup_svn_path "$BASH_IT/test/fixtures/svn/working" + setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Init the base theme again so that the working SVN script is detected - run _bash_it_appearance_scm_init - assert_success - _bash_it_appearance_scm_init + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success + _bash_it_appearance_scm_init - scm - # Make sure that the SVN command is used - assert_equal "${SCM?}" "${SCM_SVN?}" + scm + # Make sure that the SVN command is used + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: detect SVN repo even from a subfolder' { - repo="$(setup_repo)" - pushd "$repo" || return + repo="$(setup_repo)" + pushd "$repo" || return - mkdir foo - pushd foo || return + mkdir foo + pushd foo || return - setup_svn_path "$BASH_IT/test/fixtures/svn/working" + setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Init the base theme again so that the working SVN script is detected - run _bash_it_appearance_scm_init - assert_success - _bash_it_appearance_scm_init + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success + _bash_it_appearance_scm_init - scm - # Make sure that the SVN command is used - assert_equal "${SCM?}" "${SCM_SVN?}" + scm + # Make sure that the SVN command is used + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: no SCM if no .svn folder can be found' { - repo="$(setup_repo)" - pushd "$repo" || return + repo="$(setup_repo)" + pushd "$repo" || return - rm -rf .svn + rm -rf .svn - setup_svn_path "$BASH_IT/test/fixtures/svn/working" + setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # Init the base theme again so that the working SVN script is detected - run _bash_it_appearance_scm_init - assert_success - _bash_it_appearance_scm_init + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success + _bash_it_appearance_scm_init - scm - # Make sure that no SVN command is used - assert_equal "${SCM?}" "${SCM_NONE?}" + scm + # Make sure that no SVN command is used + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo when using broken SVN command' { - repo="$(setup_repo)" - pushd "$repo" || return + repo="$(setup_repo)" + pushd "$repo" || return - setup_svn_path "$BASH_IT/test/fixtures/svn/broken" + setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the working SVN script is detected - run _bash_it_appearance_scm_init - assert_success - _bash_it_appearance_scm_init + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success + _bash_it_appearance_scm_init - scm - # Make sure that no SVN command is not used - assert_equal "${SCM?}" "${SCM_NONE?}" + scm + # Make sure that no SVN command is not used + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' { - repo="$(setup_repo)" - pushd "$repo" || return + repo="$(setup_repo)" + pushd "$repo" || return - mkdir foo - pushd foo || return + mkdir foo + pushd foo || return - setup_svn_path "$BASH_IT/test/fixtures/svn/broken" + setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the working SVN script is detected - run _bash_it_appearance_scm_init - assert_success - _bash_it_appearance_scm_init + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success + _bash_it_appearance_scm_init - scm - # Make sure that no SVN command is used - assert_equal "${SCM?}" "${SCM_NONE?}" + scm + # Make sure that no SVN command is used + assert_equal "${SCM?}" "${SCM_NONE?}" } From 5524e82ad5cdab8e02316ab9b329e4caef103a2d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 00:04:42 -0800 Subject: [PATCH 12/13] BATS: unofficial strict mode --- test/test_helper.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_helper.bash b/test/test_helper.bash index 9728801681..2b4aa894ec 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -101,6 +101,7 @@ function setup() { BASH_IT_CONFIG="${BASH_IT?}" #"${BATS_TEST_TMPDIR//\/\///}" export XDG_CACHE_HOME="${BATS_TEST_TMPDIR?}" + set -Eeuo pipefail # Bash Unofficial Strict Mode setup_test_fixture local_setup } @@ -109,6 +110,7 @@ function teardown() { unset GIT_CONFIG_NOSYSTEM local_teardown clean_test_fixture + set +Eeuo pipefail # Bash Unofficial Strict Mode } function teardown_file() { From 683b9f3d99039dc9eb07e725fa030582aec61c98 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 14 Feb 2022 20:29:26 -0800 Subject: [PATCH 13/13] workaround --- test/bash_it/bash_it.bats | 4 ++++ test/completion/bash-it.completion.bats | 1 + test/lib/helpers.bats | 1 + test/lib/preexec.bats | 1 + test/lib/utilities.bats | 2 ++ 5 files changed, 9 insertions(+) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index e43ab988cd..0a49c59b87 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -8,6 +8,10 @@ function local_setup_file() { # don't load any libraries as the tests here test the *whole* kit } +function local_setup() { + : "${PROMPT_COMMAND:=}" "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:=}" +} + @test "bash-it: verify that the test fixture is available" { assert_file_exist "${BASH_IT?}/aliases/available/a.aliases.bash" assert_file_exist "${BASH_IT?}/aliases/available/b.aliases.bash" diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 8ee9ef0722..dd910f2a97 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -36,6 +36,7 @@ function __check_completion() { # Word index of the last word COMP_CWORD=$((${#COMP_WORDS[@]} - 1)) + COMP_WORDS+=('') # arg # Run the Bash-it completion function _bash-it diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 5806ac552d..5ec6713dd9 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -7,6 +7,7 @@ function local_setup_file() { } function local_setup() { + : "${BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE:=}" # Copy the test fixture to the Bash-it folder cp -RP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" } diff --git a/test/lib/preexec.bats b/test/lib/preexec.bats index 3c5ed4b041..c1bdcfec67 100644 --- a/test/lib/preexec.bats +++ b/test/lib/preexec.bats @@ -6,6 +6,7 @@ load ../test_helper function local_setup { setup_test_fixture export __bp_enable_subshells=yas + export HISTCONTROL="" } @test "vendor preexec: __bp_install_after_session_init() without existing" { diff --git a/test/lib/utilities.bats b/test/lib/utilities.bats index 7d8284e6a4..c60365f36e 100644 --- a/test/lib/utilities.bats +++ b/test/lib/utilities.bats @@ -4,6 +4,8 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { setup_libs "helpers" + # shellcheck disable=SC2034 + BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE="" } @test "_bash-it-component-item-is-enabled() - for a disabled item" {