2019-01-19 03:12:52 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
install_dummy_plugin
|
|
|
|
|
|
|
|
PROJECT_DIR=$HOME/project
|
|
|
|
mkdir -p $PROJECT_DIR
|
|
|
|
cd $PROJECT_DIR
|
|
|
|
|
|
|
|
# asdf lib needed to run generated shims
|
|
|
|
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
@test "asdf exec without argument should display help" {
|
|
|
|
run asdf exec
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "$output" | grep "usage: asdf exec <command>"
|
|
|
|
}
|
|
|
|
|
2019-01-19 19:00:34 -07:00
|
|
|
@test "asdf exec should pass all arguments to executable" {
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2019-01-19 19:00:34 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf exec dummy world hello
|
2019-01-19 19:00:34 -07:00
|
|
|
[ "$output" == "This is Dummy 1.0! hello world" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2019-01-19 19:09:53 -07:00
|
|
|
@test "asdf exec should pass all arguments to executable even if shim is not in PATH" {
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2019-01-19 19:09:53 -07:00
|
|
|
|
|
|
|
path=$(echo "$PATH" | sed -e "s|$(asdf_data_dir)/shims||g; s|::|:|g")
|
|
|
|
run env PATH=$path which dummy
|
|
|
|
[ "$output" == "" ]
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run env PATH=$path asdf exec dummy world hello
|
2019-01-19 19:09:53 -07:00
|
|
|
[ "$output" == "This is Dummy 1.0! hello world" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2019-01-19 03:12:52 -07:00
|
|
|
@test "shim exec should pass all arguments to executable" {
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$output" == "This is Dummy 1.0! hello world" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should pass stdin to executable" {
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "tr [:lower:] [:upper:]" >$ASDF_DIR/installs/dummy/1.0/bin/upper
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $ASDF_DIR/installs/dummy/1.0/bin/upper
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf reshim dummy 1.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run echo $(echo hello | $ASDF_DIR/shims/upper)
|
|
|
|
[ "$output" == "HELLO" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should fail if no version is selected" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
touch $PROJECT_DIR/.tool-versions
|
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$status" -eq 126 ]
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "$output" | grep -q "No version is set for command dummy" 2>/dev/null
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should suggest which plugin to use when no version is selected" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
touch $PROJECT_DIR/.tool-versions
|
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$status" -eq 126 ]
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "$output" | grep -q "No version is set for command dummy" 2>/dev/null
|
2020-07-31 01:46:33 -07:00
|
|
|
echo "$output" | grep -q "Consider adding one of the following versions in your config file at $PROJECT_DIR/.tool-versions" 2>/dev/null
|
2019-01-19 03:12:52 -07:00
|
|
|
echo "$output" | grep -q "dummy 1.0" 2>/dev/null
|
2020-09-18 22:37:52 -07:00
|
|
|
echo "$output" | grep -q "dummy 2.0.0" 2>/dev/null
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should suggest different plugins providing same tool when no version is selected" {
|
|
|
|
# Another fake plugin with 'dummy' executable
|
|
|
|
cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/mummy
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
|
|
|
run asdf install mummy 3.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
touch $PROJECT_DIR/.tool-versions
|
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$status" -eq 126 ]
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "$output" | grep -q "No version is set for command dummy" 2>/dev/null
|
2020-07-31 01:46:33 -07:00
|
|
|
echo "$output" | grep -q "Consider adding one of the following versions in your config file at $PROJECT_DIR/.tool-versions" 2>/dev/null
|
2019-01-19 03:12:52 -07:00
|
|
|
echo "$output" | grep -q "dummy 1.0" 2>/dev/null
|
|
|
|
echo "$output" | grep -q "mummy 3.0" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2019-12-04 07:18:58 -07:00
|
|
|
@test "shim exec should suggest to install missing version" {
|
|
|
|
run asdf install dummy 1.0
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 2.0.0 1.3" >$PROJECT_DIR/.tool-versions
|
2019-12-04 07:18:58 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$status" -eq 126 ]
|
2020-07-31 01:46:33 -07:00
|
|
|
echo "$output" | grep -q "No preset version installed for command dummy" 2>/dev/null
|
|
|
|
echo "$output" | grep -q "Please install a version by running one of the following:" 2>/dev/null
|
2020-09-18 22:37:52 -07:00
|
|
|
echo "$output" | grep -q "asdf install dummy 2.0.0" 2>/dev/null
|
2020-07-31 01:46:33 -07:00
|
|
|
echo "$output" | grep -q "asdf install dummy 1.3" 2>/dev/null
|
|
|
|
echo "$output" | grep -q "or add one of the following versions in your config file at $PROJECT_DIR/.tool-versions" 2>/dev/null
|
|
|
|
echo "$output" | grep -q "dummy 1.0" 2>/dev/null
|
2019-12-04 07:18:58 -07:00
|
|
|
}
|
|
|
|
|
2019-01-19 03:12:52 -07:00
|
|
|
@test "shim exec should execute first plugin that is installed and set" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 3.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0 3.0 2.0.0" >$PROJECT_DIR/.tool-versions
|
2019-03-14 13:08:13 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
echo "$output" | grep -q "This is Dummy 3.0! hello world" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should only use the first version found for a plugin" {
|
|
|
|
run asdf install dummy 3.0
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 3.0" >$PROJECT_DIR/.tool-versions
|
|
|
|
echo "dummy 1.0" >>$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
echo "$output" | grep -q "This is Dummy 3.0! hello world" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should determine correct executable on two projects using different plugins that provide the same tool" {
|
|
|
|
# Another fake plugin with 'dummy' executable
|
|
|
|
cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/mummy
|
|
|
|
sed -i -e 's/Dummy/Mummy/' $ASDF_DIR/plugins/mummy/bin/install
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install mummy 3.0
|
|
|
|
run asdf install dummy 1.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
mkdir $PROJECT_DIR/{A,B}
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/A/.tool-versions
|
|
|
|
echo "mummy 3.0" >$PROJECT_DIR/B/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
cd $PROJECT_DIR/A
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$output" == "This is Dummy 1.0! hello world" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
cd $PROJECT_DIR/B
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$output" == "This is Mummy 3.0! hello world" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should determine correct executable on a project with two plugins set that provide the same tool" {
|
|
|
|
# Another fake plugin with 'dummy' executable
|
|
|
|
cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/mummy
|
|
|
|
sed -i -e 's/Dummy/Mummy/' $ASDF_DIR/plugins/mummy/bin/install
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
|
|
|
run asdf install mummy 3.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 2.0.0" >$PROJECT_DIR/.tool-versions
|
|
|
|
echo "mummy 3.0" >>$PROJECT_DIR/.tool-versions
|
|
|
|
echo "dummy 1.0" >>$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$output" == "This is Mummy 3.0! hello world" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should fallback to system executable when specified version is system" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy system" >$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
mkdir $PROJECT_DIR/foo/
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "echo System" >$PROJECT_DIR/foo/dummy
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $PROJECT_DIR/foo/dummy
|
|
|
|
|
|
|
|
run env PATH=$PATH:$PROJECT_DIR/foo $ASDF_DIR/shims/dummy hello
|
2020-02-07 15:08:36 -07:00
|
|
|
[ "$output" == "System" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should use path executable when specified version path:<path>" {
|
|
|
|
run asdf install dummy 1.0
|
|
|
|
|
|
|
|
CUSTOM_DUMMY_PATH=$PROJECT_DIR/foo
|
|
|
|
CUSTOM_DUMMY_BIN_PATH=$CUSTOM_DUMMY_PATH/bin
|
|
|
|
mkdir -p $CUSTOM_DUMMY_BIN_PATH
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "echo System" >$CUSTOM_DUMMY_BIN_PATH/dummy
|
2020-02-07 15:08:36 -07:00
|
|
|
chmod +x $CUSTOM_DUMMY_BIN_PATH/dummy
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy path:$CUSTOM_DUMMY_PATH" >$PROJECT_DIR/.tool-versions
|
2020-02-07 15:08:36 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy hello
|
2019-01-19 03:12:52 -07:00
|
|
|
[ "$output" == "System" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should execute system if set first" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy system" >$PROJECT_DIR/.tool-versions
|
|
|
|
echo "dummy 2.0.0" >>$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
mkdir $PROJECT_DIR/foo/
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "echo System" >$PROJECT_DIR/foo/dummy
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $PROJECT_DIR/foo/dummy
|
|
|
|
|
|
|
|
run env PATH=$PATH:$PROJECT_DIR/foo $ASDF_DIR/shims/dummy hello
|
|
|
|
[ "$output" == "System" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should use custom exec-env for tool" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "export FOO=sourced" >$ASDF_DIR/plugins/dummy/bin/exec-env
|
2019-01-19 03:12:52 -07:00
|
|
|
mkdir $ASDF_DIR/plugins/dummy/shims
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'echo $FOO custom' >$ASDF_DIR/plugins/dummy/shims/foo
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $ASDF_DIR/plugins/dummy/shims/foo
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf reshim dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 2.0.0" >$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
run $ASDF_DIR/shims/foo
|
|
|
|
[ "$output" == "sourced custom" ]
|
|
|
|
}
|
|
|
|
|
2019-01-21 00:33:52 -07:00
|
|
|
@test "shim exec with custom exec-env using ASDF_INSTALL_PATH" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'export FOO=$ASDF_INSTALL_PATH/foo' >$ASDF_DIR/plugins/dummy/bin/exec-env
|
2019-01-21 00:33:52 -07:00
|
|
|
mkdir $ASDF_DIR/plugins/dummy/shims
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'echo $FOO custom' >$ASDF_DIR/plugins/dummy/shims/foo
|
2019-01-21 00:33:52 -07:00
|
|
|
chmod +x $ASDF_DIR/plugins/dummy/shims/foo
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf reshim dummy 2.0.0
|
2019-01-21 00:33:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 2.0.0" >$PROJECT_DIR/.tool-versions
|
2019-01-21 00:33:52 -07:00
|
|
|
run $ASDF_DIR/shims/foo
|
2020-09-18 22:37:52 -07:00
|
|
|
[ "$output" == "$ASDF_DIR/installs/dummy/2.0.0/foo custom" ]
|
2019-01-21 00:33:52 -07:00
|
|
|
}
|
|
|
|
|
2019-01-19 03:12:52 -07:00
|
|
|
@test "shim exec doest not use custom exec-env for system version" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "export FOO=sourced" >$ASDF_DIR/plugins/dummy/bin/exec-env
|
2019-01-19 03:12:52 -07:00
|
|
|
mkdir $ASDF_DIR/plugins/dummy/shims
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'echo $FOO custom' >$ASDF_DIR/plugins/dummy/shims/foo
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $ASDF_DIR/plugins/dummy/shims/foo
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf reshim dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy system" >$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
mkdir $PROJECT_DIR/sys/
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'echo x$FOO System' >$PROJECT_DIR/sys/foo
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $PROJECT_DIR/sys/foo
|
|
|
|
|
|
|
|
run env PATH=$PATH:$PROJECT_DIR/sys $ASDF_DIR/shims/foo
|
|
|
|
[ "$output" == "x System" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec should prepend the plugin paths on execution" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
mkdir $ASDF_DIR/plugins/dummy/shims
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'which dummy' >$ASDF_DIR/plugins/dummy/shims/foo
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $ASDF_DIR/plugins/dummy/shims/foo
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf reshim dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 2.0.0" >$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/foo
|
2020-09-18 22:37:52 -07:00
|
|
|
[ "$output" == "$ASDF_DIR/installs/dummy/2.0.0/bin/dummy" ]
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
2019-01-23 21:18:18 -07:00
|
|
|
@test "shim exec should be able to find other shims in path" {
|
|
|
|
cp -rf $ASDF_DIR/plugins/dummy $ASDF_DIR/plugins/gummy
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 2.0.0" >$PROJECT_DIR/.tool-versions
|
|
|
|
echo "gummy 2.0.0" >>$PROJECT_DIR/.tool-versions
|
2019-01-23 21:18:18 -07:00
|
|
|
|
|
|
|
run asdf install
|
|
|
|
|
|
|
|
mkdir $ASDF_DIR/plugins/{dummy,gummy}/shims
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'which dummy' >$ASDF_DIR/plugins/dummy/shims/foo
|
2019-01-23 21:18:18 -07:00
|
|
|
chmod +x $ASDF_DIR/plugins/dummy/shims/foo
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'which gummy' >$ASDF_DIR/plugins/dummy/shims/bar
|
2019-01-23 21:18:18 -07:00
|
|
|
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
|
2020-09-18 22:37:52 -07:00
|
|
|
[ "$output" == "$ASDF_DIR/installs/dummy/2.0.0/bin/dummy" ]
|
2019-01-23 21:18:18 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/bar
|
|
|
|
[ "$output" == "$ASDF_DIR/shims/gummy" ]
|
|
|
|
}
|
|
|
|
|
2019-01-19 03:12:52 -07:00
|
|
|
@test "shim exec should remove shim_path from path on system version execution" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy system" >$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
mkdir $PROJECT_DIR/sys/
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'which dummy' >$PROJECT_DIR/sys/dummy
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $PROJECT_DIR/sys/dummy
|
|
|
|
|
|
|
|
run env PATH=$PATH:$PROJECT_DIR/sys $ASDF_DIR/shims/dummy
|
2019-01-23 21:18:18 -07:00
|
|
|
echo $status $output
|
|
|
|
[ "$output" == "$ASDF_DIR/shims/dummy" ]
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec can take version from legacy file if configured" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "legacy_version_file = yes" >$HOME/.asdfrc
|
|
|
|
echo "2.0.0" >$PROJECT_DIR/.dummy-version
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
2020-09-18 22:37:52 -07:00
|
|
|
[ "$output" == "This is Dummy 2.0.0! hello world" ]
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec can take version from environment variable" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 2.0.0
|
|
|
|
run env ASDF_DUMMY_VERSION=2.0.0 $ASDF_DIR/shims/dummy world hello
|
|
|
|
[ "$output" == "This is Dummy 2.0.0! hello world" ]
|
2019-01-19 03:12:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec uses plugin list-bin-paths" {
|
|
|
|
exec_path="$ASDF_DIR/plugins/dummy/bin/list-bin-paths"
|
|
|
|
custom_path="$ASDF_DIR/installs/dummy/1.0/custom"
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "echo bin custom" >$exec_path
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $exec_path
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
mkdir $custom_path
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "echo CUSTOM" >$custom_path/foo
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $custom_path/foo
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf reshim dummy 1.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/foo
|
|
|
|
[ "$output" == "CUSTOM" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec uses plugin custom exec-path hook" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
exec_path="$ASDF_DIR/plugins/dummy/bin/exec-path"
|
2019-01-20 13:02:22 -07:00
|
|
|
custom_dummy="$ASDF_DIR/installs/dummy/1.0/custom/dummy"
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "echo custom/dummy" >$exec_path
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $exec_path
|
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
mkdir $(dirname $custom_dummy)
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "echo CUSTOM" >$custom_dummy
|
2019-01-19 03:12:52 -07:00
|
|
|
chmod +x $custom_dummy
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2019-01-19 03:12:52 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy
|
|
|
|
[ "$output" == "CUSTOM" ]
|
|
|
|
}
|
2019-01-19 12:00:33 -07:00
|
|
|
|
2019-01-20 13:02:22 -07:00
|
|
|
@test "shim exec uses plugin custom exec-path hook that defaults" {
|
|
|
|
run asdf install dummy 1.0
|
|
|
|
|
|
|
|
exec_path="$ASDF_DIR/plugins/dummy/bin/exec-path"
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'echo $3 # always same path' >$exec_path
|
2019-01-20 13:02:22 -07:00
|
|
|
chmod +x $exec_path
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2019-01-20 13:02:22 -07:00
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy
|
|
|
|
[ "$output" == "This is Dummy 1.0!" ]
|
|
|
|
}
|
|
|
|
|
2019-01-19 12:00:33 -07:00
|
|
|
@test "shim exec executes configured pre-hook" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2021-11-13 20:35:42 -07:00
|
|
|
echo dummy 1.0 >$PROJECT_DIR/.tool-versions
|
2019-01-19 12:00:33 -07:00
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
cat >$HOME/.asdfrc <<-'EOM'
|
2019-01-19 12:00:33 -07:00
|
|
|
pre_dummy_dummy = echo PRE $version $1 $2
|
|
|
|
EOM
|
|
|
|
|
|
|
|
run $ASDF_DIR/shims/dummy hello world
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
echo "$output" | grep "PRE 1.0 hello world"
|
|
|
|
echo "$output" | grep "This is Dummy 1.0! world hello"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "shim exec doesnt execute command if pre-hook failed" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy 1.0
|
2021-11-13 20:35:42 -07:00
|
|
|
echo dummy 1.0 >$PROJECT_DIR/.tool-versions
|
2019-01-19 12:00:33 -07:00
|
|
|
|
|
|
|
mkdir $HOME/hook
|
|
|
|
pre_cmd="$HOME/hook/pre"
|
2021-11-13 20:35:42 -07:00
|
|
|
echo 'echo $* && false' >"$pre_cmd"
|
2019-01-19 12:00:33 -07:00
|
|
|
chmod +x "$pre_cmd"
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
cat >$HOME/.asdfrc <<'EOM'
|
2019-01-19 12:00:33 -07:00
|
|
|
pre_dummy_dummy = pre $1 no $plugin_name $2
|
|
|
|
EOM
|
|
|
|
|
|
|
|
run env PATH=$PATH:$HOME/hook $ASDF_DIR/shims/dummy hello world
|
|
|
|
[ "$output" == "hello no dummy world" ]
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
}
|
|
|
|
|
2021-01-13 04:47:03 -07:00
|
|
|
# From @tejanium in https://github.com/asdf-vm/asdf/issues/581#issuecomment-635337727
|
|
|
|
@test "asdf exec should not crash when POSIXLY_CORRECT=1" {
|
|
|
|
export POSIXLY_CORRECT=1
|
|
|
|
|
2021-11-13 20:35:42 -07:00
|
|
|
echo "dummy 1.0" >$PROJECT_DIR/.tool-versions
|
2021-01-13 04:47:03 -07:00
|
|
|
run asdf install
|
|
|
|
|
|
|
|
run asdf exec dummy world hello
|
|
|
|
echo $output
|
|
|
|
[ "$output" == "This is Dummy 1.0! hello world" ]
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|