2016-06-28 20:56:33 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
2020-05-04 08:15:36 -07:00
|
|
|
install_dummy_legacy_plugin
|
2016-06-28 20:56:33 -07:00
|
|
|
install_dummy_plugin
|
2016-10-25 15:13:13 -07:00
|
|
|
|
|
|
|
PROJECT_DIR=$HOME/project
|
|
|
|
mkdir $PROJECT_DIR
|
2016-06-28 20:56:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "install_command installs the correct version" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2016-06-28 20:56:33 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.1.0/version) = "1.1.0" ]
|
2016-06-28 20:56:33 -07:00
|
|
|
}
|
|
|
|
|
2020-05-04 08:15:36 -07:00
|
|
|
@test "install_command installs the correct version for plugins without download script" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install legacy-dummy 1.1.0
|
2020-05-04 08:15:36 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/legacy-dummy/1.1.0/version) = "1.1.0" ]
|
2020-05-04 08:15:36 -07:00
|
|
|
}
|
|
|
|
|
2019-05-31 21:48:17 -07:00
|
|
|
@test "install_command without arguments installs even if the user is terrible and does not use newlines" {
|
2018-11-15 19:47:48 -07:00
|
|
|
cd $PROJECT_DIR
|
2020-09-18 22:37:52 -07:00
|
|
|
echo -n 'dummy 1.2.0' > ".tool-versions"
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2018-11-15 19:47:48 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.2.0/version) = "1.2.0" ]
|
2018-11-15 19:47:48 -07:00
|
|
|
}
|
|
|
|
|
2020-07-09 16:15:03 -07:00
|
|
|
@test "install_command with only name installs the version in .tool-versions" {
|
|
|
|
cd $PROJECT_DIR
|
2020-09-18 22:37:52 -07:00
|
|
|
echo -n 'dummy 1.2.0' > ".tool-versions"
|
2020-07-09 16:15:03 -07:00
|
|
|
run asdf install dummy
|
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.2.0/version) = "1.2.0" ]
|
2020-07-09 16:15:03 -07:00
|
|
|
}
|
|
|
|
|
2016-06-28 20:56:33 -07:00
|
|
|
@test "install_command set ASDF_CONCURRENCY" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
2016-06-28 20:56:33 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -f $ASDF_DIR/installs/dummy/1.0.0/env ]
|
|
|
|
run grep ASDF_CONCURRENCY $ASDF_DIR/installs/dummy/1.0.0/env
|
2016-06-28 20:56:33 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
2016-10-25 15:11:36 -07:00
|
|
|
|
2019-05-31 21:48:17 -07:00
|
|
|
@test "install_command without arguments should work in directory containing whitespace" {
|
2016-10-25 15:11:36 -07:00
|
|
|
WHITESPACE_DIR="$PROJECT_DIR/whitespace\ dir"
|
|
|
|
mkdir -p "$WHITESPACE_DIR"
|
|
|
|
cd "$WHITESPACE_DIR"
|
2020-09-18 22:37:52 -07:00
|
|
|
echo 'dummy 1.2.0' >> "$WHITESPACE_DIR/.tool-versions"
|
2016-10-25 15:11:36 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2016-10-25 15:11:36 -07:00
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.2.0/version) = "1.2.0" ]
|
2016-10-25 15:11:36 -07:00
|
|
|
}
|
2016-12-10 11:17:50 -07:00
|
|
|
|
2017-07-26 13:00:55 -07:00
|
|
|
@test "install_command should create a shim with asdf-plugin metadata" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
2016-12-10 11:17:50 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -f $ASDF_DIR/installs/dummy/1.0.0/env ]
|
|
|
|
run grep "asdf-plugin: dummy 1.0.0" $ASDF_DIR/shims/dummy
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2020-05-04 08:15:36 -07:00
|
|
|
@test "install_command should create a shim with asdf-plugin metadata for plugins without download script" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install legacy-dummy 1.0.0
|
2020-05-04 08:15:36 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -f $ASDF_DIR/installs/legacy-dummy/1.0.0/env ]
|
|
|
|
run grep "asdf-plugin: legacy-dummy 1.0.0" $ASDF_DIR/shims/dummy
|
2020-05-04 08:15:36 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
2019-01-19 03:12:52 -07:00
|
|
|
@test "install_command on two versions should create a shim with asdf-plugin metadata" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2019-01-19 03:12:52 -07:00
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run grep "asdf-plugin: dummy 1.1.0" $ASDF_DIR/shims/dummy
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run grep "asdf-plugin: dummy 1.0.0" $ASDF_DIR/shims/dummy
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
run grep "asdf-plugin: dummy 1.0.0" $ASDF_DIR/shims/dummy
|
2019-01-19 03:12:52 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run grep "# asdf-plugin: dummy 1.0.0"$'\n'"# asdf-plugin: dummy 1.1.0" $ASDF_DIR/shims/dummy
|
2017-07-26 13:00:55 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
lines_count=$(grep "asdf-plugin: dummy 1.1.0" $ASDF_DIR/shims/dummy | wc -l)
|
2017-09-03 18:23:06 -07:00
|
|
|
[ "$lines_count" -eq "1" ]
|
2016-12-10 11:17:50 -07:00
|
|
|
}
|
2016-12-10 11:22:36 -07:00
|
|
|
|
2019-05-31 21:48:17 -07:00
|
|
|
@test "install_command without arguments should not generate shim for subdir" {
|
2018-09-19 05:00:11 -07:00
|
|
|
cd $PROJECT_DIR
|
2020-09-18 22:37:52 -07:00
|
|
|
echo 'dummy 1.0.0' > $PROJECT_DIR/.tool-versions
|
2018-09-19 05:00:11 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2018-09-19 05:00:11 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ -f "$ASDF_DIR/shims/dummy" ]
|
|
|
|
[ ! -f "$ASDF_DIR/shims/subdir" ]
|
|
|
|
}
|
2016-12-10 11:22:36 -07:00
|
|
|
|
2019-05-31 21:48:17 -07:00
|
|
|
@test "install_command without arguments should generate shim that passes all arguments to executable" {
|
2016-12-13 12:32:49 -07:00
|
|
|
# asdf lib needed to run generated shims
|
|
|
|
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
|
|
|
|
|
|
|
|
cd $PROJECT_DIR
|
2020-09-18 22:37:52 -07:00
|
|
|
echo 'dummy 1.0.0' > $PROJECT_DIR/.tool-versions
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2016-12-13 12:32:49 -07:00
|
|
|
|
|
|
|
# execute the generated shim
|
2019-01-19 03:12:52 -07:00
|
|
|
run $ASDF_DIR/shims/dummy world hello
|
2016-12-10 11:22:36 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ "$output" == "This is Dummy 1.0.0! hello world" ]
|
2016-12-10 11:22:36 -07:00
|
|
|
}
|
2016-12-18 10:52:23 -07:00
|
|
|
|
2020-07-09 16:15:03 -07:00
|
|
|
@test "install_command fails when tool is specified but no version of the tool is configured" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy
|
2016-12-18 10:52:23 -07:00
|
|
|
[ "$status" -eq 1 ]
|
2020-07-09 16:15:03 -07:00
|
|
|
[ "$output" = "No versions specified for dummy in config files or environment" ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ ! -f $ASDF_DIR/installs/dummy/1.1.0/version ]
|
2020-07-09 16:15:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "install_command fails when tool is specified but no version of the tool is configured in config file" {
|
2020-09-18 22:37:52 -07:00
|
|
|
echo 'dummy 1.0.0' > $PROJECT_DIR/.tool-versions
|
2020-07-09 16:15:03 -07:00
|
|
|
run asdf install other-dummy
|
2016-12-18 10:52:23 -07:00
|
|
|
[ "$status" -eq 1 ]
|
2020-07-09 16:15:03 -07:00
|
|
|
[ "$output" = "No versions specified for other-dummy in config files or environment" ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ ! -f $ASDF_DIR/installs/dummy/1.0.0/version ]
|
2016-12-18 10:52:23 -07:00
|
|
|
}
|
2017-10-10 10:02:42 -07:00
|
|
|
|
2020-07-09 19:18:16 -07:00
|
|
|
@test "install_command fails when two tools are specified with no versions" {
|
2020-09-18 22:37:52 -07:00
|
|
|
printf 'dummy 1.0.0\nother-dummy 2.0.0' > $PROJECT_DIR/.tool-versions
|
2020-07-09 19:18:16 -07:00
|
|
|
run asdf install dummy other-dummy
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$output" = "Dummy couldn't install version: other-dummy (on purpose)" ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ ! -f $ASDF_DIR/installs/dummy/1.0.0/version ]
|
|
|
|
[ ! -f $ASDF_DIR/installs/other-dummy/2.0.0/version ]
|
2020-07-09 19:18:16 -07:00
|
|
|
}
|
|
|
|
|
2019-05-31 21:48:17 -07:00
|
|
|
@test "install_command without arguments uses a parent directory .tool-versions file if present" {
|
2017-10-10 10:02:42 -07:00
|
|
|
# asdf lib needed to run generated shims
|
|
|
|
cp -rf $BATS_TEST_DIRNAME/../{bin,lib} $ASDF_DIR/
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
echo 'dummy 1.0.0' > $PROJECT_DIR/.tool-versions
|
2017-10-10 10:02:42 -07:00
|
|
|
mkdir -p $PROJECT_DIR/child
|
|
|
|
|
|
|
|
cd $PROJECT_DIR/child
|
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install
|
2017-10-10 10:02:42 -07:00
|
|
|
|
|
|
|
# execute the generated shim
|
2020-09-18 22:37:52 -07:00
|
|
|
[ "$($ASDF_DIR/shims/dummy world hello)" == "This is Dummy 1.0.0! hello world" ]
|
2017-10-10 10:02:42 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
2018-10-07 11:31:30 -07:00
|
|
|
|
2019-10-22 15:58:30 -07:00
|
|
|
@test "install_command installs multiple tool versions when they are specified in a .tool-versions file" {
|
2020-09-18 22:37:52 -07:00
|
|
|
echo 'dummy 1.0.0 1.2.0' > $PROJECT_DIR/.tool-versions
|
2019-10-22 15:58:30 -07:00
|
|
|
cd $PROJECT_DIR
|
|
|
|
|
|
|
|
run asdf install
|
|
|
|
echo $output
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.0.0/version) = "1.0.0" ]
|
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.2.0/version) = "1.2.0" ]
|
2019-10-22 15:58:30 -07:00
|
|
|
}
|
|
|
|
|
2018-10-07 11:31:30 -07:00
|
|
|
@test "install_command doesn't install system version" {
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf install dummy system
|
2018-10-07 11:31:30 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ ! -f $ASDF_DIR/installs/dummy/system/version ]
|
|
|
|
}
|
2019-01-19 12:00:33 -07:00
|
|
|
|
2019-01-19 12:16:13 -07:00
|
|
|
@test "install command executes configured pre plugin install hook" {
|
|
|
|
cat > $HOME/.asdfrc <<-'EOM'
|
|
|
|
pre_asdf_install_dummy = echo will install dummy $1
|
|
|
|
EOM
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
|
|
|
[ "$output" == "will install dummy 1.0.0" ]
|
2019-01-19 12:16:13 -07:00
|
|
|
}
|
|
|
|
|
2019-01-19 12:00:33 -07:00
|
|
|
@test "install command executes configured post plugin install hook" {
|
|
|
|
cat > $HOME/.asdfrc <<-'EOM'
|
2019-01-19 12:16:13 -07:00
|
|
|
post_asdf_install_dummy = echo HEY $version FROM $plugin_name
|
2019-01-19 12:00:33 -07:00
|
|
|
EOM
|
|
|
|
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.0.0
|
|
|
|
[ "$output" == "HEY 1.0.0 FROM dummy" ]
|
2019-01-19 12:00:33 -07:00
|
|
|
}
|
2019-03-24 17:15:56 -07:00
|
|
|
|
2019-05-31 21:48:17 -07:00
|
|
|
@test "install command without arguments installs versions from legacy files" {
|
|
|
|
echo 'legacy_version_file = yes' > $HOME/.asdfrc
|
2020-09-18 22:37:52 -07:00
|
|
|
echo '1.2.0' >> $PROJECT_DIR/.dummy-version
|
2019-06-17 17:38:17 -07:00
|
|
|
cd $PROJECT_DIR
|
2019-05-31 21:48:17 -07:00
|
|
|
run asdf install
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" == "" ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -f $ASDF_DIR/installs/dummy/1.2.0/version ]
|
2019-05-31 21:48:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "install command without arguments installs versions from legacy files in parent directories" {
|
|
|
|
echo 'legacy_version_file = yes' > $HOME/.asdfrc
|
2020-09-18 22:37:52 -07:00
|
|
|
echo '1.2.0' >> $PROJECT_DIR/.dummy-version
|
2019-05-31 21:48:17 -07:00
|
|
|
|
|
|
|
mkdir -p $PROJECT_DIR/child
|
|
|
|
cd $PROJECT_DIR/child
|
|
|
|
|
2019-03-24 17:15:56 -07:00
|
|
|
run asdf install
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" == "" ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -f $ASDF_DIR/installs/dummy/1.2.0/version ]
|
2019-03-24 17:15:56 -07:00
|
|
|
}
|
2019-11-22 11:37:53 -07:00
|
|
|
|
|
|
|
@test "install_command latest installs latest stable version" {
|
|
|
|
run asdf install dummy latest
|
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/2.0.0/version) = "2.0.0" ]
|
2019-11-22 11:37:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "install_command latest:version installs latest stable version that matches the given string" {
|
|
|
|
run asdf install dummy latest:1
|
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.1.0/version) = "1.1.0" ]
|
2019-11-22 11:37:53 -07:00
|
|
|
}
|
2020-05-04 12:05:10 -07:00
|
|
|
|
|
|
|
@test "install_command deletes the download directory" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2020-05-04 12:05:10 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ ! -d $ASDF_DIR/downloads/dummy/1.1.0 ]
|
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.1.0/version) = "1.1.0" ]
|
2020-05-04 12:05:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "install_command keeps the download directory when --keep-download flag is provided" {
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0 --keep-download
|
2020-05-04 12:05:10 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -d $ASDF_DIR/downloads/dummy/1.1.0 ]
|
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.1.0/version) = "1.1.0" ]
|
2020-05-04 12:05:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "install_command keeps the download directory when always_keep_download setting is true" {
|
|
|
|
echo 'always_keep_download = yes' > $HOME/.asdfrc
|
2020-09-18 22:37:52 -07:00
|
|
|
run asdf install dummy 1.1.0
|
2020-05-04 12:05:10 -07:00
|
|
|
echo $output
|
|
|
|
[ "$status" -eq 0 ]
|
2020-09-18 22:37:52 -07:00
|
|
|
[ -d $ASDF_DIR/downloads/dummy/1.1.0 ]
|
|
|
|
[ $(cat $ASDF_DIR/installs/dummy/1.1.0/version) = "1.1.0" ]
|
2020-05-04 12:05:10 -07:00
|
|
|
}
|