asdf/test/asdf_sh.bats

98 lines
1.6 KiB
Plaintext
Raw Normal View History

2019-04-06 09:43:39 -07:00
#!/usr/bin/env bats
load test_helpers
# Helper function to handle sourcing of asdf.sh
source_asdf_sh() {
. "$(dirname "$BATS_TEST_DIRNAME")/asdf.sh"
2019-04-06 09:43:39 -07:00
}
cleaned_path() {
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ':'
2019-04-06 09:43:39 -07:00
}
@test "exports ASDF_DIR" {
output=$(
2019-04-06 09:43:39 -07:00
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
source_asdf_sh
echo "$ASDF_DIR"
2019-04-06 09:43:39 -07:00
)
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "does not error if nounset is enabled" {
output=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
set -o nounset
source_asdf_sh
echo "$ASDF_DIR"
)
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
2019-04-06 09:43:39 -07:00
}
@test "adds asdf dirs to PATH" {
output=$(
2019-04-06 09:43:39 -07:00
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
source_asdf_sh
echo "$PATH"
2019-04-06 09:43:39 -07:00
)
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
2019-04-06 09:43:39 -07:00
}
@test "does not add paths to PATH more than once" {
output=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
source_asdf_sh
source_asdf_sh
echo "$PATH"
)
result=$(echo "$output" | tr ':' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
2019-04-06 09:43:39 -07:00
@test "defines the asdf function" {
output=$(
unset -f asdf
unset ASDF_DIR
PATH=$(cleaned_path)
source_asdf_sh
type asdf
)
[[ "$output" =~ "is a function" ]]
}
2021-11-18 03:05:27 -07:00
@test "function calls asdf command" {
result=$(
unset -f asdf
ASDF_DIR=$PWD
2021-11-18 03:05:27 -07:00
PATH=$(cleaned_path)
source_asdf_sh
asdf info
)
2021-11-18 03:05:27 -07:00
output=$(echo "$result" | grep "ASDF INSTALLED PLUGINS:")
[ "$output" != "" ]
}