From ffa018763c10de63e6548372e7eaad2ae53643d6 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Wed, 25 Jan 2023 05:37:21 -0800 Subject: [PATCH] chore: Fix ShellCheck errors in tests (#1452) --- scripts/shellcheck.bash | 6 ++---- test/asdf_fish.bats | 1 + test/asdf_nu.bats | 1 + test/current_command.bats | 2 +- test/get_asdf_config_value.bats | 1 + test/plugin_list_all_command.bats | 4 ++-- test/shim_env_command.bats | 7 ++++--- test/shim_exec.bats | 1 + test/shim_versions_command.bats | 1 + test/utils.bats | 3 ++- test/version_commands.bats | 1 + 11 files changed, 17 insertions(+), 11 deletions(-) diff --git a/scripts/shellcheck.bash b/scripts/shellcheck.bash index 2318e976..405c0af4 100755 --- a/scripts/shellcheck.bash +++ b/scripts/shellcheck.bash @@ -22,7 +22,5 @@ shellcheck --shell bash --external-sources \ test/fixtures/dummy_legacy_plugin/bin/* \ test/fixtures/dummy_plugin/bin/* -# check .bats files -# TODO(jthegedus): unlock this check later -# TODO shellcheck --shell bats --external-sources \ -# TODO test/*.bats +shellcheck --shell bats --external-source \ + --severity warning test/*.bats diff --git a/test/asdf_fish.bats b/test/asdf_fish.bats index 5271469b..fddc5a96 100644 --- a/test/asdf_fish.bats +++ b/test/asdf_fish.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers diff --git a/test/asdf_nu.bats b/test/asdf_nu.bats index e1aded98..1ec2f56d 100644 --- a/test/asdf_nu.bats +++ b/test/asdf_nu.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers diff --git a/test/current_command.bats b/test/current_command.bats index b32db875..687bc9da 100755 --- a/test/current_command.bats +++ b/test/current_command.bats @@ -121,7 +121,7 @@ foobar 1.0.0 $PROJECT_DIR/.tool-versions" run asdf current "y" [ "$status" -eq 0 ] - [[ "$output" =~ "2.1.0" ]] + [[ "$output" == *'2.1.0'* ]] } @test "with no plugins prints an error" { diff --git a/test/get_asdf_config_value.bats b/test/get_asdf_config_value.bats index b57043b1..87fc0b3d 100644 --- a/test/get_asdf_config_value.bats +++ b/test/get_asdf_config_value.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers diff --git a/test/plugin_list_all_command.bats b/test/plugin_list_all_command.bats index 478e01fa..8f55e18d 100644 --- a/test/plugin_list_all_command.bats +++ b/test/plugin_list_all_command.bats @@ -33,8 +33,8 @@ foo http://example.com/foo" run asdf plugin list all [ "$status" -eq 0 ] - [[ "$output" =~ "$expected_plugin_repo_sync" ]] - [[ "$output" =~ "$expected_plugins_list" ]] + [[ "$output" == *"$expected_plugin_repo_sync"* ]] + [[ "$output" == *"$expected_plugins_list"* ]] } @test "plugin_list_all no immediate repo sync expected because check_duration is greater than 0" { diff --git a/test/shim_env_command.bats b/test/shim_env_command.bats index 8e316da6..c97da850 100644 --- a/test/shim_env_command.bats +++ b/test/shim_env_command.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers @@ -57,7 +58,7 @@ teardown() { run asdf env dummy [ "$status" -eq 0 ] - run grep 'FOO=bar' <(echo "$output") + run grep 'FOO=bar' <<<"$output" [ "$output" = "" ] [ "$status" -eq 1 ] @@ -78,6 +79,6 @@ teardown() { [ "$path_line" != "" ] # Should not contain duplicate colon - run grep '::' <(echo "$path_line") - [ "$duplicate_colon" = "" ] + run grep -q '::' <<<"$path_line" + [ "$status" -ne 0 ] } diff --git a/test/shim_exec.bats b/test/shim_exec.bats index f9b13366..607a65bc 100644 --- a/test/shim_exec.bats +++ b/test/shim_exec.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers diff --git a/test/shim_versions_command.bats b/test/shim_versions_command.bats index e4ed706c..2371231b 100644 --- a/test/shim_versions_command.bats +++ b/test/shim_versions_command.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers diff --git a/test/utils.bats b/test/utils.bats index 8e5037c0..b9f17395 100644 --- a/test/utils.bats +++ b/test/utils.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers @@ -234,7 +235,7 @@ teardown() { run find_versions "dummy" "$PROJECT_DIR" [ "$status" -eq 0 ] - [[ "$output" =~ "0.1.0|$HOME/.dummy-version" ]] + [[ "$output" == *"0.1.0|$HOME/.dummy-version"* ]] } @test "get_preset_version_for returns the current version" { diff --git a/test/version_commands.bats b/test/version_commands.bats index a6ecc40a..9206a3e5 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -1,4 +1,5 @@ #!/usr/bin/env bats +# shellcheck disable=SC2164 load test_helpers