From aafe1e5304c2d2a026831976c18faa6fb48d25bc Mon Sep 17 00:00:00 2001 From: Alberto de Murga Date: Thu, 9 Dec 2021 06:49:24 +0100 Subject: [PATCH] fix: latest --all correctly report plugins as missing (#1118) --- help.txt | 2 ++ lib/commands/command-latest.bash | 2 +- test/latest_command.bats | 11 ++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/help.txt b/help.txt index 7162a6cb2..6caf310b0 100644 --- a/help.txt +++ b/help.txt @@ -40,6 +40,8 @@ asdf global latest[:] Set the package local version to the asdf shell Set the package version to `ASDF_${LANG}_VERSION` in the current shell asdf latest [] Show latest stable version of a package +asdf latest --all Show latest stable version of all the + packages and if they are installed asdf list [version] List installed versions of a package and optionally filter the versions asdf list all [] List all versions of a package and diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index d086b5149..04ecd53c1 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -73,7 +73,7 @@ latest_all() { local installed_versions installed_versions=$(list_installed_versions "$plugin_name") - if ! printf '%s\n' "$installed_versions" | grep -q "^$version\$"; then + if [ -n "$installed_versions" ] && printf '%s\n' "$installed_versions" | grep -q "^$version\$"; then installed_status="installed" fi printf "%s\\t%s\\t%s\\n" "$plugin_name" "$version" "$installed_status" diff --git a/test/latest_command.bats b/test/latest_command.bats index ea55a7dfb..b72857f69 100644 --- a/test/latest_command.bats +++ b/test/latest_command.bats @@ -64,7 +64,16 @@ teardown() { #### latest --all #### ################################ @test "[latest_command - all plugins] shows the latest stable version of all plugins" { + run asdf install dummy 2.0.0 + run asdf install legacy-dummy 1.0.0 run asdf latest --all - [ "$(echo -e "dummy\t2.0.0\tinstalled\nlegacy-dummy\t2.0.0\tinstalled\n")" == "$output" ] + echo "output $output" + [ "$(echo -e "dummy\t2.0.0\tinstalled\nlegacy-dummy\t2.0.0\tmissing\n")" == "$output" ] + [ "$status" -eq 0 ] +} + +@test "[latest_command - all plugins] not installed plugin should return missing" { + run asdf latest --all + [ "$(echo -e "dummy\t2.0.0\tmissing\nlegacy-dummy\t2.0.0\tmissing\n")" == "$output" ] [ "$status" -eq 0 ] }