From b2279b72375e1948279fb7c6c52637723eb89d43 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 19 Oct 2021 11:09:28 -0400 Subject: [PATCH 01/10] tests: quote paths --- test/plugins/xterm.plugin.bats | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index 123a91f0..9c86e5c7 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -1,6 +1,7 @@ #!/usr/bin/env bats load ../test_helper +load ../../lib/log load ../../lib/helpers load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" @@ -21,30 +22,30 @@ function local_setup { @test "plugins xterm: shorten command output" { export SHORT_TERM_LINE=true - run _short-command ${BASH_IT}/test/fixtures/plugin/xterm/files/* + run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success - assert_output ${BASH_IT}/test/fixtures/plugin/xterm/files/arg0 + assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0" } @test "plugins xterm: full command output" { export SHORT_TERM_LINE=false - run _short-command ${BASH_IT}/test/fixtures/plugin/xterm/files/* + run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success - assert_output "$(echo ${BASH_IT}/test/fixtures/plugin/xterm/files/*)" + assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)" } @test "plugins xterm: shorten dirname output" { export SHORT_TERM_LINE=true run _short-dirname assert_success - assert_output "$(basename $PWD)" + assert_output "$(basename "${PWD}")" } @test "plugins xterm: full dirname output" { export SHORT_TERM_LINE=false run _short-dirname assert_success - assert_output $PWD + assert_output "${PWD}" } @test "plugins xterm: set xterm title" { From 9dcbeec7ad2b512c3bec0df5341b4eb4378b21a1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 19 Oct 2021 11:28:48 -0400 Subject: [PATCH 02/10] tests: test_helper already loads `composure.sh` ...and `cite()`s metadata --- test/bash_it/bash_it.bats | 1 - test/completion/bash-it.completion.bats | 1 - test/install/install.bats | 1 - test/install/uninstall.bats | 1 - test/lib/composure.bats | 1 - test/lib/helpers.bats | 3 --- test/lib/log.bats | 4 +--- test/lib/search.bats | 3 --- test/lib/utilities.bats | 4 +--- test/plugins/alias-completion.plugin.bats | 3 --- test/plugins/base.plugin.bats | 1 - test/plugins/battery.plugin.bats | 3 --- test/plugins/cmd-returned-notify.plugin.bats | 2 +- test/plugins/go.plugin.bats | 1 - test/plugins/ruby.plugin.bats | 6 ++---- test/plugins/xterm.plugin.bats | 1 - test/themes/base.theme.bats | 3 --- test/themes/base.theme.git.bats | 3 --- test/themes/base.theme.svn.bats | 3 --- 19 files changed, 5 insertions(+), 40 deletions(-) mode change 100755 => 100644 test/lib/composure.bats mode change 100755 => 100644 test/plugins/base.plugin.bats mode change 100755 => 100644 test/plugins/battery.plugin.bats mode change 100755 => 100644 test/plugins/ruby.plugin.bats diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index a692909e..13c84238 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -1,7 +1,6 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" function local_setup { setup_test_fixture diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index fbf0a3fa..cb1761bf 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -1,7 +1,6 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../completion/available/bash-it.completion function local_setup { diff --git a/test/install/install.bats b/test/install/install.bats index 40f3162d..4a88e23f 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -1,7 +1,6 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" # Determine which config file to use based on OS. case $OSTYPE in diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index 038125b3..16bb7f7b 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -1,7 +1,6 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" # Determine which config file to use based on OS. case $OSTYPE in diff --git a/test/lib/composure.bats b/test/lib/composure.bats old mode 100755 new mode 100644 index 02da83eb..8198936c --- a/test/lib/composure.bats +++ b/test/lib/composure.bats @@ -1,7 +1,6 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" @test "lib composure: _composure_keywords()" { run _composure_keywords diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index d876d882..ea7bc68e 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -1,13 +1,10 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log load ../../lib/utilities load ../../lib/search -cite _about _param _example _group _author _version - load ../../lib/helpers load ../../plugins/available/base.plugin diff --git a/test/lib/log.bats b/test/lib/log.bats index 329386bd..00efbc2d 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -1,10 +1,8 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" -load ../../lib/appearance +load ../../themes/colors.theme -cite _about _param _example _group _author _version load ../../lib/log load ../../lib/helpers load ../../plugins/available/base.plugin diff --git a/test/lib/search.bats b/test/lib/search.bats index 2081abab..6a54a62d 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -1,14 +1,11 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log load ../../lib/helpers load ../../lib/utilities load ../../lib/search -cite _about _param _example _group _author _version - load ../../plugins/available/base.plugin load ../../aliases/available/git.aliases load ../../plugins/available/ruby.plugin diff --git a/test/lib/utilities.bats b/test/lib/utilities.bats index 4907a763..9554a2db 100644 --- a/test/lib/utilities.bats +++ b/test/lib/utilities.bats @@ -1,13 +1,11 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +load ../../lib/log load ../../lib/helpers load ../../lib/utilities load ../../lib/search -cite _about _param _example _group _author _version - function local_setup { setup_test_fixture } diff --git a/test/plugins/alias-completion.plugin.bats b/test/plugins/alias-completion.plugin.bats index 497dded9..b0ad2659 100644 --- a/test/plugins/alias-completion.plugin.bats +++ b/test/plugins/alias-completion.plugin.bats @@ -1,12 +1,9 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log load ../../lib/helpers -cite _about _param _example _group _author _version - load ../../completion/available/capistrano.completion @test "alias-completion: See that aliases with double quotes and brackets do not break the plugin" { diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats old mode 100755 new mode 100644 index 6f1099cc..2f1cd327 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -1,7 +1,6 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log load ../../lib/helpers load ../../plugins/available/base.plugin diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats old mode 100755 new mode 100644 index fda52b02..b7ea5e8a --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -1,12 +1,9 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load "${BASH_IT}/lib/log.bash" load "${BASH_IT}/lib/helpers.bash" -cite _about _param _example _group _author _version - load ../../plugins/available/battery.plugin # Sets up the `_command_exists` function so that it only responds `true` if called with diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index f201e465..8e14f565 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -2,7 +2,7 @@ load ../test_helper load ../../lib/helpers -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" +load ../../vendor/init.d/preexec load ../../plugins/available/cmd-returned-notify.plugin diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index 110699e8..f421bbf7 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -2,7 +2,6 @@ load ../test_helper load ../../lib/helpers -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" # We test `go version` in each test to account for users with goenv and no system go. diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats old mode 100755 new mode 100644 index 7a719020..6a3d7893 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -2,14 +2,14 @@ load ../test_helper load ../../lib/helpers -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" -load ../../plugins/available/ruby.plugin function local_setup { setup_test_fixture export OLD_PATH="$PATH" export PATH="/usr/bin:/bin:/usr/sbin" + + load ../../plugins/available/ruby.plugin } function local_teardown { @@ -27,8 +27,6 @@ function local_teardown { skip 'ruby not installed' fi - load ../../plugins/available/ruby.plugin - local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1) [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] } diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index 9c86e5c7..0a4eb859 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -3,7 +3,6 @@ load ../test_helper load ../../lib/log load ../../lib/helpers -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../plugins/available/xterm.plugin diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index dc8213d3..a7067b83 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -1,11 +1,8 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log -cite _about _param _example _group _author _version - load ../../lib/helpers load ../../themes/base.theme diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index f2c4b9c2..bc354867 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -1,11 +1,8 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log -cite _about _param _example _group _author _version - load ../../lib/helpers load ../../themes/githelpers.theme load ../../themes/base.theme diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index d1c2c311..e8b4cb13 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -1,11 +1,8 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" load ../../lib/log -cite _about _param _example _group _author _version - load ../../lib/helpers function local_setup { From da6b27166f44e3ba2566a668d81d2a99d80c3845 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 21 Oct 2021 02:52:26 -0400 Subject: [PATCH 03/10] tests: new file `test_helper_libs.bash` For testing non-core files, just `load ../test_helper_libs` after `load ../test_helper` instead of trying to guess which libs must be loaded, in which order, for testing to succeed. `_command_exists` spews log messages, so our test log is littered with `_log_debug not found`. This fixes that too. --- clean_files.txt | 1 + test/lib/helpers.bats | 6 +----- test/lib/search.bats | 5 +---- test/lib/utilities.bats | 5 +---- test/plugins/alias-completion.plugin.bats | 3 +-- test/plugins/base.plugin.bats | 3 +-- test/plugins/battery.plugin.bats | 3 +-- test/plugins/cmd-returned-notify.plugin.bats | 2 +- test/plugins/go.plugin.bats | 2 +- test/plugins/ruby.plugin.bats | 2 +- test/plugins/xterm.plugin.bats | 3 +-- test/test_helper_libs.bash | 6 ++++++ test/themes/base.theme.bats | 4 +--- test/themes/base.theme.git.bats | 4 +--- test/themes/base.theme.svn.bats | 4 +--- 15 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 test/test_helper_libs.bash diff --git a/clean_files.txt b/clean_files.txt index 4ecda787..242d7327 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -123,6 +123,7 @@ plugins/available/zoxide.plugin.bash # test/plugins/alias-completion.plugin.bats test/test_helper.bash +test/test_helper_libs.bash # themes # diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index ea7bc68e..4df36277 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -1,11 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log -load ../../lib/utilities -load ../../lib/search - -load ../../lib/helpers +load ../test_helper_libs load ../../plugins/available/base.plugin function local_setup { diff --git a/test/lib/search.bats b/test/lib/search.bats index 6a54a62d..c8a95027 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -1,10 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log -load ../../lib/helpers -load ../../lib/utilities -load ../../lib/search +load ../test_helper_libs load ../../plugins/available/base.plugin load ../../aliases/available/git.aliases diff --git a/test/lib/utilities.bats b/test/lib/utilities.bats index 9554a2db..67e6a640 100644 --- a/test/lib/utilities.bats +++ b/test/lib/utilities.bats @@ -1,10 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log -load ../../lib/helpers -load ../../lib/utilities -load ../../lib/search +load ../test_helper_libs function local_setup { setup_test_fixture diff --git a/test/plugins/alias-completion.plugin.bats b/test/plugins/alias-completion.plugin.bats index b0ad2659..20d13cf2 100644 --- a/test/plugins/alias-completion.plugin.bats +++ b/test/plugins/alias-completion.plugin.bats @@ -1,8 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log -load ../../lib/helpers +load ../test_helper_libs load ../../completion/available/capistrano.completion diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 2f1cd327..05081a8a 100644 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -1,8 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log -load ../../lib/helpers +load ../test_helper_libs load ../../plugins/available/base.plugin @test 'plugins base: ips()' { diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index b7ea5e8a..eac6d021 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -1,8 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load "${BASH_IT}/lib/log.bash" -load "${BASH_IT}/lib/helpers.bash" +load ../test_helper_libs load ../../plugins/available/battery.plugin diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index 8e14f565..daf58330 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/helpers +load ../test_helper_libs load ../../vendor/init.d/preexec load ../../plugins/available/cmd-returned-notify.plugin diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index f421bbf7..4021e643 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/helpers +load ../test_helper_libs # We test `go version` in each test to account for users with goenv and no system go. diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 6a3d7893..dc8a3e85 100644 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/helpers +load ../test_helper_libs function local_setup { setup_test_fixture diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index 0a4eb859..c175d854 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -1,8 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log -load ../../lib/helpers +load ../test_helper_libs load ../../plugins/available/xterm.plugin diff --git a/test/test_helper_libs.bash b/test/test_helper_libs.bash new file mode 100644 index 00000000..57115e7e --- /dev/null +++ b/test/test_helper_libs.bash @@ -0,0 +1,6 @@ +# shellcheck shell=bash + +load "${BASH_IT}/lib/log.bash" +load "${BASH_IT}/lib/utilities.bash" +load "${BASH_IT}/lib/helpers.bash" +load "${BASH_IT}/lib/search.bash" diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index a7067b83..1730f7ad 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -1,9 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log - -load ../../lib/helpers +load ../test_helper_libs load ../../themes/base.theme @test 'themes base: battery_percentage should not exist' { diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index bc354867..ad2c5a8d 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -1,9 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log - -load ../../lib/helpers +load ../test_helper_libs load ../../themes/githelpers.theme load ../../themes/base.theme diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index e8b4cb13..789d85e5 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -1,9 +1,7 @@ #!/usr/bin/env bats load ../test_helper -load ../../lib/log - -load ../../lib/helpers +load ../test_helper_libs function local_setup { setup_test_fixture From 6030767b4e43fc1d8b7679d0bf0c9b38b03b38e2 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 19 Oct 2021 11:45:51 -0400 Subject: [PATCH 04/10] test/theme: load colors --- test/themes/base.theme.bats | 1 + 1 file changed, 1 insertion(+) diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 1730f7ad..2e15e865 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -2,6 +2,7 @@ load ../test_helper load ../test_helper_libs +load ../../themes/colors.theme load ../../themes/base.theme @test 'themes base: battery_percentage should not exist' { From 21a2198a12bc428c73767a81063330d9dc8767e1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 19 Oct 2021 12:07:12 -0400 Subject: [PATCH 05/10] test/theme: make fewer assumptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Literally copying a line from the source to be tested is perhaps not the best way to test that code. 😉 That said, we do want to verify that the function was actually loaded. TODO: actually test the function. --- test/themes/base.theme.bats | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 2e15e865..50098c1d 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -18,30 +18,32 @@ load ../../themes/base.theme } @test 'themes base: battery_char should exist' { - run type -a battery_char &> /dev/null + run type -t battery_char assert_success + assert_line "function" run battery_char - assert_success assert_line -n 0 "" - - run type -a battery_char - assert_line " echo -n" } @test 'themes base: battery_char should exist if battery plugin loaded' { unset -f battery_char - load ../../plugins/available/battery.plugin - load ../../themes/base.theme - run type -a battery_char &> /dev/null + load ../../plugins/available/battery.plugin + run type -t battery_percentage assert_success + assert_line "function" + + load ../../themes/base.theme + run type -t battery_char + assert_success + assert_line "function" run battery_char assert_success run type -a battery_char - assert_line ' if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then' + assert_output --partial 'THEME_BATTERY_PERCENTAGE_CHECK' } @test 'themes base: battery_charge should exist' { From c35ed44cbf8b45da1257a2071400bcc3a3208e87 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 8 Sep 2021 17:03:36 -0700 Subject: [PATCH 06/10] plugins/ruby: tests on Mac OS X Test was failing only on Mac OS X for some reason, so refactor a little. It turned out to be due to explicitly setting `$HOME` *after* loading the plugin. --- test/plugins/ruby.plugin.bats | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) mode change 100644 => 100755 test/plugins/ruby.plugin.bats diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats old mode 100644 new mode 100755 index dc8a3e85..e40dfeae --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -8,8 +8,6 @@ function local_setup { export OLD_PATH="$PATH" export PATH="/usr/bin:/bin:/usr/sbin" - - load ../../plugins/available/ruby.plugin } function local_teardown { @@ -18,15 +16,21 @@ function local_teardown { } @test "plugins ruby: remove_gem is defined" { + load ../../plugins/available/ruby.plugin + run type remove_gem assert_line -n 1 "remove_gem () " } @test "plugins ruby: PATH includes ~/.gem/ruby/bin" { - if ! which ruby >/dev/null; then + if ! type ruby >/dev/null; then skip 'ruby not installed' fi - local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1) - [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] + mkdir -p "$(ruby -e 'print Gem.user_dir')/bin" + + load ../../plugins/available/ruby.plugin + + local last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" + [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] } From 61e1d6aec26d69f1c9ca891f6c40ddadd17f8f42 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 21 Oct 2021 02:31:11 -0400 Subject: [PATCH 07/10] lib/utilities: simplify test flow This subshell is...wut --- test/lib/utilities.bats | 64 +++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/test/lib/utilities.bats b/test/lib/utilities.bats index 67e6a640..a0968fce 100644 --- a/test/lib/utilities.bats +++ b/test/lib/utilities.bats @@ -7,82 +7,78 @@ function local_setup { setup_test_fixture } -function has_match() { - $(_bash-it-array-contains-element ${@}) && echo "has" "$1" -} - -function item_enabled() { - $(_bash-it-component-item-is-enabled ${@}) && echo "$1" "$2" "is enabled" -} - -function item_disabled() { - $(_bash-it-component-item-is-disabled ${@}) && echo "$1" "$2" "is disabled" -} - @test "_bash-it-component-item-is-enabled() - for a disabled item" { - run item_enabled aliases svn - assert_line -n 0 '' + 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 item_enabled alias svn - assert_line -n 0 'alias svn is enabled' + 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 item_enabled alias svn - assert_line -n 0 '' + 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 item_disabled alias svn - assert_line -n 0 'alias svn is disabled' + 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 item_disabled alias svn - assert_line -n 0 '' + 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 item_disabled alias svn - assert_line -n 0 'alias svn is disabled' + 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 has_match apple "${fruits[@]}" - assert_line -n 0 'has apple' + 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 has_match mandarin "${fruits[@]}" - assert_line -n 0 'has 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 has_match pear "${fruits[@]}" - assert_line -n 0 'has pear' + 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 has_match "yellow watermelon" "${fruits[@]}" - assert_line -n 0 'has 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 has_match xyz "${fruits[@]}" - assert_line -n 0 '' + run _bash-it-array-contains-element xyz "${fruits[@]}" + assert_failure } From 97ef5a8087b88dd6e772dda749d88e44a5d51736 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 6 Jan 2022 20:09:40 -0800 Subject: [PATCH 08/10] test/run: lint --- clean_files.txt | 1 + test/run | 57 +++++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 242d7327..ad9a364a 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -122,6 +122,7 @@ plugins/available/zoxide.plugin.bash # tests # test/plugins/alias-completion.plugin.bats +test/run test/test_helper.bash test/test_helper_libs.bash diff --git a/test/run b/test/run index 7999d4fb..14d83950 100755 --- a/test/run +++ b/test/run @@ -4,16 +4,15 @@ bats_executable="${test_directory}/../test_lib/bats-core/bin/bats" git submodule init && git submodule update -if [ -z "${BASH_IT}" ]; then - declare BASH_IT - BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" - export BASH_IT +if [[ -z "${BASH_IT}" ]]; then + BASH_IT="$(cd "${test_directory}" && dirname "${PWD}")" + export BASH_IT fi -if [ -z "$1" ]; then - test_dirs=( "${test_directory}"/{bash_it,completion,install,lib,plugins,themes} ) +if [[ -z "$1" ]]; then + test_dirs=("${test_directory}"/{bash_it,completion,install,lib,plugins,themes}) else - test_dirs=( "$1" ) + test_dirs=("$1") fi # Make sure that the `parallel` command is installed, @@ -21,28 +20,26 @@ fi # If that is the case, try to guess the number of CPU cores, # so we can run `bats` in parallel processing mode, which is a lot faster. if command -v parallel &> /dev/null \ - && parallel -V &> /dev/null \ - && { parallel -V 2> /dev/null | grep -q '^GNU\>'; } -then - # Expect to run at least on a dual-core CPU; slightly degraded performance - # shouldn't matter otherwise. - declare -i -r test_jobs_default=2 - declare -i -r test_jobs_effective="$( - if [ "${TEST_JOBS:-detect}" = "detect" ] \ - && command -v nproc &> /dev/null - then - nproc - elif [ -n "${TEST_JOBS}" ] \ - && [ "${TEST_JOBS}" != "detect" ] - then - echo "${TEST_JOBS}" - else - echo ${test_jobs_default} - fi - )" - exec "$bats_executable" ${CI:+--tap} --jobs ${test_jobs_effective} \ - "${test_dirs[@]}" + && parallel -V &> /dev/null \ + && { parallel -V 2> /dev/null | grep -q '^GNU\>'; }; then + # Expect to run at least on a dual-core CPU; slightly degraded performance + # shouldn't matter otherwise. + declare -i -r test_jobs_default=2 + # shellcheck disable=SC2155 + declare -i -r test_jobs_effective="$( + if [[ "${TEST_JOBS:-detect}" = "detect" ]] \ + && command -v nproc &> /dev/null; then + nproc + elif [[ -n "${TEST_JOBS}" ]] \ + && [[ "${TEST_JOBS}" != "detect" ]]; then + echo "${TEST_JOBS}" + else + echo "${test_jobs_default}" + fi + )" + exec "$bats_executable" "${CI:+--tap}" --jobs "${test_jobs_effective}" \ + "${test_dirs[@]}" else - # Run `bats` in single-threaded mode. - exec "$bats_executable" ${CI:+--tap} "${test_dirs[@]}" + # Run `bats` in single-threaded mode. + exec "$bats_executable" ${CI:+--tap} "${test_dirs[@]}" fi From 30ca1bfba2b48927f6874817c27d78ef12a862d0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 6 Jan 2022 20:14:33 -0800 Subject: [PATCH 09/10] test/test_helper: exclude bad symlink Symlink `/test_lib/bats-core/test/fixtures/parallel/suite/helper.bash` references a not-existing file, but it's in a submodule so I can't just fix it. Exclude it from `rsync` in `setup_test_fixture()`. --- 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 8d92e89c..9dda3b36 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -41,7 +41,7 @@ setup_test_fixture() { if command -v rsync &> /dev/null; then # Use rsync to copy Bash-it to the temp folder - rsync -qavrKL -d --delete-excluded --exclude=.git --exclude=enabled "$src_topdir" "$BASH_IT" + rsync -qavrKL -d --delete-excluded --exclude=.git --exclude=helper.bash --exclude=enabled "$src_topdir" "$BASH_IT" else rm -rf "$BASH_IT" mkdir -p "$BASH_IT" From 8a226a73f1b0ddffaf3f8d24ba282a7794678129 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 7 Jan 2022 16:43:34 -0800 Subject: [PATCH 10/10] test/test-helper: support 'plumbing' metadata --- test/test_helper.bash | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 test/test_helper.bash diff --git a/test/test_helper.bash b/test/test_helper.bash old mode 100644 new mode 100755 index 9dda3b36..06660979 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -21,6 +21,7 @@ load "${TEST_DEPS_DIR}/bats-file/load.bash" # support 'plumbing' metadata cite _about _param _example _group _author _version +cite about-alias about-plugin about-completion local_setup() { true