2023-01-04 13:42:34 -07:00
|
|
|
#!/usr/bin/env bats
|
2023-01-25 06:37:21 -07:00
|
|
|
# shellcheck disable=SC2164
|
2023-01-04 13:42:34 -07:00
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
cd "$(dirname "$BATS_TEST_DIRNAME")"
|
2023-01-06 07:43:15 -07:00
|
|
|
|
2023-03-26 16:18:00 -07:00
|
|
|
if ! command -v nu &>/dev/null && [ -z "$GITHUB_ACTIONS" ]; then
|
2023-01-06 07:43:15 -07:00
|
|
|
skip "Nu is not installed"
|
|
|
|
fi
|
2023-03-21 01:53:10 -07:00
|
|
|
|
|
|
|
setup_asdf_dir
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
clean_asdf_dir
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
cleaned_path() {
|
|
|
|
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ':'
|
|
|
|
}
|
|
|
|
|
2023-03-22 18:23:53 -07:00
|
|
|
run_nushell() {
|
2023-01-04 13:42:34 -07:00
|
|
|
run nu -c "
|
|
|
|
hide-env -i asdf
|
|
|
|
hide-env -i ASDF_DIR
|
2023-09-11 04:02:46 -07:00
|
|
|
\$env.PATH = ( '$(cleaned_path)' | split row ':' )
|
2024-01-09 05:25:30 -07:00
|
|
|
\$env.ASDF_DIR = '$PWD'
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
2023-03-22 18:23:53 -07:00
|
|
|
$1"
|
|
|
|
}
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-03-22 18:23:53 -07:00
|
|
|
@test "exports ASDF_DIR" {
|
|
|
|
run_nushell "echo \$env.ASDF_DIR"
|
2023-01-04 13:42:34 -07:00
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
result=$(echo "$output" | grep "asdf")
|
|
|
|
[ "$result" = "$PWD" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds asdf dirs to PATH" {
|
2023-03-22 18:23:53 -07:00
|
|
|
run_nushell "\$env.PATH | to text"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2023-01-04 13:42:34 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2023-02-19 03:46:59 -07:00
|
|
|
[[ "$output" == *"$PWD/bin"* ]]
|
|
|
|
[[ "$output" == *"$HOME/.asdf/shims"* ]]
|
2023-01-04 13:42:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "does not add paths to PATH more than once" {
|
2023-03-22 18:23:53 -07:00
|
|
|
run_nushell "
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
2023-01-04 13:42:34 -07:00
|
|
|
echo \$env.PATH"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2023-01-04 13:42:34 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2023-01-04 13:42:34 -07:00
|
|
|
result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
|
|
|
|
[ "$result" = "" ]
|
|
|
|
}
|
|
|
|
|
2024-01-09 05:25:30 -07:00
|
|
|
@test "retains ASDF_DIR (from ASDF_NU_DIR)" {
|
2023-01-04 13:42:34 -07:00
|
|
|
run nu -c "
|
|
|
|
hide-env -i asdf
|
2023-09-11 04:02:46 -07:00
|
|
|
\$env.ASDF_DIR = ( pwd )
|
|
|
|
\$env.PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
\$env.ASDF_NU_DIR = '$PWD'
|
2024-01-09 05:25:30 -07:00
|
|
|
|
|
|
|
source asdf.nu
|
|
|
|
|
|
|
|
echo \$env.ASDF_DIR"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$PWD" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "retains ASDF_DIR (from ASDF_DIR)" {
|
|
|
|
run nu -c "
|
|
|
|
hide-env -i asdf
|
|
|
|
\$env.ASDF_DIR = ( pwd )
|
|
|
|
\$env.PATH = ( '$(cleaned_path)' | split row ':' )
|
|
|
|
\$env.ASDF_DIR = '$PWD'
|
2023-01-04 13:42:34 -07:00
|
|
|
|
2023-01-06 07:43:15 -07:00
|
|
|
source asdf.nu
|
2023-01-04 13:42:34 -07:00
|
|
|
|
|
|
|
echo \$env.ASDF_DIR"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$PWD" ]
|
|
|
|
}
|
|
|
|
|
2023-02-19 03:46:59 -07:00
|
|
|
@test "defines the asdf or main function" {
|
2023-03-22 18:23:53 -07:00
|
|
|
run_nushell "which asdf | get path | to text"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2023-01-04 13:42:34 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "function calls asdf command" {
|
2023-03-22 18:23:53 -07:00
|
|
|
run_nushell "asdf info"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2023-01-04 13:42:34 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2023-01-04 13:42:34 -07:00
|
|
|
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
|
|
|
|
[ "$result" != "" ]
|
|
|
|
}
|
2023-03-21 01:53:10 -07:00
|
|
|
|
2023-03-22 18:23:53 -07:00
|
|
|
@test "parses the output of asdf plugin list" {
|
|
|
|
setup_repo
|
|
|
|
install_dummy_plugin
|
|
|
|
run_nushell "asdf plugin list | to csv -n"
|
2023-03-21 01:53:10 -07:00
|
|
|
|
2023-03-22 18:23:53 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "dummy" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "parses the output of asdf plugin list --urls" {
|
|
|
|
setup_repo
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
|
|
|
|
|
|
|
run_nushell "asdf plugin list --urls | to csv -n"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
local repo_url
|
|
|
|
repo_url=$(get_plugin_remote_url "dummy")
|
|
|
|
|
|
|
|
[ "$output" = "dummy,$repo_url" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "parses the output of asdf plugin list --refs" {
|
|
|
|
setup_repo
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
|
|
|
|
|
|
|
run_nushell "asdf plugin list --refs | to csv -n"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
local branch gitref
|
|
|
|
branch=$(get_plugin_remote_branch "dummy")
|
|
|
|
gitref=$(get_plugin_remote_gitref "dummy")
|
|
|
|
|
|
|
|
[ "$output" = "dummy,$branch,$gitref" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "parses the output of asdf plugin list --urls --refs" {
|
|
|
|
setup_repo
|
|
|
|
install_mock_plugin_repo "dummy"
|
|
|
|
asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
|
|
|
|
|
|
|
|
run_nushell "asdf plugin list --urls --refs | to csv -n"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
local repo_url branch gitref
|
|
|
|
repo_url=$(get_plugin_remote_url "dummy")
|
|
|
|
branch=$(get_plugin_remote_branch "dummy")
|
|
|
|
gitref=$(get_plugin_remote_gitref "dummy")
|
|
|
|
|
|
|
|
[ "$output" = "dummy,$repo_url,$branch,$gitref" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "parses the output of asdf plugin list all" {
|
|
|
|
setup_repo
|
|
|
|
install_dummy_plugin
|
|
|
|
run_nushell "asdf plugin list all | to csv -n"
|
2023-03-21 01:53:10 -07:00
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "\
|
|
|
|
bar,false,http://example.com/bar
|
|
|
|
dummy,true,http://example.com/dummy
|
|
|
|
foo,false,http://example.com/foo" ]
|
|
|
|
}
|