asdf
1#!/usr/bin/env bats
2# shellcheck disable=SC2164
3
4load test_helpers
5
6setup() {
7cd "$(dirname "$BATS_TEST_DIRNAME")"
8
9if ! command -v fish &>/dev/null && [ -z "$GITHUB_ACTIONS" ]; then
10skip "Fish is not installed"
11fi
12}
13
14cleaned_path() {
15echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ' '
16}
17
18@test "exports ASDF_DIR" {
19run fish --no-config -c "
20set -e asdf
21set -e ASDF_DIR
22set -e ASDF_DATA_DIR
23set PATH $(cleaned_path)
24
25. asdf.fish
26echo \$ASDF_DIR"
27
28[ "$status" -eq 0 ]
29[ "$output" != "" ]
30}
31
32@test "adds asdf dirs to PATH" {
33run fish --no-config -c "
34set -e asdf
35set -e ASDF_DIR
36set -e ASDF_DATA_DIR
37set PATH $(cleaned_path)
38
39. (pwd)/asdf.fish # if the full path is not passed, status -f will return the relative path
40echo \$PATH"
41
42[ "$status" -eq 0 ]
43
44result=$(echo "$output" | grep "asdf")
45[ "$result" != "" ]
46}
47
48@test "does not add paths to PATH more than once" {
49run fish --no-config -c "
50set -e asdf
51set -e ASDF_DIR
52set -e ASDF_DATA_DIR
53set PATH $(cleaned_path)
54
55. asdf.fish
56. asdf.fish
57echo \$PATH"
58
59[ "$status" -eq 0 ]
60
61result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
62[ "$result" = "" ]
63}
64
65@test "defines the asdf function" {
66run fish --no-config -c "
67set -e asdf
68set -e ASDF_DIR
69set PATH $(cleaned_path)
70
71. asdf.fish
72type asdf"
73
74[ "$status" -eq 0 ]
75[[ "$output" =~ "is a function" ]]
76}
77
78@test "function calls asdf command" {
79run fish --no-config -c "
80set -e asdf
81set -x ASDF_DIR $(pwd) # checkstyle-ignore
82set PATH $(cleaned_path)
83
84. asdf.fish
85asdf info"
86
87[ "$status" -eq 0 ]
88
89result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
90[ "$result" != "" ]
91}
92