2021-11-18 03:05:27 -07:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
cd $(dirname "$BATS_TEST_DIRNAME")
|
2022-02-11 15:19:55 -07:00
|
|
|
mkdir -p $HOME/.config/elvish/lib
|
|
|
|
cp ./asdf.elv $HOME/.config/elvish/lib/asdftest.elv
|
2021-11-18 03:05:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
2022-02-11 15:19:55 -07:00
|
|
|
rm $HOME/.config/elvish/lib/asdftest.elv
|
2021-11-18 03:05:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
cleaned_path() {
|
|
|
|
echo $PATH | tr ':' '\n' | grep -v "asdf" | tr '\n' ' '
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "exports ASDF_DIR" {
|
|
|
|
output=$(elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:ASDF_DIR
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
[ "$output" = "$HOME/.asdf" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "retains ASDF_DIR" {
|
|
|
|
output=$(elvish -norc -c "
|
|
|
|
set-env ASDF_DIR "/path/to/asdf"
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:ASDF_DIR
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
[ "$output" = "/path/to/asdf" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "retains ASDF_DATA_DIR" {
|
|
|
|
output=$(elvish -norc -c "
|
|
|
|
set-env ASDF_DATA_DIR "/path/to/asdf-data"
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:ASDF_DATA_DIR
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
[ "$output" = "/path/to/asdf-data" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "adds asdf dirs to PATH" {
|
|
|
|
result=$(elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
echo \$E:PATH
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
echo "$result"
|
|
|
|
output=$(echo "$result" | grep "asdf")
|
|
|
|
[ "$output" != "" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "defines the _asdf namespace" {
|
|
|
|
output=$(elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
pprint \$_asdf:
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
[[ "$output" =~ "<ns " ]]
|
|
|
|
}
|
|
|
|
|
2022-06-25 04:35:08 -07:00
|
|
|
@test "does not add paths to PATH more than once" {
|
|
|
|
result=$(elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
|
|
|
echo \$E:PATH
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
output=$(echo $PATH | tr ':' '\n' | grep "asdf" | sort | uniq -d)
|
|
|
|
[ "$output" = "" ]
|
|
|
|
}
|
|
|
|
|
2021-11-18 03:05:27 -07:00
|
|
|
@test "defines the asdf function" {
|
|
|
|
output=$(elvish -norc -c "
|
|
|
|
unset-env ASDF_DIR
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
pprint \$asdf~
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
echo "$output"
|
|
|
|
[[ "$output" =~ "<closure " ]]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "function calls asdf command" {
|
|
|
|
result=$(elvish -norc -c "
|
|
|
|
set-env ASDF_DIR $(pwd)
|
2022-02-11 15:19:55 -07:00
|
|
|
set paths = [$(cleaned_path)]
|
|
|
|
use asdftest _asdf; var asdf~ = \$_asdf:asdf~
|
2021-11-18 03:05:27 -07:00
|
|
|
asdf info
|
|
|
|
")
|
|
|
|
[ "$?" -eq 0 ]
|
|
|
|
output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
|
|
|
|
[ "$output" != "" ]
|
|
|
|
}
|