diff --git a/bin/asdf b/bin/asdf index 5845e8f5..2b00a20f 100755 --- a/bin/asdf +++ b/bin/asdf @@ -3,49 +3,12 @@ # shellcheck source=lib/utils.sh source "$(dirname "$(dirname "$0")")/lib/utils.sh" -# shellcheck source=lib/commands/help.sh -source "$(dirname "$(dirname "$0")")/lib/commands/help.sh" -# shellcheck source=lib/commands/shim-exec.sh -source "$(dirname "$(dirname "$0")")/lib/commands/shim-exec.sh" -# shellcheck source=lib/commands/shim-env.sh -source "$(dirname "$(dirname "$0")")/lib/commands/shim-env.sh" -# shellcheck source=lib/commands/update.sh -source "$(dirname "$(dirname "$0")")/lib/commands/update.sh" -# shellcheck source=lib/commands/install.sh -source "$(dirname "$(dirname "$0")")/lib/commands/install.sh" -# shellcheck source=lib/commands/uninstall.sh -source "$(dirname "$(dirname "$0")")/lib/commands/uninstall.sh" -# shellcheck source=lib/commands/current.sh -source "$(dirname "$(dirname "$0")")/lib/commands/current.sh" -# shellcheck source=lib/commands/where.sh -source "$(dirname "$(dirname "$0")")/lib/commands/where.sh" -# shellcheck source=lib/commands/which.sh -source "$(dirname "$(dirname "$0")")/lib/commands/which.sh" -# shellcheck source=lib/commands/shim_versions.sh -source "$(dirname "$(dirname "$0")")/lib/commands/shim_versions.sh" -# shellcheck source=lib/commands/version_commands.sh -source "$(dirname "$(dirname "$0")")/lib/commands/version_commands.sh" -# shellcheck source=lib/commands/list.sh -source "$(dirname "$(dirname "$0")")/lib/commands/list.sh" -# shellcheck source=lib/commands/list-all.sh -source "$(dirname "$(dirname "$0")")/lib/commands/list-all.sh" -# shellcheck source=lib/commands/reshim.sh -source "$(dirname "$(dirname "$0")")/lib/commands/reshim.sh" -# shellcheck source=lib/commands/plugin-add.sh -source "$(dirname "$(dirname "$0")")/lib/commands/plugin-add.sh" -# shellcheck source=lib/commands/plugin-list.sh -source "$(dirname "$(dirname "$0")")/lib/commands/plugin-list.sh" -# shellcheck source=lib/commands/plugin-list-all.sh -source "$(dirname "$(dirname "$0")")/lib/commands/plugin-list-all.sh" -# shellcheck source=lib/commands/plugin-update.sh -source "$(dirname "$(dirname "$0")")/lib/commands/plugin-update.sh" -# shellcheck source=lib/commands/plugin-remove.sh -source "$(dirname "$(dirname "$0")")/lib/commands/plugin-remove.sh" - -# shellcheck source=lib/commands/plugin-push.sh -source "$(dirname "$(dirname "$0")")/lib/commands/plugin-push.sh" -# shellcheck source=lib/commands/plugin-test.sh -source "$(dirname "$(dirname "$0")")/lib/commands/plugin-test.sh" +load_cmd() { + for cmd in "$@"; do + # shellcheck disable=SC1091 + source "$(dirname "$(dirname "$0")")/lib/commands/$cmd.sh" + done +} # shellcheck disable=SC2124 callback_args="${@:2}" @@ -53,76 +16,96 @@ callback_args="${@:2}" # shellcheck disable=SC2086 case $1 in - "--version") - asdf_version $callback_args;; - "exec") + load_cmd "shim-exec" shim_exec_command $callback_args;; "env") + load_cmd "shim-exec" "shim-env" shim_env_command $callback_args;; - "help") - help_command $callback_args;; - "update") + load_cmd "update" update_command $callback_args;; "install") + load_cmd "install" "reshim" install_command $callback_args;; "uninstall") + load_cmd "uninstall" "reshim" uninstall_command $callback_args;; "current") + load_cmd "current" "plugin-list" current_command $callback_args;; "where") + load_cmd "where" where_command $callback_args;; "which") + load_cmd "which" which_command $callback_args;; "local") + load_cmd "version_commands" local_command $callback_args;; "global") + load_cmd "version_commands" global_command $callback_args;; "list") + load_cmd "list" list_command $callback_args;; "list-all") + load_cmd "list-all" list_all_command $callback_args;; "reshim") + load_cmd "reshim" reshim_command $callback_args;; "plugin-add") + load_cmd "plugin-add" plugin_add_command $callback_args;; "plugin-list") + load_cmd "plugin-list" plugin_list_command $callback_args;; "plugin-list-all") + load_cmd "plugin-list-all" plugin_list_all_command $callback_args;; "plugin-update") + load_cmd "plugin-update" plugin_update_command $callback_args;; "plugin-remove") + load_cmd "plugin-remove" plugin_remove_command $callback_args;; # Undocumented commands for development "plugin-push") + load_cmd "plugin-push" plugin_push_command $callback_args;; "plugin-test") + load_cmd "plugin-test" plugin_test_command $callback_args;; "shim-versions") + load_cmd "shim_versions" shim_versions_command $callback_args;; + + "--version") + asdf_version $callback_args;; + *) + load_cmd "help" help_command exit 1;; esac diff --git a/lib/commands/shim-env.sh b/lib/commands/shim-env.sh index 4102d4fa..5040a8b1 100644 --- a/lib/commands/shim-env.sh +++ b/lib/commands/shim-env.sh @@ -2,6 +2,11 @@ shim_env_command() { local shim_name="$1" local env_cmd="${2}" + if [ -z "$shim_name" ]; then + echo "usage: asdf env " + exit 1 + fi + if [ -z "$env_cmd" ]; then env_cmd="env" fi diff --git a/lib/commands/shim-exec.sh b/lib/commands/shim-exec.sh index 0a962731..7a68893b 100644 --- a/lib/commands/shim-exec.sh +++ b/lib/commands/shim-exec.sh @@ -26,6 +26,11 @@ select_from_preset_version() { shim_exec_command() { local shim_name="$1" + if [ -z "$shim_name" ]; then + echo "usage: asdf exec " + exit 1 + fi + selected_version=$(select_from_tool_versions) if [ -z "$selected_version" ]; then diff --git a/test/current_command.bats b/test/current_command.bats index fdc855b6..962bc161 100644 --- a/test/current_command.bats +++ b/test/current_command.bats @@ -2,9 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/current.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list.sh - setup() { setup_asdf_dir install_dummy_plugin @@ -24,7 +21,7 @@ teardown() { cd $PROJECT_DIR echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions - run current_command "dummy" + run asdf current "dummy" [ "$status" -eq 0 ] [ "$output" = "1.1.0 (set by $PROJECT_DIR/.tool-versions)" ] } @@ -33,7 +30,7 @@ teardown() { cd $PROJECT_DIR echo "dummy nightly-2000-01-01" >> $PROJECT_DIR/.tool-versions - run current_command "dummy" + run asdf current "dummy" [ "$status" -eq 0 ] [ "$output" = "nightly-2000-01-01 (set by $PROJECT_DIR/.tool-versions)" ] } @@ -42,7 +39,7 @@ teardown() { cd $PROJECT_DIR echo "dummy 1.2.0 1.1.0" >> $PROJECT_DIR/.tool-versions - run current_command "dummy" + run asdf current "dummy" [ "$status" -eq 0 ] [ "$output" = "1.2.0 1.1.0 (set by $PROJECT_DIR/.tool-versions)" ] } @@ -53,13 +50,13 @@ teardown() { echo 'legacy_version_file = yes' > $HOME/.asdfrc echo '1.2.0' >> $PROJECT_DIR/.dummy-version - run current_command "dummy" + run asdf current "dummy" [ "$status" -eq 0 ] [ "$output" = "1.2.0 (set by $PROJECT_DIR/.dummy-version)" ] } @test "current should error when the plugin doesn't exist" { - run current_command "foobar" + run asdf current "foobar" [ "$status" -eq 1 ] [ "$output" = "No such plugin: foobar" ] } @@ -67,7 +64,7 @@ teardown() { @test "current should error when no version is set" { cd $PROJECT_DIR - run current_command "dummy" + run asdf current "dummy" [ "$status" -eq 126 ] } @@ -75,7 +72,7 @@ teardown() { cd $PROJECT_DIR echo 'dummy 9.9.9' >> $PROJECT_DIR/.tool-versions - run current_command "dummy" + run asdf current "dummy" [ "$status" -eq 1 ] [ "$output" = "version 9.9.9 is not installed for dummy" ] } @@ -94,7 +91,7 @@ teardown() { echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions echo 'foobar 1.0.0' >> $PROJECT_DIR/.tool-versions - run current_command + run asdf current expected="baz No version set for baz; please run \`asdf baz \` dummy 1.1.0 (set by $PROJECT_DIR/.tool-versions) foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)" @@ -113,14 +110,14 @@ foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)" echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions echo 'y 2.1.0' >> $PROJECT_DIR/.tool-versions - run current_command "y" + run asdf current "y" [ "$status" -eq 0 ] [[ "$output" =~ "2.1.0" ]] } @test "with no plugins prints an error" { clean_asdf_dir - run current_command + run asdf current [ "$status" -eq 0 ] echo "$output" | grep "Oohes nooes ~! No plugins installed" } diff --git a/test/install_command.bats b/test/install_command.bats index 3a44cd97..120b0d58 100644 --- a/test/install_command.bats +++ b/test/install_command.bats @@ -2,9 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh - setup() { setup_asdf_dir install_dummy_plugin @@ -18,7 +15,7 @@ teardown() { } @test "install_command installs the correct version" { - run install_command dummy 1.1 + run asdf install dummy 1.1 [ "$status" -eq 0 ] [ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ] } @@ -26,13 +23,13 @@ teardown() { @test "install_command installs even if the user is terrible and does not use newlines" { cd $PROJECT_DIR echo -n 'dummy 1.2' > ".tool-versions" - run install_command + run asdf install [ "$status" -eq 0 ] [ $(cat $ASDF_DIR/installs/dummy/1.2/version) = "1.2" ] } @test "install_command set ASDF_CONCURRENCY" { - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$status" -eq 0 ] [ -f $ASDF_DIR/installs/dummy/1.0/env ] run grep ASDF_CONCURRENCY $ASDF_DIR/installs/dummy/1.0/env @@ -45,14 +42,14 @@ teardown() { cd "$WHITESPACE_DIR" echo 'dummy 1.2' >> "$WHITESPACE_DIR/.tool-versions" - run install_command + run asdf install [ "$status" -eq 0 ] [ $(cat $ASDF_DIR/installs/dummy/1.2/version) = "1.2" ] } @test "install_command should create a shim with asdf-plugin metadata" { - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$status" -eq 0 ] [ -f $ASDF_DIR/installs/dummy/1.0/env ] run grep "asdf-plugin: dummy 1.0" $ASDF_DIR/shims/dummy @@ -60,7 +57,7 @@ teardown() { } @test "install_command on two versions should create a shim with asdf-plugin metadata" { - run install_command dummy 1.1 + run asdf install dummy 1.1 [ "$status" -eq 0 ] run grep "asdf-plugin: dummy 1.1" $ASDF_DIR/shims/dummy @@ -69,7 +66,7 @@ teardown() { run grep "asdf-plugin: dummy 1.0" $ASDF_DIR/shims/dummy [ "$status" -eq 1 ] - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$status" -eq 0 ] run grep "asdf-plugin: dummy 1.0" $ASDF_DIR/shims/dummy [ "$status" -eq 0 ] @@ -85,7 +82,7 @@ teardown() { cd $PROJECT_DIR echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions - run install_command + run asdf install [ "$status" -eq 0 ] [ -f "$ASDF_DIR/shims/dummy" ] [ ! -f "$ASDF_DIR/shims/subdir" ] @@ -97,7 +94,7 @@ teardown() { cd $PROJECT_DIR echo 'dummy 1.0' > $PROJECT_DIR/.tool-versions - run install_command + run asdf install # execute the generated shim run $ASDF_DIR/shims/dummy world hello @@ -106,12 +103,12 @@ teardown() { } @test "install_command fails when the name or version are not specified" { - run install_command dummy + run asdf install dummy [ "$status" -eq 1 ] [ "$output" = "You must specify a name and a version to install" ] [ ! -f $ASDF_DIR/installs/dummy/1.1/version ] - run install_command 1.1 + run asdf install 1.1 [ "$status" -eq 1 ] [ "$output" = "You must specify a name and a version to install" ] [ ! -f $ASDF_DIR/installs/dummy/1.1/version ] @@ -126,7 +123,7 @@ teardown() { cd $PROJECT_DIR/child - run install_command + run asdf install # execute the generated shim [ "$($ASDF_DIR/shims/dummy world hello)" == "This is Dummy 1.0! hello world" ] @@ -134,7 +131,7 @@ teardown() { } @test "install_command doesn't install system version" { - run install_command dummy system + run asdf install dummy system [ "$status" -eq 0 ] [ ! -f $ASDF_DIR/installs/dummy/system/version ] } @@ -144,7 +141,7 @@ teardown() { pre_asdf_install_dummy = echo will install dummy $1 EOM - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$output" == "will install dummy 1.0" ] } @@ -153,6 +150,6 @@ EOM post_asdf_install_dummy = echo HEY $version FROM $plugin_name EOM - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$output" == "HEY 1.0 FROM dummy" ] } diff --git a/test/list_command.bats b/test/list_command.bats index cf4a0f3d..06f1e188 100644 --- a/test/list_command.bats +++ b/test/list_command.bats @@ -2,9 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/list.sh - setup() { setup_asdf_dir install_dummy_plugin @@ -15,9 +12,9 @@ teardown() { } @test "list_command should list plugins with installed versions" { - run install_command dummy 1.0 - run install_command dummy 1.1 - run list_command + run asdf install dummy 1.0 + run asdf install dummy 1.1 + run asdf list [ "$(echo -e "dummy\n 1.0\n 1.1")" == "$output" ] [ "$status" -eq 0 ] } @@ -26,17 +23,17 @@ teardown() { run install_mock_plugin "dummy" run install_mock_plugin "mummy" run install_mock_plugin "tummy" - run install_command dummy 1.0 - run install_command tummy 2.0 - run list_command + run asdf install dummy 1.0 + run asdf install tummy 2.0 + run asdf list [ "$(echo -e "dummy\n 1.0\nmummy\nNo versions installed\ntummy\n 2.0")" == "$output" ] [ "$status" -eq 0 ] } @test "list_command with plugin should list installed versions" { - run install_command dummy 1.0 - run install_command dummy 1.1 - run list_command dummy + run asdf install dummy 1.0 + run asdf install dummy 1.1 + run asdf list dummy [ "$(echo -e " 1.0\n 1.1")" == "$output" ] [ "$status" -eq 0 ] } diff --git a/test/plugin_commands.bats b/test/plugin_commands.bats index 4d7e4b0c..fa6a8bf0 100644 --- a/test/plugin_commands.bats +++ b/test/plugin_commands.bats @@ -2,9 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-add.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list.sh - setup() { setup_asdf_dir } @@ -14,16 +11,16 @@ teardown() { } @test "plugin_add command with no URL specified adds a plugin using repo" { - run plugin_add_command "elixir" + run asdf plugin-add "elixir" [ "$status" -eq 0 ] - run plugin_list_command + run asdf plugin-list # whitespace between 'elixir' and url is from printf %-15s %s format [ "$output" = "elixir" ] } @test "plugin_add command with no URL specified fails if the plugin doesn't exist" { - run plugin_add_command "does-not-exist" + run asdf plugin-add "does-not-exist" [ "$status" -eq 1 ] echo "$output" | grep "plugin does-not-exist not found in repository" } diff --git a/test/plugin_list_all_command.bats b/test/plugin_list_all_command.bats index 1f0a64ac..7ab4ad77 100644 --- a/test/plugin_list_all_command.bats +++ b/test/plugin_list_all_command.bats @@ -2,8 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list-all.sh - setup() { setup_asdf_dir setup_repo @@ -15,7 +13,7 @@ teardown() { } @test "plugin_list_all list all plugins in the repository" { - run plugin_list_all_command + run asdf plugin-list-all local expected="bar http://example.com/bar dummy *http://example.com/dummy foo http://example.com/foo" diff --git a/test/plugin_test_command.bats b/test/plugin_test_command.bats index adfa4ad4..332ce1d9 100644 --- a/test/plugin_test_command.bats +++ b/test/plugin_test_command.bats @@ -2,10 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-add.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-test.sh - setup() { setup_asdf_dir } @@ -15,13 +11,13 @@ teardown() { } @test "plugin_test_command with no URL specified prints an error" { - run plugin_test_command "elixir" + run asdf plugin-test "elixir" [ "$status" -eq 1 ] [ "$output" = "FAILED: please provide a plugin name and url" ] } @test "plugin_test_command with no name or URL specified prints an error" { - run plugin_test_command + run asdf plugin-test [ "$status" -eq 1 ] [ "$output" = "FAILED: please provide a plugin name and url" ] } diff --git a/test/remove_command.bats b/test/remove_command.bats index 72952e0a..0f2fa1f6 100644 --- a/test/remove_command.bats +++ b/test/remove_command.bats @@ -2,10 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-remove.sh - setup() { setup_asdf_dir } @@ -17,41 +13,41 @@ teardown() { @test "plugin_remove_command removes a plugin" { install_dummy_plugin - run plugin_remove_command "dummy" + run asdf plugin-remove "dummy" [ "$status" -eq 0 ] [ "$output" = "" ] } @test "plugin_remove_command should exit with 1 when not passed any arguments" { - run plugin_remove_command + run asdf plugin-remove [ "$status" -eq 1 ] [ "$output" = "No plugin given" ] } @test "plugin_remove_command should exit with 1 when passed invalid plugin name" { - run plugin_remove_command "does-not-exist" + run asdf plugin-remove "does-not-exist" [ "$status" -eq 1 ] [ "$output" = "No such plugin: does-not-exist" ] } @test "plugin_remove_command should remove installed versions" { install_dummy_plugin - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$status" -eq 0 ] [ -d $ASDF_DIR/installs/dummy ] - run plugin_remove_command dummy + run asdf plugin-remove dummy [ "$status" -eq 0 ] [ ! -d $ASDF_DIR/installs/dummy ] } @test "plugin_remove_command should also remove shims for that plugin" { install_dummy_plugin - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$status" -eq 0 ] [ -f $ASDF_DIR/shims/dummy ] - run plugin_remove_command dummy + run asdf plugin-remove dummy [ "$status" -eq 0 ] [ ! -f $ASDF_DIR/shims/dummy ] } @@ -59,12 +55,12 @@ teardown() { @test "plugin_remove_command should not remove unrelated shims" { install_dummy_plugin - run install_command dummy 1.0 + run asdf install dummy 1.0 # make an unrelated shim echo "# asdf-plugin: gummy" > $ASDF_DIR/shims/gummy - run plugin_remove_command dummy + run asdf plugin-remove dummy [ "$status" -eq 0 ] # unrelated shim should exist diff --git a/test/reshim_command.bats b/test/reshim_command.bats index 0d8e9c5d..c20133cc 100644 --- a/test/reshim_command.bats +++ b/test/reshim_command.bats @@ -2,9 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh - setup() { setup_asdf_dir install_dummy_plugin @@ -19,26 +16,26 @@ teardown() { @test "reshim command should remove shims of removed binaries" { - run install_command dummy 1.0 + run asdf install dummy 1.0 [ "$status" -eq 0 ] [ -f "$ASDF_DIR/shims/dummy" ] - run reshim_command dummy + run asdf reshim dummy [ "$status" -eq 0 ] [ -f "$ASDF_DIR/shims/dummy" ] run rm "$ASDF_DIR/installs/dummy/1.0/bin/dummy" - run reshim_command dummy + run asdf reshim dummy [ "$status" -eq 0 ] [ ! -f "$ASDF_DIR/shims/dummy" ] } @test "reshim should remove metadata of removed binaries" { - run install_command dummy 1.0 - run install_command dummy 1.1 + run asdf install dummy 1.0 + run asdf install dummy 1.1 run rm "$ASDF_DIR/installs/dummy/1.0/bin/dummy" - run reshim_command dummy + run asdf reshim dummy [ "$status" -eq 0 ] [ -f "$ASDF_DIR/shims/dummy" ] run grep "asdf-plugin: dummy 1.0" "$ASDF_DIR/shims/dummy" @@ -50,8 +47,8 @@ teardown() { @test "reshim should not duplicate shims" { cd $PROJECT_DIR - run install_command dummy 1.0 - run install_command dummy 1.1 + run asdf install dummy 1.0 + run asdf install dummy 1.1 [ "$status" -eq 0 ] [ -f "$ASDF_DIR/shims/dummy" ] @@ -59,11 +56,11 @@ teardown() { [ "$status" -eq 0 ] [ "0" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] - run reshim_command dummy + run asdf reshim dummy [ "$status" -eq 0 ] [ "1" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] - run reshim_command dummy + run asdf reshim dummy [ "$status" -eq 0 ] [ "1" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] } @@ -71,8 +68,8 @@ teardown() { @test "reshim should create shims only for files and not folders" { cd $PROJECT_DIR - run install_command dummy 1.0 - run install_command dummy 1.1 + run asdf install dummy 1.0 + run asdf install dummy 1.1 [ "$status" -eq 0 ] [ -f "$ASDF_DIR/shims/dummy" ] [ ! -f "$ASDF_DIR/shims/subdir" ] @@ -82,7 +79,7 @@ teardown() { [ "0" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] [ "0" -eq "$(ls $ASDF_DIR/shims/subdir* | wc -l)" ] - run reshim_command dummy + run asdf reshim dummy [ "$status" -eq 0 ] [ "1" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] [ "0" -eq "$(ls $ASDF_DIR/shims/subdir* | wc -l)" ] @@ -90,33 +87,33 @@ teardown() { } @test "reshim without arguments reshims all installed plugins" { - run install_command dummy 1.0 + run asdf install dummy 1.0 run rm $ASDF_DIR/shims/* [ "$status" -eq 0 ] [ "0" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] - run reshim_command + run asdf reshim [ "$status" -eq 0 ] [ "1" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] } @test "reshim command executes configured pre hook" { - run install_command dummy 1.0 + run asdf install dummy 1.0 cat > $HOME/.asdfrc <<-'EOM' pre_asdf_reshim_dummy = echo RESHIM EOM - run reshim_command dummy 1.0 + run asdf reshim dummy 1.0 [ "$output" == "RESHIM" ] } @test "reshim command executes configured post hook" { - run install_command dummy 1.0 + run asdf install dummy 1.0 cat > $HOME/.asdfrc <<-'EOM' post_asdf_reshim_dummy = echo RESHIM EOM - run reshim_command dummy 1.0 + run asdf reshim dummy 1.0 [ "$output" == "RESHIM" ] } diff --git a/test/shim_env_command.bats b/test/shim_env_command.bats index d543701c..6879185e 100644 --- a/test/shim_env_command.bats +++ b/test/shim_env_command.bats @@ -2,10 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/shim-env.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh - setup() { setup_asdf_dir install_dummy_plugin @@ -22,11 +18,17 @@ teardown() { clean_asdf_dir } +@test "asdf env without argument should display help" { + run asdf env + [ "$status" -eq 1 ] + echo "$output" | grep "usage: asdf env " +} + @test "asdf env should execute under the environment used for a shim" { echo "dummy 1.0" > $PROJECT_DIR/.tool-versions - run install_command + run asdf install - run $ASDF_DIR/bin/asdf env dummy which dummy + run asdf env dummy which dummy [ "$status" -eq 0 ] [ "$output" == "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ] } @@ -34,33 +36,33 @@ teardown() { @test "asdf env should execute under plugin custom environment used for a shim" { echo "dummy 1.0" > $PROJECT_DIR/.tool-versions - run install_command + run asdf install echo "export FOO=bar" > $ASDF_DIR/plugins/dummy/bin/exec-env chmod +x $ASDF_DIR/plugins/dummy/bin/exec-env - run $ASDF_DIR/bin/asdf env dummy + run asdf env dummy [ "$status" -eq 0 ] echo $output | grep 'FOO=bar' } @test "asdf env should ignore plugin custom environment on system version" { echo "dummy 1.0" > $PROJECT_DIR/.tool-versions - run install_command + run asdf install echo "export FOO=bar" > $ASDF_DIR/plugins/dummy/bin/exec-env chmod +x $ASDF_DIR/plugins/dummy/bin/exec-env echo "dummy system" > $PROJECT_DIR/.tool-versions - run $ASDF_DIR/bin/asdf env dummy + run asdf env dummy [ "$status" -eq 0 ] run grep 'FOO=bar' <(echo $output) [ "$output" == "" ] [ "$status" -eq 1 ] - run $ASDF_DIR/bin/asdf env dummy which dummy + run asdf env dummy which dummy [ "$output" == "" ] [ "$status" -eq 1 ] } diff --git a/test/shim_exec.bats b/test/shim_exec.bats index 2ad6128f..f007d664 100644 --- a/test/shim_exec.bats +++ b/test/shim_exec.bats @@ -21,32 +21,38 @@ teardown() { clean_asdf_dir } +@test "asdf exec without argument should display help" { + run asdf exec + [ "$status" -eq 1 ] + echo "$output" | grep "usage: asdf exec " +} + @test "asdf exec should pass all arguments to executable" { echo "dummy 1.0" > $PROJECT_DIR/.tool-versions - run install_command + run asdf install - run $ASDF_DIR/bin/asdf exec dummy world hello + run asdf exec dummy world hello [ "$output" == "This is Dummy 1.0! hello world" ] [ "$status" -eq 0 ] } @test "asdf exec should pass all arguments to executable even if shim is not in PATH" { echo "dummy 1.0" > $PROJECT_DIR/.tool-versions - run install_command + run asdf install path=$(echo "$PATH" | sed -e "s|$(asdf_data_dir)/shims||g; s|::|:|g") run env PATH=$path which dummy [ "$output" == "" ] [ "$status" -eq 1 ] - run env PATH=$path $ASDF_DIR/bin/asdf exec dummy world hello + run env PATH=$path asdf exec dummy world hello [ "$output" == "This is Dummy 1.0! hello world" ] [ "$status" -eq 0 ] } @test "shim exec should pass all arguments to executable" { echo "dummy 1.0" > $PROJECT_DIR/.tool-versions - run install_command + run asdf install run $ASDF_DIR/shims/dummy world hello [ "$output" == "This is Dummy 1.0! hello world" ] @@ -55,12 +61,12 @@ teardown() { @test "shim exec should pass stdin to executable" { echo "dummy 1.0" > $PROJECT_DIR/.tool-versions - run install_command + run asdf install echo "tr [:lower:] [:upper:]" > $ASDF_DIR/installs/dummy/1.0/bin/upper chmod +x $ASDF_DIR/installs/dummy/1.0/bin/upper - run reshim_command dummy 1.0 + run asdf reshim dummy 1.0 run echo $(echo hello | $ASDF_DIR/shims/upper) [ "$output" == "HELLO" ] @@ -68,7 +74,7 @@ teardown() { } @test "shim exec should fail if no version is selected" { - run install_command dummy 1.0 + run asdf install dummy 1.0 touch $PROJECT_DIR/.tool-versions @@ -78,8 +84,8 @@ teardown() { } @test "shim exec should suggest which plugin to use when no version is selected" { - run install_command dummy 1.0 - run install_command dummy 2.0 + run asdf install dummy 1.0 + run asdf install dummy 2.0 touch $PROJECT_DIR/.tool-versions @@ -96,8 +102,8 @@ teardown() { # Another fake plugin with 'dummy' executable cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/mummy - run install_command dummy 1.0 - run install_command mummy 3.0 + run asdf install dummy 1.0 + run asdf install mummy 3.0 touch $PROJECT_DIR/.tool-versions @@ -111,7 +117,7 @@ teardown() { } @test "shim exec should execute first plugin that is installed and set" { - run install_command dummy 3.0 + run asdf install dummy 3.0 echo "dummy 1.0" > $PROJECT_DIR/.tool-versions echo "dummy 3.0" >> $PROJECT_DIR/.tool-versions @@ -128,8 +134,8 @@ teardown() { cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/mummy sed -i -e 's/Dummy/Mummy/' $ASDF_DIR/plugins/mummy/bin/install - run install_command mummy 3.0 - run install_command dummy 1.0 + run asdf install mummy 3.0 + run asdf install dummy 1.0 mkdir $PROJECT_DIR/{A,B} echo "dummy 1.0" > $PROJECT_DIR/A/.tool-versions @@ -151,8 +157,8 @@ teardown() { cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/mummy sed -i -e 's/Dummy/Mummy/' $ASDF_DIR/plugins/mummy/bin/install - run install_command dummy 1.0 - run install_command mummy 3.0 + run asdf install dummy 1.0 + run asdf install mummy 3.0 echo "dummy 2.0" > $PROJECT_DIR/.tool-versions echo "mummy 3.0" >> $PROJECT_DIR/.tool-versions @@ -164,7 +170,7 @@ teardown() { } @test "shim exec should fallback to system executable when specified version is system" { - run install_command dummy 1.0 + run asdf install dummy 1.0 echo "dummy system" > $PROJECT_DIR/.tool-versions @@ -177,7 +183,7 @@ teardown() { } @test "shim exec should execute system if set first" { - run install_command dummy 2.0 + run asdf install dummy 2.0 echo "dummy system" > $PROJECT_DIR/.tool-versions echo "dummy 2.0" >> $PROJECT_DIR/.tool-versions @@ -191,12 +197,12 @@ teardown() { } @test "shim exec should use custom exec-env for tool" { - run install_command dummy 2.0 + run asdf install dummy 2.0 echo "export FOO=sourced" > $ASDF_DIR/plugins/dummy/bin/exec-env mkdir $ASDF_DIR/plugins/dummy/shims echo 'echo $FOO custom' > $ASDF_DIR/plugins/dummy/shims/foo chmod +x $ASDF_DIR/plugins/dummy/shims/foo - run reshim_command dummy 2.0 + run asdf reshim dummy 2.0 echo "dummy 2.0" > $PROJECT_DIR/.tool-versions run $ASDF_DIR/shims/foo @@ -204,12 +210,12 @@ teardown() { } @test "shim exec doest not use custom exec-env for system version" { - run install_command dummy 2.0 + run asdf install dummy 2.0 echo "export FOO=sourced" > $ASDF_DIR/plugins/dummy/bin/exec-env mkdir $ASDF_DIR/plugins/dummy/shims echo 'echo $FOO custom' > $ASDF_DIR/plugins/dummy/shims/foo chmod +x $ASDF_DIR/plugins/dummy/shims/foo - run reshim_command dummy 2.0 + run asdf reshim dummy 2.0 echo "dummy system" > $PROJECT_DIR/.tool-versions @@ -222,12 +228,12 @@ teardown() { } @test "shim exec should prepend the plugin paths on execution" { - run install_command dummy 2.0 + run asdf install dummy 2.0 mkdir $ASDF_DIR/plugins/dummy/shims echo 'which dummy' > $ASDF_DIR/plugins/dummy/shims/foo chmod +x $ASDF_DIR/plugins/dummy/shims/foo - run reshim_command dummy 2.0 + run asdf reshim dummy 2.0 echo "dummy 2.0" > $PROJECT_DIR/.tool-versions @@ -236,7 +242,7 @@ teardown() { } @test "shim exec should remove shim_path from path on system version execution" { - run install_command dummy 2.0 + run asdf install dummy 2.0 echo "dummy system" > $PROJECT_DIR/.tool-versions @@ -250,7 +256,7 @@ teardown() { @test "shim exec can take version from legacy file if configured" { - run install_command dummy 2.0 + run asdf install dummy 2.0 echo "legacy_version_file = yes" > $HOME/.asdfrc echo "2.0" > $PROJECT_DIR/.dummy-version @@ -260,7 +266,7 @@ teardown() { } @test "shim exec can take version from environment variable" { - run install_command dummy 2.0 + run asdf install dummy 2.0 run env ASDF_DUMMY_VERSION=2.0 $ASDF_DIR/shims/dummy world hello [ "$output" == "This is Dummy 2.0! hello world" ] } @@ -272,21 +278,21 @@ teardown() { echo "echo bin custom" > $exec_path chmod +x $exec_path - run install_command dummy 1.0 + run asdf install dummy 1.0 echo "dummy 1.0" > $PROJECT_DIR/.tool-versions mkdir $custom_path echo "echo CUSTOM" > $custom_path/foo chmod +x $custom_path/foo - run reshim_command dummy 1.0 + run asdf reshim dummy 1.0 run $ASDF_DIR/shims/foo [ "$output" == "CUSTOM" ] } @test "shim exec uses plugin custom exec-path hook" { - run install_command dummy 1.0 + run asdf install dummy 1.0 exec_path="$ASDF_DIR/plugins/dummy/bin/exec-path" custom_dummy="$PROJECT_DIR/custom" @@ -304,7 +310,7 @@ teardown() { } @test "shim exec executes configured pre-hook" { - run install_command dummy 1.0 + run asdf install dummy 1.0 echo dummy 1.0 > $PROJECT_DIR/.tool-versions cat > $HOME/.asdfrc <<-'EOM' @@ -318,7 +324,7 @@ EOM } @test "shim exec doesnt execute command if pre-hook failed" { - run install_command dummy 1.0 + run asdf install dummy 1.0 echo dummy 1.0 > $PROJECT_DIR/.tool-versions mkdir $HOME/hook @@ -336,7 +342,7 @@ EOM } @test "shim exec executes configured post-hook if command was successful" { - run install_command dummy 1.0 + run asdf install dummy 1.0 echo dummy 1.0 > $PROJECT_DIR/.tool-versions cat > $HOME/.asdfrc <<-'EOM' @@ -350,7 +356,7 @@ EOM } @test "shim exec does not executes configured post-hook if command failed" { - run install_command dummy 1.0 + run asdf install dummy 1.0 echo dummy 1.0 > $PROJECT_DIR/.tool-versions cat > $HOME/.asdfrc <<-'EOM' diff --git a/test/shim_versions_command.bats b/test/shim_versions_command.bats index 367e27ed..35727c4e 100644 --- a/test/shim_versions_command.bats +++ b/test/shim_versions_command.bats @@ -21,11 +21,11 @@ teardown() { @test "shim_versions_command should list plugins and versions where command is available" { cd $PROJECT_DIR - run install_command dummy 3.0 - run install_command dummy 1.0 - run reshim_command dummy + run asdf install dummy 3.0 + run asdf install dummy 1.0 + run asdf reshim dummy - run shim_versions_command dummy + run asdf shim-versions dummy [ "$status" -eq 0 ] echo "$output" | grep "dummy 3.0" diff --git a/test/test_helpers.bash b/test/test_helpers.bash index 4a77dba4..7391d744 100644 --- a/test/test_helpers.bash +++ b/test/test_helpers.bash @@ -11,7 +11,8 @@ setup_asdf_dir() { mkdir -p "$ASDF_DIR/installs" mkdir -p "$ASDF_DIR/shims" mkdir -p "$ASDF_DIR/tmp" - PATH=$ASDF_DIR/shims:$PATH + ASDF_BIN=$(dirname "$BATS_TEST_DIRNAME")/bin + PATH=$ASDF_DIR/shims:$ASDF_BIN:$PATH } install_mock_plugin() { @@ -56,3 +57,4 @@ setup_repo() { cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugins_repo" "$ASDF_DIR/repository" touch "$(asdf_dir)/tmp/repo-updated" } + diff --git a/test/uninstall_command.bats b/test/uninstall_command.bats index 109a3341..ae3dfa7e 100644 --- a/test/uninstall_command.bats +++ b/test/uninstall_command.bats @@ -19,57 +19,57 @@ teardown() { } @test "uninstall_command should fail when no such version is installed" { - run uninstall_command dummy 3.14 + run asdf uninstall dummy 3.14 [ "$output" == "No such version" ] [ "$status" -eq 1 ] } @test "uninstall_command should remove the plugin with that version from asdf" { - run install_command dummy 1.1 + run asdf install dummy 1.1 [ "$status" -eq 0 ] [ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ] - run uninstall_command dummy 1.1 + run asdf uninstall dummy 1.1 [ ! -f $ASDF_DIR/installs/dummy/1.1/version ] } @test "uninstall_command should invoke the plugin bin/uninstall if available" { - run install_command dummy 1.1 + run asdf install dummy 1.1 [ "$status" -eq 0 ] mkdir -p $ASDF_DIR/plugins/dummy/bin echo "echo custom uninstall" > $ASDF_DIR/plugins/dummy/bin/uninstall chmod 755 $ASDF_DIR/plugins/dummy/bin/uninstall - run uninstall_command dummy 1.1 + run asdf uninstall dummy 1.1 [ "$output" == "custom uninstall" ] [ "$status" -eq 0 ] } @test "uninstall_command should remove the plugin shims if no other version is installed" { - run install_command dummy 1.1 + run asdf install dummy 1.1 [ -f $ASDF_DIR/shims/dummy ] - run uninstall_command dummy 1.1 + run asdf uninstall dummy 1.1 [ ! -f $ASDF_DIR/shims/dummy ] } @test "uninstall_command should leave the plugin shims if other version is installed" { - run install_command dummy 1.0 + run asdf install dummy 1.0 [ -f $ASDF_DIR/installs/dummy/1.0/bin/dummy ] - run install_command dummy 1.1 + run asdf install dummy 1.1 [ -f $ASDF_DIR/installs/dummy/1.1/bin/dummy ] [ -f $ASDF_DIR/shims/dummy ] - run uninstall_command dummy 1.0 + run asdf uninstall dummy 1.0 [ -f $ASDF_DIR/shims/dummy ] } @test "uninstall_command should remove relevant asdf-plugin metadata" { - run install_command dummy 1.0 + run asdf install dummy 1.0 [ -f $ASDF_DIR/installs/dummy/1.0/bin/dummy ] - run install_command dummy 1.1 + run asdf install dummy 1.1 [ -f $ASDF_DIR/installs/dummy/1.1/bin/dummy ] - run uninstall_command dummy 1.0 + run asdf uninstall dummy 1.0 run grep "asdf-plugin: dummy 1.1" $ASDF_DIR/shims/dummy [ "$status" -eq 0 ] run grep "asdf-plugin: dummy 1.0" $ASDF_DIR/shims/dummy @@ -77,13 +77,13 @@ teardown() { } @test "uninstall_command should not remove other unrelated shims" { - run install_command dummy 1.0 + run asdf install dummy 1.0 [ -f $ASDF_DIR/shims/dummy ] touch $ASDF_DIR/shims/gummy [ -f $ASDF_DIR/shims/gummy ] - run uninstall_command dummy 1.0 + run asdf uninstall dummy 1.0 [ -f $ASDF_DIR/shims/gummy ] } @@ -92,8 +92,8 @@ teardown() { pre_asdf_uninstall_dummy = echo will uninstall dummy $1 EOM - run install_command dummy 1.0 - run uninstall_command dummy 1.0 + run asdf install dummy 1.0 + run asdf uninstall dummy 1.0 [ "$output" == "will uninstall dummy 1.0" ] } @@ -102,8 +102,8 @@ EOM post_asdf_uninstall_dummy = echo removed dummy $1 EOM - run install_command dummy 1.0 - run uninstall_command dummy 1.0 + run asdf install dummy 1.0 + run asdf uninstall dummy 1.0 echo $output [ "$output" == "removed dummy 1.0" ] } diff --git a/test/update_command.bats b/test/update_command.bats index 0c1d3d73..84789876 100644 --- a/test/update_command.bats +++ b/test/update_command.bats @@ -3,9 +3,6 @@ load test_helpers . $(dirname "$BATS_TEST_DIRNAME")/lib/commands/update.sh -. $(dirname "$BATS_TEST_DIRNAME")/lib/commands/reshim.sh -. $(dirname "$BATS_TEST_DIRNAME")/lib/commands/install.sh -. $(dirname "$BATS_TEST_DIRNAME")/lib/commands/uninstall.sh setup() { setup_asdf_dir @@ -49,7 +46,7 @@ teardown() { } @test "update_command should not remove plugin versions" { - run install_command dummy 1.1 + run asdf install dummy 1.1 [ "$status" -eq 0 ] [ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ] run update_command @@ -71,7 +68,7 @@ teardown() { } @test "update_command should not remove shims" { - run install_command dummy 1.1 + run asdf install dummy 1.1 [ -f $ASDF_DIR/shims/dummy ] run update_command [ "$status" -eq 0 ] diff --git a/test/version_commands.bats b/test/version_commands.bats index 2457cdce..46eb78d1 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -25,31 +25,31 @@ teardown() { # Warn users who invoke the old style command without arguments. @test "local should emit an error when called with incorrect arity" { - run local_command "dummy" + run asdf local "dummy" [ "$status" -eq 1 ] [ "$output" = "Usage: asdf local " ] } @test "local should emit an error when plugin does not exist" { - run local_command "inexistent" "1.0.0" + run asdf local "inexistent" "1.0.0" [ "$status" -eq 1 ] [ "$output" = "No such plugin: inexistent" ] } @test "local should emit an error when plugin version does not exist" { - run local_command "dummy" "0.0.1" + run asdf local "dummy" "0.0.1" [ "$status" -eq 1 ] [ "$output" = "version 0.0.1 is not installed for dummy" ] } @test "local should create a local .tool-versions file if it doesn't exist" { - run local_command "dummy" "1.1.0" + run asdf local "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] } @test "local should allow multiple versions" { - run local_command "dummy" "1.1.0" "1.0.0" + run asdf local "dummy" "1.1.0" "1.0.0" [ "$status" -eq 0 ] [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0 1.0.0" ] } @@ -59,7 +59,7 @@ teardown() { mkdir -p "$WHITESPACE_DIR" cd "$WHITESPACE_DIR" - run local_command "dummy" "1.1.0" + run asdf local "dummy" "1.1.0" tool_version_contents=$(cat "$WHITESPACE_DIR/.tool-versions") [ "$status" -eq 0 ] @@ -69,45 +69,45 @@ teardown() { @test "local should not create a duplicate .tool-versions file if such file exists" { echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions - run local_command "dummy" "1.1.0" + run asdf local "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(ls $PROJECT_DIR/.tool-versions* | wc -l)" -eq 1 ] } @test "local should overwrite the existing version if it's set" { echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions - run local_command "dummy" "1.1.0" + run asdf local "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] } @test "local should fail to set a path:dir if dir does not exists " { - run local_command "dummy" "path:$PROJECT_DIR/local" - [ "$output" = "version path:$PROJECT_DIR/local is not installed for dummy" ] - [ "$status" -eq 1 ] + run asdf local "dummy" "path:$PROJECT_DIR/local" + [ "$output" = "version path:$PROJECT_DIR/local is not installed for dummy" ] + [ "$status" -eq 1 ] } @test "local should set a path:dir if dir exists " { - mkdir -p $PROJECT_DIR/local - run local_command "dummy" "path:$PROJECT_DIR/local" - [ "$status" -eq 0 ] - [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ] + mkdir -p $PROJECT_DIR/local + run asdf local "dummy" "path:$PROJECT_DIR/local" + [ "$status" -eq 0 ] + [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ] } @test "local -p/--parent should set should emit an error when called with incorrect arity" { - run local_command -p "dummy" + run asdf local -p "dummy" [ "$status" -eq 1 ] [ "$output" = "Usage: asdf local " ] } @test "local -p/--parent should emit an error when plugin does not exist" { - run local_command -p "inexistent" "1.0.0" + run asdf local -p "inexistent" "1.0.0" [ "$status" -eq 1 ] [ "$output" = "No such plugin: inexistent" ] } @test "local -p/--parent should emit an error when plugin version does not exist" { - run local_command -p "dummy" "0.0.1" + run asdf local -p "dummy" "0.0.1" [ "$status" -eq 1 ] [ "$output" = "version 0.0.1 is not installed for dummy" ] } @@ -115,7 +115,7 @@ teardown() { @test "local -p/--parent should allow multiple versions" { cd $CHILD_DIR touch $PROJECT_DIR/.tool-versions - run local_command -p "dummy" "1.1.0" "1.0.0" + run asdf local -p "dummy" "1.1.0" "1.0.0" [ "$status" -eq 0 ] [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0 1.0.0" ] } @@ -123,7 +123,7 @@ teardown() { @test "local -p/--parent should overwrite the existing version if it's set" { cd $CHILD_DIR echo 'dummy 1.0.0' >> $PROJECT_DIR/.tool-versions - run local_command -p "dummy" "1.1.0" + run asdf local -p "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] } @@ -131,65 +131,67 @@ teardown() { @test "local -p/--parent should set the version if it's unset" { cd $CHILD_DIR touch $PROJECT_DIR/.tool-versions - run local_command -p "dummy" "1.1.0" + run asdf local -p "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $PROJECT_DIR/.tool-versions)" = "dummy 1.1.0" ] } @test "global should create a global .tool-versions file if it doesn't exist" { - run global_command "dummy" "1.1.0" + run asdf global "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ] } @test "global should accept multiple versions" { - run global_command "dummy" "1.1.0" "1.0.0" + run asdf global "dummy" "1.1.0" "1.0.0" [ "$status" -eq 0 ] [ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0 1.0.0" ] } @test "global should overwrite the existing version if it's set" { echo 'dummy 1.0.0' >> $HOME/.tool-versions - run global_command "dummy" "1.1.0" + run asdf global "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $HOME/.tool-versions)" = "dummy 1.1.0" ] } @test "global should fail to set a path:dir if dir does not exists " { - run global_command "dummy" "path:$PROJECT_DIR/local" - [ "$output" = "version path:$PROJECT_DIR/local is not installed for dummy" ] - [ "$status" -eq 1 ] + run asdf global "dummy" "path:$PROJECT_DIR/local" + [ "$output" = "version path:$PROJECT_DIR/local is not installed for dummy" ] + [ "$status" -eq 1 ] } @test "global should set a path:dir if dir exists " { - mkdir -p $PROJECT_DIR/local - run global_command "dummy" "path:$PROJECT_DIR/local" - [ "$status" -eq 0 ] - [ "$(cat $HOME/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ] + mkdir -p $PROJECT_DIR/local + run asdf global "dummy" "path:$PROJECT_DIR/local" + [ "$status" -eq 0 ] + [ "$(cat $HOME/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ] } @test "global should write to ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" { - ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions" - run global_command "dummy" "1.1.0" + export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions" + run asdf global "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] [ "$(cat $HOME/.tool-versions)" = "" ] + unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME } @test "global should overwrite contents of ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" { - ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions" + export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions" echo 'dummy 1.0.0' >> "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" - run global_command "dummy" "1.1.0" + run asdf global "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] [ "$(cat $HOME/.tool-versions)" = "" ] + unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME } @test "local should preserve symlinks when setting versions" { mkdir other-dir touch other-dir/.tool-versions ln -s other-dir/.tool-versions .tool-versions - run local_command "dummy" "1.1.0" + run asdf local "dummy" "1.1.0" [ "$status" -eq 0 ] [ -L .tool-versions ] [ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ] @@ -199,8 +201,8 @@ teardown() { mkdir other-dir touch other-dir/.tool-versions ln -s other-dir/.tool-versions .tool-versions - run local_command "dummy" "1.1.0" - run local_command "dummy" "1.1.0" + run asdf local "dummy" "1.1.0" + run asdf local "dummy" "1.1.0" [ "$status" -eq 0 ] [ -L .tool-versions ] [ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ] @@ -211,7 +213,7 @@ teardown() { touch other-dir/.tool-versions ln -s other-dir/.tool-versions $HOME/.tool-versions - run global_command "dummy" "1.1.0" + run asdf global "dummy" "1.1.0" [ "$status" -eq 0 ] [ -L $HOME/.tool-versions ] [ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ] @@ -222,8 +224,8 @@ teardown() { touch other-dir/.tool-versions ln -s other-dir/.tool-versions $HOME/.tool-versions - run global_command "dummy" "1.1.0" - run global_command "dummy" "1.1.0" + run asdf global "dummy" "1.1.0" + run asdf global "dummy" "1.1.0" [ "$status" -eq 0 ] [ -L $HOME/.tool-versions ] [ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ] diff --git a/test/where_command.bats b/test/where_command.bats index 006584fb..478387f2 100644 --- a/test/where_command.bats +++ b/test/where_command.bats @@ -17,13 +17,13 @@ function teardown() { } @test "where shows install location of selected version" { - run where_command 'dummy' '1.0' + run asdf where 'dummy' '1.0' [ "$status" -eq 0 ] [ "$output" = "$ASDF_DIR/installs/dummy/1.0" ] } @test "where understands versions installed by ref" { - run where_command 'dummy' 'ref:master' + run asdf where 'dummy' 'ref:master' [ "$status" -eq 0 ] [ "$output" = "$ASDF_DIR/installs/dummy/ref-master" ] } @@ -31,26 +31,26 @@ function teardown() { @test "where shows install location of current version if no version specified" { echo 'dummy 2.1' >> $HOME/.tool-versions - run where_command 'dummy' + run asdf where 'dummy' [ "$status" -eq 0 ] [ "$output" = "$ASDF_DIR/installs/dummy/2.1" ] } @test "where should error when the plugin doesn't exist" { - run where_command "foobar" + run asdf where "foobar" [ "$status" -eq 1 ] [ "$output" = "No such plugin: foobar" ] } @test "where should error when version is not installed" { - run where_command 'dummy' '1.6' + run asdf where 'dummy' '1.6' [ "$status" -eq 1 ] [ "$output" = "Version not installed" ] } @test "where should error when no current version selected and version not specified" { - run where_command 'dummy' + run asdf where 'dummy' local expected expected="No version set for dummy; please run \`asdf dummy \`" diff --git a/test/which_command.bats b/test/which_command.bats index d4cc42ed..e93d9907 100644 --- a/test/which_command.bats +++ b/test/which_command.bats @@ -8,7 +8,7 @@ load test_helpers setup() { setup_asdf_dir install_dummy_plugin - run install_command dummy 1.0 + run asdf install dummy 1.0 PROJECT_DIR=$HOME/project mkdir $PROJECT_DIR @@ -22,7 +22,7 @@ teardown() { @test "which should show dummy 1.0 main binary" { cd $PROJECT_DIR - run which_command "dummy" + run asdf which "dummy" [ "$status" -eq 0 ] [ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/dummy" ] } @@ -30,7 +30,7 @@ teardown() { @test "which should show dummy 1.0 other binary" { cd $PROJECT_DIR - run which_command "other_bin" + run asdf which "other_bin" [ "$status" -eq 0 ] [ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/subdir/other_bin" ] } @@ -39,7 +39,7 @@ teardown() { echo 'dummy system 1.0' > $PROJECT_DIR/.tool-versions cd $PROJECT_DIR - run which_command "other_bin" + run asdf which "other_bin" [ "$status" -eq 0 ] [ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/subdir/other_bin" ] } @@ -47,7 +47,7 @@ teardown() { @test "which should inform when no binary is found" { cd $PROJECT_DIR - run which_command "bazbat" + run asdf which "bazbat" [ "$status" -eq 1 ] [ "$output" = "No executable binary found for bazbat" ] } @@ -56,7 +56,7 @@ teardown() { cd $PROJECT_DIR install_dummy_exec_path_script "dummy" - run which_command "dummy" + run asdf which "dummy" [ "$status" -eq 0 ] [ "$output" = "$ASDF_DIR/installs/dummy/1.0/bin/custom/dummy" ] }