2019-04-06 11:19:57 -07:00
|
|
|
#!/usr/bin/env bats
|
2023-01-25 06:37:21 -07:00
|
|
|
# shellcheck disable=SC2164
|
2019-04-06 11:19:57 -07:00
|
|
|
|
|
|
|
load test_helpers
|
|
|
|
|
|
|
|
setup() {
|
2023-01-24 06:15:23 -07:00
|
|
|
cd "$(dirname "$BATS_TEST_DIRNAME")"
|
2023-01-28 18:51:54 -07:00
|
|
|
|
2023-03-26 16:18:00 -07:00
|
|
|
if ! command -v fish &>/dev/null && [ -z "$GITHUB_ACTIONS" ]; then
|
2023-01-28 18:51:54 -07:00
|
|
|
skip "Fish is not installed"
|
|
|
|
fi
|
2019-04-06 11:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
cleaned_path() {
|
2023-01-22 16:36:47 -07:00
|
|
|
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ' '
|
2019-04-06 11:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "exports ASDF_DIR" {
|
2024-01-19 01:38:06 -07:00
|
|
|
run fish --no-config -c "
|
2019-04-06 11:19:57 -07:00
|
|
|
set -e asdf
|
|
|
|
set -e ASDF_DIR
|
|
|
|
set -e ASDF_DATA_DIR
|
|
|
|
set PATH $(cleaned_path)
|
|
|
|
|
2021-05-21 09:03:06 -07:00
|
|
|
. asdf.fish
|
2023-01-24 06:15:23 -07:00
|
|
|
echo \$ASDF_DIR"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
2021-11-18 03:05:27 -07:00
|
|
|
[ "$output" != "" ]
|
2019-04-06 11:19:57 -07:00
|
|
|
}
|
|
|
|
|
2019-04-07 14:07:50 -07:00
|
|
|
@test "adds asdf dirs to PATH" {
|
2024-01-19 01:38:06 -07:00
|
|
|
run fish --no-config -c "
|
2022-06-24 02:20:27 -07:00
|
|
|
set -e asdf
|
|
|
|
set -e ASDF_DIR
|
|
|
|
set -e ASDF_DATA_DIR
|
|
|
|
set PATH $(cleaned_path)
|
2019-04-07 14:07:50 -07:00
|
|
|
|
2022-06-24 02:20:27 -07:00
|
|
|
. (pwd)/asdf.fish # if the full path is not passed, status -f will return the relative path
|
2023-01-24 06:15:23 -07:00
|
|
|
echo \$PATH"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
result=$(echo "$output" | grep "asdf")
|
|
|
|
[ "$result" != "" ]
|
2019-04-07 14:07:50 -07:00
|
|
|
}
|
2019-04-06 11:19:57 -07:00
|
|
|
|
|
|
|
@test "does not add paths to PATH more than once" {
|
2024-01-19 01:38:06 -07:00
|
|
|
run fish --no-config -c "
|
2019-04-06 11:19:57 -07:00
|
|
|
set -e asdf
|
|
|
|
set -e ASDF_DIR
|
|
|
|
set -e ASDF_DATA_DIR
|
|
|
|
set PATH $(cleaned_path)
|
|
|
|
|
2021-05-21 09:03:06 -07:00
|
|
|
. asdf.fish
|
|
|
|
. asdf.fish
|
2023-01-24 06:15:23 -07:00
|
|
|
echo \$PATH"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
|
|
|
|
[ "$result" = "" ]
|
2019-04-06 11:19:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "defines the asdf function" {
|
2024-01-19 01:38:06 -07:00
|
|
|
run fish --no-config -c "
|
2019-04-06 11:19:57 -07:00
|
|
|
set -e asdf
|
|
|
|
set -e ASDF_DIR
|
|
|
|
set PATH $(cleaned_path)
|
|
|
|
|
2021-05-21 09:03:06 -07:00
|
|
|
. asdf.fish
|
2023-01-24 06:15:23 -07:00
|
|
|
type asdf"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
2019-04-06 11:19:57 -07:00
|
|
|
[[ "$output" =~ "is a function" ]]
|
|
|
|
}
|
2021-11-18 03:05:27 -07:00
|
|
|
|
|
|
|
@test "function calls asdf command" {
|
2024-01-19 01:38:06 -07:00
|
|
|
run fish --no-config -c "
|
2021-11-18 03:05:27 -07:00
|
|
|
set -e asdf
|
2022-12-27 06:33:59 -07:00
|
|
|
set -x ASDF_DIR $(pwd) # checkstyle-ignore
|
2021-11-18 03:05:27 -07:00
|
|
|
set PATH $(cleaned_path)
|
|
|
|
|
|
|
|
. asdf.fish
|
2023-01-24 06:15:23 -07:00
|
|
|
asdf info"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
|
|
|
|
[ "$result" != "" ]
|
2021-11-18 03:05:27 -07:00
|
|
|
}
|