Merge pull request #401 from asdf-vm/fix-current-with-multiple-versions

Fix current behavior when multiple versions of a plugin are set
This commit is contained in:
Daniel Perez 2018-11-10 11:41:22 +00:00 committed by GitHub
commit dab04107ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -7,19 +7,22 @@ plugin_current_command() {
search_path=$(pwd) search_path=$(pwd)
local version_and_path local version_and_path
version_and_path=$(find_version "$plugin_name" "$search_path") version_and_path=$(find_version "$plugin_name" "$search_path")
local version local full_version
version=$(cut -d '|' -f 1 <<< "$version_and_path"); full_version=$(cut -d '|' -f 1 <<< "$version_and_path");
local version_file_path local version_file_path
version_file_path=$(cut -d '|' -f 2 <<< "$version_and_path"); version_file_path=$(cut -d '|' -f 2 <<< "$version_and_path");
check_if_version_exists "$plugin_name" "$version" IFS=' ' read -r -a versions <<< "$full_version"
for version in $versions; do
check_if_version_exists "$plugin_name" "$version"
done
check_for_deprecated_plugin "$plugin_name" check_for_deprecated_plugin "$plugin_name"
if [ -z "$version" ]; then if [ -z "$full_version" ]; then
printf "%s\\n" "$(display_no_version_set "$plugin_name")" printf "%s\\n" "$(display_no_version_set "$plugin_name")"
exit 126 exit 126
else else
printf "%-8s (set by %s)\\n" "$version" "$version_file_path" printf "%-8s (set by %s)\\n" "$full_version" "$version_file_path"
fi fi
} }

View File

@ -38,6 +38,16 @@ teardown() {
[ "$output" = "nightly-2000-01-01 (set by $PROJECT_DIR/.tool-versions)" ] [ "$output" = "nightly-2000-01-01 (set by $PROJECT_DIR/.tool-versions)" ]
} }
@test "current should handle multiple versions" {
cd $PROJECT_DIR
echo "dummy 1.2.0 1.1.0" >> $PROJECT_DIR/.tool-versions
run current_command "dummy"
[ "$status" -eq 0 ]
[ "$output" = "1.2.0 1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
}
@test "current should derive from the legacy file if enabled" { @test "current should derive from the legacy file if enabled" {
cd $PROJECT_DIR cd $PROJECT_DIR
echo 'legacy_version_file = yes' > $HOME/.asdfrc echo 'legacy_version_file = yes' > $HOME/.asdfrc