mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 09:38:16 -07:00
fix: incorrect version output in asdf current (#746)
This commit is contained in:
parent
77a748d70a
commit
e9c149ea21
@ -1,7 +1,9 @@
|
|||||||
# -*- sh -*-
|
# -*- sh -*-
|
||||||
|
|
||||||
|
# shellcheck disable=SC2059
|
||||||
plugin_current_command() {
|
plugin_current_command() {
|
||||||
local plugin_name=$1
|
local plugin_name=$1
|
||||||
|
local terminal_format=$2
|
||||||
|
|
||||||
check_if_plugin_exists "$plugin_name"
|
check_if_plugin_exists "$plugin_name"
|
||||||
|
|
||||||
@ -13,30 +15,48 @@ plugin_current_command() {
|
|||||||
full_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")
|
||||||
|
local version_not_installed
|
||||||
|
local description=""
|
||||||
|
|
||||||
IFS=' ' read -r -a versions <<<"$full_version"
|
IFS=' ' read -r -a versions <<<"$full_version"
|
||||||
for version in "${versions[@]}"; do
|
for version in "${versions[@]}"; do
|
||||||
check_if_version_exists "$plugin_name" "$version"
|
if ! (check_if_version_exists "$plugin_name" "$version"); then
|
||||||
|
version_not_installed="$version"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
check_for_deprecated_plugin "$plugin_name"
|
check_for_deprecated_plugin "$plugin_name"
|
||||||
|
|
||||||
if [ -z "$full_version" ]; then
|
if [ -n "$version_not_installed" ]; then
|
||||||
printf "%s\\n" "$(display_no_version_set "$plugin_name")"
|
description="Not installed. Run \"asdf install $plugin $version\""
|
||||||
exit 126
|
printf "$terminal_format" "$plugin" "$version" "$description" 1>&2
|
||||||
|
return 1
|
||||||
|
elif [ -z "$full_version" ]; then
|
||||||
|
description="No version set. Run \"asdf <global|shell|local> $plugin <version>\""
|
||||||
|
printf "$terminal_format" "$plugin" "______" "$description" 1>&2
|
||||||
|
return 126
|
||||||
else
|
else
|
||||||
printf "%-8s (set by %s)\\n" "$full_version" "$version_file_path"
|
description="$version_file_path"
|
||||||
|
printf "$terminal_format" "$plugin" "$full_version" "$description"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2059
|
||||||
current_command() {
|
current_command() {
|
||||||
|
local terminal_format="%-15s %-15s %-10s\\n"
|
||||||
|
local exit_status=0
|
||||||
|
|
||||||
|
printf "$terminal_format" "PLUGIN" "VERSION" "SET BY CONFIG"
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
for plugin in $(asdf plugin list); do
|
for plugin in $(asdf plugin list); do
|
||||||
printf "%-15s%s\\n" "$plugin" "$(plugin_current_command "$plugin")" >&2
|
plugin_current_command "$plugin" "$terminal_format"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
local plugin=$1
|
local plugin=$1
|
||||||
plugin_current_command "$plugin"
|
plugin_current_command "$plugin" "$terminal_format"
|
||||||
|
exit_status="$?"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
exit "$exit_status"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Warn if the plugin isn't using the updated legacy file api.
|
# Warn if the plugin isn't using the updated legacy file api.
|
||||||
|
@ -30,6 +30,7 @@ shell_command() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
if ! (check_if_version_exists "$plugin" "$version"); then
|
if ! (check_if_version_exists "$plugin" "$version"); then
|
||||||
|
version_not_installed_text "$plugin" "$version" 1>&2
|
||||||
echo 'false'
|
echo 'false'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -34,7 +34,10 @@ version_command() {
|
|||||||
|
|
||||||
local version
|
local version
|
||||||
for version in "${versions[@]}"; do
|
for version in "${versions[@]}"; do
|
||||||
check_if_version_exists "$plugin_name" "$version"
|
if ! (check_if_version_exists "$plugin_name" "$version"); then
|
||||||
|
version_not_installed_text "$plugin_name" "$version" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -f "$file" ] && grep "^$plugin_name " "$file" >/dev/null; then
|
if [ -f "$file" ] && grep "^$plugin_name " "$file" >/dev/null; then
|
||||||
|
@ -127,11 +127,17 @@ check_if_version_exists() {
|
|||||||
install_path=$(find_install_path "$plugin_name" "$version")
|
install_path=$(find_install_path "$plugin_name" "$version")
|
||||||
|
|
||||||
if [ "$version" != "system" ] && [ ! -d "$install_path" ]; then
|
if [ "$version" != "system" ] && [ ! -d "$install_path" ]; then
|
||||||
display_error "version $version is not installed for $plugin_name"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version_not_installed_text() {
|
||||||
|
local plugin_name=$1
|
||||||
|
local version=$2
|
||||||
|
|
||||||
|
printf "version %s is not installed for %s\\n" "$version" "$plugin_name"
|
||||||
|
}
|
||||||
|
|
||||||
get_plugin_path() {
|
get_plugin_path() {
|
||||||
if test -n "$1"; then
|
if test -n "$1"; then
|
||||||
echo "$(asdf_data_dir)/plugins/$1"
|
echo "$(asdf_data_dir)/plugins/$1"
|
||||||
|
@ -20,28 +20,34 @@ teardown() {
|
|||||||
@test "current should derive from the current .tool-versions" {
|
@test "current should derive from the current .tool-versions" {
|
||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
|
echo 'dummy 1.1.0' >> $PROJECT_DIR/.tool-versions
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
dummy 1.1.0 $PROJECT_DIR/.tool-versions"
|
||||||
|
|
||||||
run asdf current "dummy"
|
run asdf current "dummy"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "current should handle long version name" {
|
@test "current should handle long version name" {
|
||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
echo "dummy nightly-2000-01-01" >> $PROJECT_DIR/.tool-versions
|
echo "dummy nightly-2000-01-01" >> $PROJECT_DIR/.tool-versions
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
dummy nightly-2000-01-01 $PROJECT_DIR/.tool-versions"
|
||||||
|
|
||||||
run asdf current "dummy"
|
run asdf current "dummy"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "nightly-2000-01-01 (set by $PROJECT_DIR/.tool-versions)" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "current should handle multiple versions" {
|
@test "current should handle multiple versions" {
|
||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
echo "dummy 1.2.0 1.1.0" >> $PROJECT_DIR/.tool-versions
|
echo "dummy 1.2.0 1.1.0" >> $PROJECT_DIR/.tool-versions
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
dummy 1.2.0 1.1.0 $PROJECT_DIR/.tool-versions"
|
||||||
|
|
||||||
run asdf current "dummy"
|
run asdf current "dummy"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "1.2.0 1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -49,32 +55,43 @@ teardown() {
|
|||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
echo 'legacy_version_file = yes' > $HOME/.asdfrc
|
echo 'legacy_version_file = yes' > $HOME/.asdfrc
|
||||||
echo '1.2.0' >> $PROJECT_DIR/.dummy-version
|
echo '1.2.0' >> $PROJECT_DIR/.dummy-version
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
dummy 1.2.0 $PROJECT_DIR/.dummy-version"
|
||||||
|
|
||||||
run asdf current "dummy"
|
run asdf current "dummy"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "1.2.0 (set by $PROJECT_DIR/.dummy-version)" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# TODO: Need to fix plugin error as well
|
||||||
@test "current should error when the plugin doesn't exist" {
|
@test "current should error when the plugin doesn't exist" {
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
No such plugin: foobar"
|
||||||
|
|
||||||
run asdf current "foobar"
|
run asdf current "foobar"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[ "$output" = "No such plugin: foobar" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "current should error when no version is set" {
|
@test "current should error when no version is set" {
|
||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
dummy ______ No version set. Run \"asdf <global|shell|local> dummy <version>\""
|
||||||
|
|
||||||
run asdf current "dummy"
|
run asdf current "dummy"
|
||||||
[ "$status" -eq 126 ]
|
[ "$status" -eq 126 ]
|
||||||
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "current should error when a version is set that isn't installed" {
|
@test "current should error when a version is set that isn't installed" {
|
||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
echo 'dummy 9.9.9' >> $PROJECT_DIR/.tool-versions
|
echo 'dummy 9.9.9' >> $PROJECT_DIR/.tool-versions
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
dummy 9.9.9 Not installed. Run \"asdf install dummy 9.9.9\""
|
||||||
|
|
||||||
run asdf current "dummy"
|
run asdf current "dummy"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[ "$output" = "version 9.9.9 is not installed for dummy" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "should output all plugins when no plugin passed" {
|
@test "should output all plugins when no plugin passed" {
|
||||||
@ -92,9 +109,10 @@ teardown() {
|
|||||||
echo 'foobar 1.0.0' >> $PROJECT_DIR/.tool-versions
|
echo 'foobar 1.0.0' >> $PROJECT_DIR/.tool-versions
|
||||||
|
|
||||||
run asdf current
|
run asdf current
|
||||||
expected="baz No version set for baz; please run \`asdf <global | shell | local> baz <version>\`
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
dummy 1.1.0 (set by $PROJECT_DIR/.tool-versions)
|
baz ______ No version set. Run \"asdf <global|shell|local> baz <version>\"
|
||||||
foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)"
|
dummy 1.1.0 $PROJECT_DIR/.tool-versions
|
||||||
|
foobar 1.0.0 $PROJECT_DIR/.tool-versions"
|
||||||
|
|
||||||
[ "$expected" = "$output" ]
|
[ "$expected" = "$output" ]
|
||||||
}
|
}
|
||||||
@ -117,17 +135,21 @@ foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)"
|
|||||||
|
|
||||||
@test "with no plugins prints an error" {
|
@test "with no plugins prints an error" {
|
||||||
clean_asdf_dir
|
clean_asdf_dir
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
Oohes nooes ~! No plugins installed"
|
||||||
|
|
||||||
run asdf current
|
run asdf current
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
echo "$output" | grep "Oohes nooes ~! No plugins installed"
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "current should handle comments" {
|
@test "current should handle comments" {
|
||||||
cd $PROJECT_DIR
|
cd $PROJECT_DIR
|
||||||
echo "dummy 1.2.0 # this is a comment" >> $PROJECT_DIR/.tool-versions
|
echo "dummy 1.2.0 # this is a comment" >> $PROJECT_DIR/.tool-versions
|
||||||
|
expected="PLUGIN VERSION SET BY CONFIG
|
||||||
|
dummy 1.2.0 $PROJECT_DIR/.tool-versions"
|
||||||
|
|
||||||
run asdf current "dummy"
|
run asdf current "dummy"
|
||||||
echo "$output"
|
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "1.2.0 (set by $PROJECT_DIR/.tool-versions)" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,11 @@ teardown() {
|
|||||||
@test "check_if_version_exists should exit with 1 if version does not exist" {
|
@test "check_if_version_exists should exit with 1 if version does not exist" {
|
||||||
run check_if_version_exists "dummy" "1.0.0"
|
run check_if_version_exists "dummy" "1.0.0"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "version_not_installed_text is correct" {
|
||||||
|
run version_not_installed_text "dummy" "1.0.0"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "version 1.0.0 is not installed for dummy" ]
|
[ "$output" = "version 1.0.0 is not installed for dummy" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,28 +247,37 @@ teardown() {
|
|||||||
|
|
||||||
@test "shell wrapper function should return an error for missing plugins" {
|
@test "shell wrapper function should return an error for missing plugins" {
|
||||||
source $(dirname "$BATS_TEST_DIRNAME")/asdf.sh
|
source $(dirname "$BATS_TEST_DIRNAME")/asdf.sh
|
||||||
|
expected="No such plugin: nonexistent
|
||||||
|
version 1.0.0 is not installed for nonexistent"
|
||||||
|
|
||||||
run asdf shell "nonexistent" "1.0.0"
|
run asdf shell "nonexistent" "1.0.0"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[ "$output" = "No such plugin: nonexistent" ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "shell should emit an error when wrapper function is not loaded" {
|
@test "shell should emit an error when wrapper function is not loaded" {
|
||||||
run asdf shell "dummy" "1.1.0"
|
run asdf shell "dummy" "1.1.0"
|
||||||
echo $output
|
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[ "$output" = "Shell integration is not enabled. Please ensure you source asdf in your shell setup." ]
|
[ "$output" = "Shell integration is not enabled. Please ensure you source asdf in your shell setup." ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "export-shell-version should emit an error when plugin does not exist" {
|
@test "export-shell-version should emit an error when plugin does not exist" {
|
||||||
|
expected="No such plugin: nonexistent
|
||||||
|
version 1.0.0 is not installed for nonexistent
|
||||||
|
false"
|
||||||
|
|
||||||
run asdf export-shell-version sh "nonexistent" "1.0.0"
|
run asdf export-shell-version sh "nonexistent" "1.0.0"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[ "$output" = $'No such plugin: nonexistent\nfalse' ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "export-shell-version should emit an error when version does not exist" {
|
@test "export-shell-version should emit an error when version does not exist" {
|
||||||
|
expected="version nonexistent is not installed for dummy
|
||||||
|
false"
|
||||||
|
|
||||||
run asdf export-shell-version sh "dummy" "nonexistent"
|
run asdf export-shell-version sh "dummy" "nonexistent"
|
||||||
[ "$status" -eq 1 ]
|
[ "$status" -eq 1 ]
|
||||||
[ "$output" = $'version nonexistent is not installed for dummy\nfalse' ]
|
[ "$output" = "$expected" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "export-shell-version should export version if it exists" {
|
@test "export-shell-version should export version if it exists" {
|
||||||
|
Loading…
Reference in New Issue
Block a user