2016-07-24 08:47:17 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
install_dummy_plugin
|
2016-07-30 16:48:57 -07:00
|
|
|
install_dummy_version "1.1.0"
|
|
|
|
install_dummy_version "1.2.0"
|
2018-10-10 07:00:59 -07:00
|
|
|
install_dummy_version "nightly-2000-01-01"
|
2016-07-24 08:47:17 -07:00
|
|
|
|
2023-01-22 16:36:47 -07:00
|
|
|
PROJECT_DIR="$HOME/project"
|
|
|
|
mkdir -p "$PROJECT_DIR"
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2016-07-30 16:48:57 -07:00
|
|
|
@test "current should derive from the current .tool-versions" {
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo 'dummy 1.1.0' >>"$PROJECT_DIR/.tool-versions"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
dummy 1.1.0 $PROJECT_DIR/.tool-versions true"
|
2016-07-24 08:47:17 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "dummy"
|
2024-12-15 12:16:28 -07:00
|
|
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' <<<"$output")"
|
|
|
|
|
2016-07-24 08:47:17 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2024-12-15 12:16:28 -07:00
|
|
|
[ "$condensed_output" = "$expected" ]
|
2018-10-10 07:00:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "current should handle long version name" {
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo "dummy nightly-2000-01-01" >>"$PROJECT_DIR/.tool-versions"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
dummy nightly-2000-01-01 $PROJECT_DIR/.tool-versions true"
|
2018-10-10 07:00:59 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "dummy"
|
2024-12-15 12:16:28 -07:00
|
|
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' <<<"$output")"
|
|
|
|
|
2018-10-10 07:00:59 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2024-12-15 12:16:28 -07:00
|
|
|
[ "$condensed_output" = "$expected" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
2018-11-10 04:32:02 -07:00
|
|
|
@test "current should handle multiple versions" {
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo "dummy 1.2.0 1.1.0" >>"$PROJECT_DIR/.tool-versions"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
dummy 1.2.0 1.1.0 $PROJECT_DIR/.tool-versions true"
|
2018-11-10 04:32:02 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "dummy"
|
2024-12-15 12:16:28 -07:00
|
|
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' <<<"$output")"
|
|
|
|
|
2018-11-10 04:32:02 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2024-12-15 12:16:28 -07:00
|
|
|
[ "$condensed_output" = "$expected" ]
|
2018-11-10 04:32:02 -07:00
|
|
|
}
|
|
|
|
|
2016-07-30 16:48:57 -07:00
|
|
|
@test "current should derive from the legacy file if enabled" {
|
2023-01-22 16:36:47 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo 'legacy_version_file = yes' >"$HOME/.asdfrc"
|
|
|
|
echo '1.2.0' >>"$PROJECT_DIR/.dummy-version"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
dummy 1.2.0 $PROJECT_DIR/.dummy-version true"
|
2016-07-24 08:47:17 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "dummy"
|
2024-12-15 12:16:28 -07:00
|
|
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' <<<"$output")"
|
|
|
|
|
2016-07-24 08:47:17 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2024-12-15 12:16:28 -07:00
|
|
|
[ "$condensed_output" = "$expected" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
2020-08-28 16:09:22 -07:00
|
|
|
# TODO: Need to fix plugin error as well
|
2016-07-24 08:47:17 -07:00
|
|
|
@test "current should error when the plugin doesn't exist" {
|
2020-09-01 16:11:07 -07:00
|
|
|
expected="No such plugin: foobar"
|
2020-08-28 16:09:22 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "foobar"
|
2016-07-24 08:47:17 -07:00
|
|
|
[ "$status" -eq 1 ]
|
2020-08-28 16:09:22 -07:00
|
|
|
[ "$output" = "$expected" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "current should error when no version is set" {
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
dummy ______ ______ "
|
2016-07-30 16:48:57 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "dummy"
|
2024-12-15 12:16:28 -07:00
|
|
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' <<<"$output")"
|
|
|
|
|
2018-04-09 11:35:51 -07:00
|
|
|
[ "$status" -eq 126 ]
|
2024-12-15 12:16:28 -07:00
|
|
|
[ "$condensed_output" = "$expected" ]
|
2016-07-30 16:48:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "current should error when a version is set that isn't installed" {
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo 'dummy 9.9.9' >>"$PROJECT_DIR/.tool-versions"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
dummy 9.9.9 $PROJECT_DIR/.tool-versions false - Run \`asdf install dummy 9.9.9\`"
|
2016-07-24 08:47:17 -07:00
|
|
|
|
2024-12-15 12:16:28 -07:00
|
|
|
asdf uninstall dummy 9.9.9 || true
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "dummy"
|
2024-12-15 12:16:28 -07:00
|
|
|
|
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' -e 's/ $//g' <<<"$output")"
|
|
|
|
|
2016-07-24 08:47:17 -07:00
|
|
|
[ "$status" -eq 1 ]
|
2024-12-15 12:16:28 -07:00
|
|
|
|
|
|
|
[ "$condensed_output" = "$expected" ]
|
2016-07-24 08:47:17 -07:00
|
|
|
}
|
2017-08-18 21:56:28 -07:00
|
|
|
|
|
|
|
@test "should output all plugins when no plugin passed" {
|
|
|
|
|
2024-09-14 13:06:08 -07:00
|
|
|
#install_dummy_plugin
|
2017-08-18 21:56:28 -07:00
|
|
|
install_dummy_version "1.1.0"
|
|
|
|
|
|
|
|
install_mock_plugin "foobar"
|
|
|
|
install_mock_plugin_version "foobar" "1.0.0"
|
|
|
|
|
2017-09-03 20:20:35 -07:00
|
|
|
install_mock_plugin "baz"
|
|
|
|
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo 'dummy 1.1.0' >>"$PROJECT_DIR/.tool-versions"
|
|
|
|
echo 'foobar 1.0.0' >>"$PROJECT_DIR/.tool-versions"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
baz ______ ______
|
|
|
|
dummy 1.1.0 $PROJECT_DIR/.tool-versions true
|
|
|
|
foobar 1.0.0 $PROJECT_DIR/.tool-versions true"
|
2017-08-18 21:56:28 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current
|
2017-08-18 21:56:28 -07:00
|
|
|
|
2024-12-15 12:16:28 -07:00
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' -e 's/ $//g' <<<"$output")"
|
|
|
|
|
|
|
|
[ "$expected" = "$condensed_output" ]
|
2017-08-18 21:56:28 -07:00
|
|
|
}
|
2018-02-11 15:28:29 -07:00
|
|
|
|
|
|
|
@test "should always match the tool name exactly" {
|
2024-09-14 13:06:08 -07:00
|
|
|
#install_dummy_plugin
|
2018-02-11 15:28:29 -07:00
|
|
|
install_dummy_version "1.1.0"
|
|
|
|
|
|
|
|
install_mock_plugin "y"
|
|
|
|
install_mock_plugin_version "y" "2.1.0"
|
|
|
|
|
2023-01-22 21:29:18 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo 'dummy 1.1.0' >>"$PROJECT_DIR/.tool-versions"
|
|
|
|
echo 'y 2.1.0' >>"$PROJECT_DIR/.tool-versions"
|
2018-02-11 15:28:29 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current "y"
|
2018-02-11 15:28:29 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-25 06:37:21 -07:00
|
|
|
[[ "$output" == *'2.1.0'* ]]
|
2018-02-11 15:28:29 -07:00
|
|
|
}
|
|
|
|
|
2018-10-07 11:22:31 -07:00
|
|
|
@test "with no plugins prints an error" {
|
|
|
|
clean_asdf_dir
|
2020-12-20 17:00:09 -07:00
|
|
|
expected="No plugins installed"
|
2020-08-28 16:09:22 -07:00
|
|
|
|
2019-01-20 01:13:20 -07:00
|
|
|
run asdf current
|
2018-10-07 11:22:31 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-08-28 16:09:22 -07:00
|
|
|
[ "$output" = "$expected" ]
|
2018-10-07 11:22:31 -07:00
|
|
|
}
|
2019-03-31 12:39:36 -07:00
|
|
|
|
|
|
|
@test "current should handle comments" {
|
2023-01-22 02:20:23 -07:00
|
|
|
cd "$PROJECT_DIR"
|
|
|
|
echo "dummy 1.2.0 # this is a comment" >>"$PROJECT_DIR/.tool-versions"
|
2024-12-15 12:16:28 -07:00
|
|
|
expected="Name Version Source Installed
|
|
|
|
dummy 1.2.0 $PROJECT_DIR/.tool-versions true"
|
2019-03-31 12:39:36 -07:00
|
|
|
|
|
|
|
run asdf current "dummy"
|
|
|
|
[ "$status" -eq 0 ]
|
2024-12-15 12:16:28 -07:00
|
|
|
# shellcheck disable=SC2001
|
|
|
|
condensed_output="$(sed -e 's/ [ ]*/ /g' <<<"$output")"
|
|
|
|
[ "$condensed_output" = "$expected" ]
|
2019-03-31 12:39:36 -07:00
|
|
|
}
|