From 4b40e8077644a811aa244ea6bc7f4a87606325b5 Mon Sep 17 00:00:00 2001 From: Victor Hugo Borja Date: Wed, 23 Jan 2019 22:18:18 -0600 Subject: [PATCH] Test that command being executed can see other tools shims on path --- lib/utils.sh | 11 ++++++----- test/shim_env_command.bats | 4 ++-- test/shim_exec.bats | 31 ++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/utils.sh b/lib/utils.sh index 010c09f4..e1ae8a44 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -492,10 +492,6 @@ with_plugin_env() { # create a new subshell to keep env ( - # first remove asdf shims from the path - PATH=$(echo "$PATH" | sed -e "s|$(asdf_data_dir)/shims||g; s|::|:|g") - export PATH - if [ "$version" = "system" ]; then # execute as is for system "$callback" @@ -638,7 +634,12 @@ with_shim_executable() { plugin_path=$(get_plugin_path "$plugin_name") run_within_env() { - executable_path=$(command -v "$shim_name") + local path=$PATH + if [ "system" == "$full_version" ]; then + path=$(echo "$PATH" | sed -e "s|$(asdf_data_dir)/shims||g; s|::|:|g") + fi + + executable_path=$(PATH=$path command -v "$shim_name") if [ -x "${plugin_path}/bin/exec-path" ]; then install_path=$(find_install_path "$plugin_name" "$full_version") diff --git a/test/shim_env_command.bats b/test/shim_env_command.bats index 6879185e..e638dc15 100644 --- a/test/shim_env_command.bats +++ b/test/shim_env_command.bats @@ -63,6 +63,6 @@ teardown() { [ "$status" -eq 1 ] run asdf env dummy which dummy - [ "$output" == "" ] - [ "$status" -eq 1 ] + [ "$output" == "$ASDF_DIR/shims/dummy" ] + [ "$status" -eq 0 ] } diff --git a/test/shim_exec.bats b/test/shim_exec.bats index 3b678904..1fbdd27c 100644 --- a/test/shim_exec.bats +++ b/test/shim_exec.bats @@ -251,6 +251,34 @@ teardown() { [ "$output" == "$ASDF_DIR/installs/dummy/2.0/bin/dummy" ] } +@test "shim exec should be able to find other shims in path" { + cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/gummy + + echo "dummy 2.0" > $PROJECT_DIR/.tool-versions + echo "gummy 2.0" >> $PROJECT_DIR/.tool-versions + + run asdf install + + mkdir $ASDF_DIR/plugins/{dummy,gummy}/shims + + echo 'which dummy' > $ASDF_DIR/plugins/dummy/shims/foo + chmod +x $ASDF_DIR/plugins/dummy/shims/foo + + echo 'which gummy' > $ASDF_DIR/plugins/dummy/shims/bar + chmod +x $ASDF_DIR/plugins/dummy/shims/bar + + touch $ASDF_DIR/plugins/gummy/shims/gummy + chmod +x $ASDF_DIR/plugins/gummy/shims/gummy + + run asdf reshim + + run $ASDF_DIR/shims/foo + [ "$output" == "$ASDF_DIR/installs/dummy/2.0/bin/dummy" ] + + run $ASDF_DIR/shims/bar + [ "$output" == "$ASDF_DIR/shims/gummy" ] +} + @test "shim exec should remove shim_path from path on system version execution" { run asdf install dummy 2.0 @@ -261,7 +289,8 @@ teardown() { chmod +x $PROJECT_DIR/sys/dummy run env PATH=$PATH:$PROJECT_DIR/sys $ASDF_DIR/shims/dummy - [ "$output" == "$PROJECT_DIR/sys/dummy" ] + echo $status $output + [ "$output" == "$ASDF_DIR/shims/dummy" ] }