mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Merge pull request #337 from Stratus3D/symlink-tests
Symlink fix and tests
This commit is contained in:
commit
9a525d6bca
@ -17,6 +17,11 @@ version_command() {
|
||||
file="$(pwd)/.tool-versions"
|
||||
fi
|
||||
|
||||
if [ -L "$file" ]; then
|
||||
# Resolve file path if symlink
|
||||
file="$(resolve_symlink "$file")"
|
||||
fi
|
||||
|
||||
check_if_plugin_exists "$plugin"
|
||||
|
||||
local version
|
||||
@ -24,6 +29,7 @@ version_command() {
|
||||
check_if_version_exists "$plugin" "$version"
|
||||
done
|
||||
|
||||
|
||||
if [ -f "$file" ] && grep "^$plugin " "$file" > /dev/null; then
|
||||
sed -i.bak -e "s/^$plugin .*$/$plugin ${versions[*]}/" "$file"
|
||||
rm "$file".bak
|
||||
|
10
lib/utils.sh
10
lib/utils.sh
@ -354,3 +354,13 @@ find_tool_versions() {
|
||||
search_path=$(dirname "$search_path")
|
||||
done
|
||||
}
|
||||
|
||||
resolve_symlink() {
|
||||
local symlink
|
||||
symlink="$1"
|
||||
|
||||
# This seems to be the only cross-platform way to resolve symlink paths to
|
||||
# the real file path.
|
||||
# shellcheck disable=SC2012
|
||||
ls -l "$symlink" | sed -e 's|.*-> \(.*\)|\1|'
|
||||
}
|
||||
|
@ -2,7 +2,14 @@
|
||||
|
||||
load test_helpers
|
||||
|
||||
banned_commands=(realpath eval)
|
||||
banned_commands=(
|
||||
realpath
|
||||
# readlink on OSX behaves differently from readlink on other Unix systems
|
||||
readlink
|
||||
# It's best to avoid eval as it makes it easier to accidentally execute
|
||||
# arbitrary strings
|
||||
eval
|
||||
)
|
||||
|
||||
setup() {
|
||||
setup_asdf_dir
|
||||
|
@ -139,3 +139,47 @@ teardown() {
|
||||
[ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ]
|
||||
[ "$(cat $HOME/.tool-versions)" = "" ]
|
||||
}
|
||||
|
||||
@test "local should preserve symlinks when setting versions" {
|
||||
mkdir other-dir
|
||||
touch other-dir/.tool-versions
|
||||
ln -s other-dir/.tool-versions .tool-versions
|
||||
run local_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -L .tool-versions ]
|
||||
[ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
@test "local should preserve symlinks when updating versions" {
|
||||
mkdir other-dir
|
||||
touch other-dir/.tool-versions
|
||||
ln -s other-dir/.tool-versions .tool-versions
|
||||
run local_command "dummy" "1.1.0"
|
||||
run local_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -L .tool-versions ]
|
||||
[ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
@test "global should preserve symlinks when setting versions" {
|
||||
mkdir other-dir
|
||||
touch other-dir/.tool-versions
|
||||
ln -s other-dir/.tool-versions $HOME/.tool-versions
|
||||
|
||||
run global_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -L $HOME/.tool-versions ]
|
||||
[ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
||||
@test "global should preserve symlinks when updating versions" {
|
||||
mkdir other-dir
|
||||
touch other-dir/.tool-versions
|
||||
ln -s other-dir/.tool-versions $HOME/.tool-versions
|
||||
|
||||
run global_command "dummy" "1.1.0"
|
||||
run global_command "dummy" "1.1.0"
|
||||
[ "$status" -eq 0 ]
|
||||
[ -L $HOME/.tool-versions ]
|
||||
[ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user