2017-07-23 09:34:58 -07:00
|
|
|
#!/usr/bin/env bats
|
2022-06-27 16:47:49 -07:00
|
|
|
# shellcheck disable=SC2030,SC2031
|
2017-07-23 09:34:58 -07:00
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_asdf_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
|
|
|
}
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
@test "plugin_add command with plugin name matching all valid regex chars succeeds" {
|
2022-12-28 19:12:47 -07:00
|
|
|
install_mock_plugin_repo "plugin_with-all-valid-chars-123"
|
2021-07-29 15:49:01 -07:00
|
|
|
|
2022-12-28 19:12:47 -07:00
|
|
|
run asdf plugin add "plugin_with-all-valid-chars-123" "${BASE_DIR}/repo-plugin_with-all-valid-chars-123"
|
2021-07-29 15:49:01 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2022-06-27 16:47:49 -07:00
|
|
|
run asdf plugin list
|
2022-12-28 19:12:47 -07:00
|
|
|
[ "$output" = "plugin_with-all-valid-chars-123" ]
|
2021-07-29 15:49:01 -07:00
|
|
|
}
|
|
|
|
|
2022-06-07 05:43:02 -07:00
|
|
|
@test "plugin_add command with LANG=sv_SE.UTF-8 and plugin name matching all valid regex chars succeeds" {
|
|
|
|
ORIGINAL_LANG="$LANG"
|
|
|
|
LANG=sv_SE.UTF-8
|
|
|
|
|
|
|
|
install_mock_plugin_repo "plugin-with-w"
|
|
|
|
|
|
|
|
# https://stackoverflow.com/questions/52570103/regular-expression-a-za-z-seems-to-not-include-letter-w-and-wA
|
|
|
|
# https://github.com/asdf-vm/asdf/issues/1237
|
|
|
|
run asdf plugin add "plugin-with-w" "${BASE_DIR}/repo-plugin-with-w"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2024-03-07 12:15:24 -07:00
|
|
|
run asdf plugin list
|
2022-06-07 05:43:02 -07:00
|
|
|
[ "$output" = "plugin-with-w" ]
|
|
|
|
|
|
|
|
LANG="$ORIGINAL_LANG"
|
|
|
|
}
|
2022-12-28 19:12:47 -07:00
|
|
|
|
|
|
|
@test "plugin_add command with plugin name not matching valid regex fails 1" {
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "invalid\$plugin\$name"
|
|
|
|
[ "$status" -eq 1 ]
|
2022-12-28 19:12:47 -07:00
|
|
|
[ "$output" = "invalid\$plugin\$name is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
|
2021-07-29 15:49:01 -07:00
|
|
|
}
|
|
|
|
|
2022-12-28 19:12:47 -07:00
|
|
|
@test "plugin_add command with plugin name not matching valid regex fails 2" {
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "#invalid#plugin#name"
|
|
|
|
[ "$status" -eq 1 ]
|
2022-12-28 19:12:47 -07:00
|
|
|
[ "$output" = "#invalid#plugin#name is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "plugin_add command with plugin name not matching valid regex fails 3" {
|
|
|
|
run asdf plugin add "Ruby"
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$output" = "Ruby is invalid. Name may only contain lowercase letters, numbers, '_', and '-'" ]
|
2021-07-29 15:49:01 -07:00
|
|
|
}
|
|
|
|
|
2017-07-23 09:34:58 -07:00
|
|
|
@test "plugin_add command with no URL specified adds a plugin using repo" {
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "elixir"
|
2017-07-23 09:34:58 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2022-06-27 16:47:49 -07:00
|
|
|
run asdf plugin list
|
2018-01-14 01:38:00 -07:00
|
|
|
[ "$output" = "elixir" ]
|
2017-07-23 09:34:58 -07:00
|
|
|
}
|
2017-07-25 17:03:30 -07:00
|
|
|
|
2022-06-27 16:47:49 -07:00
|
|
|
@test "plugin_add command with no URL specified adds a plugin when short name repository is enabled" {
|
|
|
|
export ASDF_CONFIG_DEFAULT_FILE="$HOME/.asdfrc"
|
|
|
|
echo "disable_plugin_short_name_repository=no" >"$ASDF_CONFIG_DEFAULT_FILE"
|
|
|
|
|
|
|
|
run asdf plugin add "elixir"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
local expected="elixir"
|
|
|
|
run asdf plugin list
|
|
|
|
[ "$output" = "$expected" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "plugin_add command with no URL specified fails to add a plugin when disabled" {
|
|
|
|
export ASDF_CONFIG_DEFAULT_FILE="$HOME/.asdfrc"
|
|
|
|
echo "disable_plugin_short_name_repository=yes" >"$ASDF_CONFIG_DEFAULT_FILE"
|
|
|
|
local expected="Short-name plugin repository is disabled"
|
|
|
|
|
|
|
|
run asdf plugin add "elixir"
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
[ "$output" = "$expected" ]
|
|
|
|
}
|
|
|
|
|
2020-03-21 06:59:33 -07:00
|
|
|
@test "plugin_add command with URL specified adds a plugin using repo" {
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
2020-03-21 06:59:33 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2022-06-27 16:47:49 -07:00
|
|
|
run asdf plugin list
|
2020-03-21 06:59:33 -07:00
|
|
|
# whitespace between 'elixir' and url is from printf %-15s %s format
|
|
|
|
[ "$output" = "dummy" ]
|
|
|
|
}
|
|
|
|
|
2023-07-26 04:42:08 -07:00
|
|
|
@test "plugin_add command with URL specified twice returns success on second time" {
|
2020-03-31 06:20:10 -07:00
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
2023-07-26 04:42:08 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2020-03-31 06:20:10 -07:00
|
|
|
[ "$output" = "Plugin named dummy already added" ]
|
|
|
|
}
|
|
|
|
|
2017-07-25 17:03:30 -07:00
|
|
|
@test "plugin_add command with no URL specified fails if the plugin doesn't exist" {
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "does-not-exist"
|
2017-07-25 17:03:30 -07:00
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
echo "$output" | grep "plugin does-not-exist not found in repository"
|
|
|
|
}
|
2020-03-21 06:59:33 -07:00
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
@test "plugin_add command executes post-plugin add script" {
|
2020-03-21 18:57:54 -07:00
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
|
|
|
[ "$output" = "plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy" ]
|
2020-03-21 18:57:54 -07:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:59:33 -07:00
|
|
|
@test "plugin_add command executes configured pre hook (generic)" {
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
cat >"$HOME/.asdfrc" <<-'EOM'
|
2020-03-21 06:59:33 -07:00
|
|
|
pre_asdf_plugin_add = echo ADD ${@}
|
|
|
|
EOM
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
2020-03-21 06:59:33 -07:00
|
|
|
|
|
|
|
local expected_output="ADD dummy
|
2021-07-29 15:49:01 -07:00
|
|
|
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
|
2020-03-21 06:59:33 -07:00
|
|
|
[ "$output" = "${expected_output}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "plugin_add command executes configured pre hook (specific)" {
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
cat >"$HOME/.asdfrc" <<-'EOM'
|
2020-03-21 06:59:33 -07:00
|
|
|
pre_asdf_plugin_add_dummy = echo ADD
|
|
|
|
EOM
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
2020-03-21 06:59:33 -07:00
|
|
|
|
|
|
|
local expected_output="ADD
|
2021-07-29 15:49:01 -07:00
|
|
|
plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy"
|
2020-03-21 06:59:33 -07:00
|
|
|
[ "$output" = "${expected_output}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "plugin_add command executes configured post hook (generic)" {
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
cat >"$HOME/.asdfrc" <<-'EOM'
|
2020-03-21 06:59:33 -07:00
|
|
|
post_asdf_plugin_add = echo ADD ${@}
|
|
|
|
EOM
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
2020-03-21 06:59:33 -07:00
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy
|
2020-03-21 06:59:33 -07:00
|
|
|
ADD dummy"
|
|
|
|
[ "$output" = "${expected_output}" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "plugin_add command executes configured post hook (specific)" {
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
cat >"$HOME/.asdfrc" <<-'EOM'
|
2020-03-21 06:59:33 -07:00
|
|
|
post_asdf_plugin_add_dummy = echo ADD
|
|
|
|
EOM
|
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
run asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
2020-03-21 06:59:33 -07:00
|
|
|
|
2021-07-29 15:49:01 -07:00
|
|
|
local expected_output="plugin add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy
|
2020-03-21 06:59:33 -07:00
|
|
|
ADD"
|
|
|
|
[ "$output" = "${expected_output}" ]
|
|
|
|
}
|