2021-11-18 03:05:27 -07:00
|
|
|
#!/usr/bin/env bats
|
2023-01-27 05:17:41 -07:00
|
|
|
# shellcheck disable=SC2030,SC2031
|
2021-11-18 03:05:27 -07:00
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
2023-01-08 17:59:42 -07:00
|
|
|
export XDG_CONFIG_HOME=
|
|
|
|
export XDG_DATA_HOME=
|
|
|
|
export XDG_DATA_DIRS=
|
|
|
|
|
|
|
|
local ver_major=
|
|
|
|
local ver_minor=
|
|
|
|
local ver_patch=
|
|
|
|
IFS='.' read -r ver_major ver_minor ver_patch <<<"$(elvish -version)"
|
|
|
|
|
|
|
|
if ((ver_major == 0 && ver_minor < 18)); then
|
|
|
|
skip "Elvish version is not at least 0.18. Found ${ver_major}.${ver_minor}.${ver_patch}"
|
|
|
|
fi
|
2021-11-18 03:05:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
cleaned_path() {
|
|
|
|
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ' '
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "exports ASDF_DIR" {
|
|
|
|
run elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:ASDF_DIR"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "$HOME/.asdf" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "retains ASDF_DIR" {
|
|
|
|
run elvish -norc -c "
|
|
|
|
set-env ASDF_DIR \"/path/to/asdf\"
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:ASDF_DIR"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "/path/to/asdf" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "retains ASDF_DATA_DIR" {
|
|
|
|
run elvish -norc -c "
|
|
|
|
set-env ASDF_DATA_DIR \"/path/to/asdf-data\"
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:ASDF_DATA_DIR"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[ "$output" = "/path/to/asdf-data" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds asdf dirs to PATH" {
|
|
|
|
run elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:PATH"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
result=$(echo "$output" | grep "asdf")
|
|
|
|
[ "$result" != "" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "defines the _asdf namespace" {
|
|
|
|
run elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
pprint \$_asdf:"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "<ns " ]]
|
|
|
|
}
|
|
|
|
|
2022-06-25 04:35:08 -07:00
|
|
|
@test "does not add paths to PATH more than once" {
|
|
|
|
run elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2022-06-25 04:35:08 -07:00
|
|
|
echo \$E:PATH"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2022-06-25 04:35:08 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2022-10-18 06:58:12 -07:00
|
|
|
result=$(echo "$result" | tr ':' '\n' | grep "asdf" | sort | uniq -d)
|
2022-06-25 04:35:08 -07:00
|
|
|
[ "$result" = "" ]
|
|
|
|
}
|
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
@test "defines the asdf function" {
|
|
|
|
run elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
pprint \$asdf~"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" =~ "<closure " ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "function calls asdf command" {
|
|
|
|
run elvish -norc -c "
|
2022-12-27 06:33:59 -07:00
|
|
|
set-env ASDF_DIR $(pwd) # checkstyle-ignore
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
2023-01-08 17:59:42 -07:00
|
|
|
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
asdf info"
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$status" -eq 0 ]
|
2023-01-24 06:15:23 -07:00
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
|
|
|
|
[ "$result" != "" ]
|
|
|
|
}
|