mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Start adding tests for system version
This commit is contained in:
parent
f5152f255a
commit
23f92987c0
46
lib/utils.sh
46
lib/utils.sh
@ -46,7 +46,7 @@ list_installed_versions() {
|
||||
check_if_plugin_exists() {
|
||||
# Check if we have a non-empty argument
|
||||
if [ -z "${1+set}" ]; then
|
||||
display_error "No such plugin"
|
||||
display_error "No plugin given"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -57,7 +57,7 @@ check_if_plugin_exists() {
|
||||
}
|
||||
|
||||
check_if_version_exists() {
|
||||
local plugin=$1
|
||||
local plugin_name=$1
|
||||
local version=$2
|
||||
local version_dir=$(asdf_dir)/installs/$plugin/$version
|
||||
|
||||
@ -66,8 +66,10 @@ check_if_version_exists() {
|
||||
version_dir=$(echo $version | cut -d: -f 2)
|
||||
fi
|
||||
|
||||
check_if_plugin_exists $plugin_name
|
||||
|
||||
if [ $version != "system" -a ! -d $version_dir ]; then
|
||||
display_error "version $version is not installed for $plugin"
|
||||
display_error "version $version is not installed for $plugin_name"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@ -173,6 +175,8 @@ get_executable_path() {
|
||||
local version=$2
|
||||
local executable_path=$3
|
||||
|
||||
check_if_version_exists $plugin_name $version
|
||||
|
||||
if [ $version = "system" ]; then
|
||||
path=$(echo $PATH | sed -e "s|$(asdf_dir)/shims:\?||g")
|
||||
cmd=$(basename $executable_path)
|
||||
@ -226,29 +230,29 @@ get_preset_version_for() {
|
||||
}
|
||||
|
||||
get_asdf_config_value_from_file() {
|
||||
local config_path=$1
|
||||
local key=$2
|
||||
local config_path=$1
|
||||
local key=$2
|
||||
|
||||
if [ ! -f $config_path ]; then
|
||||
return 0
|
||||
fi
|
||||
if [ ! -f $config_path ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local result=$(grep -E "^\s*$key\s*=" $config_path | awk -F '=' '{ gsub(/ /, "", $2); print $2 }')
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
fi
|
||||
local result=$(grep -E "^\s*$key\s*=" $config_path | awk -F '=' '{ gsub(/ /, "", $2); print $2 }')
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
fi
|
||||
}
|
||||
|
||||
get_asdf_config_value() {
|
||||
local key=$1
|
||||
local config_path=${AZDF_CONFIG_FILE:-"$HOME/.asdfrc"}
|
||||
local default_config_path=${AZDF_CONFIG_DEFAULT_FILE:-"$(asdf_dir)/defaults"}
|
||||
local key=$1
|
||||
local config_path=${AZDF_CONFIG_FILE:-"$HOME/.asdfrc"}
|
||||
local default_config_path=${AZDF_CONFIG_DEFAULT_FILE:-"$(asdf_dir)/defaults"}
|
||||
|
||||
local result=$(get_asdf_config_value_from_file $config_path $key)
|
||||
local result=$(get_asdf_config_value_from_file $config_path $key)
|
||||
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
else
|
||||
get_asdf_config_value_from_file $default_config_path $key
|
||||
fi
|
||||
if [ -n "$result" ]; then
|
||||
echo $result
|
||||
else
|
||||
get_asdf_config_value_from_file $default_config_path $key
|
||||
fi
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ setup_asdf_dir() {
|
||||
ASDF_DIR=$HOME/.asdf
|
||||
mkdir -p $ASDF_DIR/plugins
|
||||
mkdir -p $ASDF_DIR/installs
|
||||
mkdir -p $ASDF_DIR/shims
|
||||
PATH=$ASDF_DIR/shims:$PATH
|
||||
}
|
||||
|
||||
install_dummy_plugin() {
|
||||
|
@ -34,10 +34,17 @@ teardown() {
|
||||
[ "$output" = "" ]
|
||||
}
|
||||
|
||||
@test "check_if_version_exists should be noop if version is system" {
|
||||
mkdir -p $ASDF_DIR/plugins/foo
|
||||
run check_if_version_exists "foo" "system"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "" ]
|
||||
}
|
||||
|
||||
@test "check_if_plugin_exists should exit with 1 when plugin is empty string" {
|
||||
run check_if_plugin_exists
|
||||
[ "$status" -eq 1 ]
|
||||
[ "$output" = "No such plugin" ]
|
||||
[ "$output" = "No plugin given" ]
|
||||
}
|
||||
|
||||
@test "check_if_plugin_exists should be noop if plugin exists" {
|
||||
@ -139,3 +146,34 @@ teardown() {
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "path:/some/place with spaces" ]
|
||||
}
|
||||
|
||||
@test "get_executable_path for system version should return system path" {
|
||||
mkdir -p $ASDF_DIR/plugins/foo
|
||||
run get_executable_path "foo" "system" "ls"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = $(which ls) ]
|
||||
}
|
||||
|
||||
@test "get_executable_path for system version should not use asdf shims" {
|
||||
mkdir -p $ASDF_DIR/plugins/foo
|
||||
touch $ASDF_DIR/shims/dummy_executable
|
||||
chmod +x $ASDF_DIR/shims/dummy_executable
|
||||
|
||||
run which dummy_executable
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run get_executable_path "foo" "system" "dummy_executable"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "get_executable_path for non system version should return relative path from plugin" {
|
||||
mkdir -p $ASDF_DIR/plugins/foo
|
||||
mkdir -p $ASDF_DIR/installs/foo/1.0.0/bin
|
||||
executable_path=$ASDF_DIR/installs/foo/1.0.0/bin/dummy
|
||||
touch $executable_path
|
||||
chmod +x $executable_path
|
||||
|
||||
run get_executable_path "foo" "1.0.0" "bin/dummy"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "$executable_path" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user