forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasdf_elvish.bats
127 lines (101 loc) · 2.88 KB
/
asdf_elvish.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bats
# shellcheck disable=SC2030,SC2031
load test_helpers
setup() {
export XDG_CONFIG_HOME=
export XDG_DATA_HOME=
export XDG_DATA_DIRS=
if ! command -v elvish &>/dev/null && [ -z "$GITHUB_ACTIONS" ]; then
skip 'Elvish not installed'
fi
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)) && [ -z "$GITHUB_ACTIONS" ]; then
skip "Elvish version is not at least 0.18. Found ${ver_major}.${ver_minor}.${ver_patch}"
fi
}
cleaned_path() {
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ' '
}
@test "exports ASDF_DIR" {
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DIR"
[ "$status" -eq 0 ]
[ "$output" = "$HOME/.asdf" ]
}
@test "retains ASDF_DIR" {
run elvish -norc -c "
set-env ASDF_DIR \"/path/to/asdf\"
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DIR"
[ "$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\"
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:ASDF_DATA_DIR"
[ "$status" -eq 0 ]
[ "$output" = "/path/to/asdf-data" ]
}
@test "adds asdf dirs to PATH" {
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "defines the _asdf namespace" {
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
pprint \$_asdf:"
[ "$status" -eq 0 ]
[[ "$output" =~ "<ns " ]]
}
@test "does not add paths to PATH more than once" {
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
echo \$E:PATH"
[ "$status" -eq 0 ]
result=$(echo "$result" | tr ':' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
@test "defines the asdf function" {
run elvish -norc -c "
unset-env ASDF_DIR
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
pprint \$asdf~"
[ "$status" -eq 0 ]
if [ "$(uname)" = "Linux" ]; then
[[ "$output" =~ "<closure " ]]
else
[[ "$output" =~ ^'[^fn ' ]]
fi
}
@test "function calls asdf command" {
run elvish -norc -c "
set-env ASDF_DIR $(pwd) # checkstyle-ignore
set paths = [$(cleaned_path)]
use ./asdf _asdf; var asdf~ = \$_asdf:asdf~
asdf info"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
}