diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index 04ecd53c1..ab9e57762 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -28,7 +28,7 @@ latest_command() { else # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) versions=$(asdf list-all "$plugin_name" "$query" | - grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | + grep -ivE "(^Available versions:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | sed 's/^[[:space:]]\+//' | tail -1) if [ -z "${versions}" ]; then @@ -59,7 +59,7 @@ latest_all() { else # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) version=$(asdf list-all "$plugin_name" | - grep -vE "(^Available version:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | + grep -ivE "(^Available version:|-src|-dev|-latest|-stm|[-\\.]rc|-alpha|-beta|[-\\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" | sed 's/^[[:space:]]\+//' | tail -1) if [ -z "${version}" ]; then diff --git a/test/fixtures/dummy_legacy_plugin/bin/list-all b/test/fixtures/dummy_legacy_plugin/bin/list-all index 1b9e8dd9e..01fe133c2 100755 --- a/test/fixtures/dummy_legacy_plugin/bin/list-all +++ b/test/fixtures/dummy_legacy_plugin/bin/list-all @@ -1,4 +1,4 @@ #!/usr/bin/env bash -versions_list=(1.0.0 1.1.0 2.0.0) +versions_list=(1.0.0 1.1.0 2.0.0 3.0.0-alpha1 3.0.0-beta2 4.0.0 4.1.0-pre 5.0.0-Alpha1 5.1.0 5.2.0-Alpha2) echo "${versions_list[@]}" diff --git a/test/fixtures/dummy_plugin/bin/list-all b/test/fixtures/dummy_plugin/bin/list-all index efec9526d..39668af49 100755 --- a/test/fixtures/dummy_plugin/bin/list-all +++ b/test/fixtures/dummy_plugin/bin/list-all @@ -1,6 +1,6 @@ #!/usr/bin/env bash -versions_list=(1.0.0 1.1.0 2.0.0) +versions_list=(1.0.0 1.1.0 2.0.0 3.0.0-alpha1 3.0.0-beta2 4.0.0 4.1.0-pre 5.0.0-Alpha1 5.1.0 5.2.0-Alpha2) echo "${versions_list[@]}" # Sending message to STD error to ensure that it is ignored echo "ignore this error" >&2 diff --git a/test/latest_command.bats b/test/latest_command.bats index b72857f69..8e01ce809 100644 --- a/test/latest_command.bats +++ b/test/latest_command.bats @@ -40,7 +40,7 @@ teardown() { run asdf latest legacy-dummy echo "status: $status" echo "output: $output" - [ "$(echo "2.0.0")" == "$output" ] + [ "$(echo "5.1.0")" == "$output" ] [ "$status" -eq 0 ] } @@ -52,11 +52,35 @@ teardown() { [ "$status" -eq 0 ] } -@test "[latest_command - dummy_legacy_plugin] an invalid version should return an error" { +@test "[latest_command - dummy_legacy_plugin] No stable version should return an error" { run asdf latest legacy-dummy 3 echo "status: $status" echo "output: $output" - [ "$(echo "No compatible versions available (legacy-dummy 3)")" == "$output" ] + [ -z "$output" ] + [ "$status" -eq 1 ] +} + +@test "[latest_command - dummy_legacy_plugin] do not show latest unstable version that matches the given string" { + run asdf latest legacy-dummy 4 + echo "status: $status" + echo "output: $output" + [ "$(echo "4.0.0")" == "$output" ] + [ "$status" -eq 0 ] +} + +@test "[latest_command - dummy_legacy_plugin] do not show latest unstable version with capital characters that matches the given string" { + run asdf latest legacy-dummy 5 + echo "status: $status" + echo "output: $output" + [ "$(echo "5.1.0")" == "$output" ] + [ "$status" -eq 0 ] +} + +@test "[latest_command - dummy_legacy_plugin] an invalid version should return an error" { + run asdf latest legacy-dummy 6 + echo "status: $status" + echo "output: $output" + [ "$(echo "No compatible versions available (legacy-dummy 6)")" == "$output" ] [ "$status" -eq 1 ] } @@ -65,15 +89,15 @@ teardown() { ################################ @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 install legacy-dummy 4.0.0 run asdf latest --all echo "output $output" - [ "$(echo -e "dummy\t2.0.0\tinstalled\nlegacy-dummy\t2.0.0\tmissing\n")" == "$output" ] + [ "$(echo -e "dummy\t2.0.0\tinstalled\nlegacy-dummy\t5.1.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" ] + [ "$(echo -e "dummy\t2.0.0\tmissing\nlegacy-dummy\t5.1.0\tmissing\n")" == "$output" ] [ "$status" -eq 0 ] }