forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasdf_nu.bats
175 lines (127 loc) · 3.54 KB
/
asdf_nu.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bats
# shellcheck disable=SC2164
load test_helpers
setup() {
cd "$(dirname "$BATS_TEST_DIRNAME")"
if ! command -v nu &>/dev/null && [ -z "$GITHUB_ACTIONS" ]; then
skip "Nu is not installed"
fi
setup_asdf_dir
}
teardown() {
clean_asdf_dir
}
cleaned_path() {
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ':'
}
run_nushell() {
run nu -c "
hide-env -i asdf
hide-env -i ASDF_DIR
\$env.PATH = ( '$(cleaned_path)' | split row ':' )
\$env.ASDF_DIR = '$PWD'
source asdf.nu
$1"
}
@test "exports ASDF_DIR" {
run_nushell "echo \$env.ASDF_DIR"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "asdf")
[ "$result" = "$PWD" ]
}
@test "adds asdf dirs to PATH" {
run_nushell "\$env.PATH | to text"
[ "$status" -eq 0 ]
[[ "$output" == *"$PWD/bin"* ]]
[[ "$output" == *"$HOME/.asdf/shims"* ]]
}
@test "does not add paths to PATH more than once" {
run_nushell "
source asdf.nu
echo \$env.PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
@test "retains ASDF_DIR (from ASDF_NU_DIR)" {
run nu -c "
hide-env -i asdf
\$env.ASDF_DIR = ( pwd )
\$env.PATH = ( '$(cleaned_path)' | split row ':' )
\$env.ASDF_NU_DIR = '$PWD'
source asdf.nu
echo \$env.ASDF_DIR"
[ "$status" -eq 0 ]
[ "$output" = "$PWD" ]
}
@test "retains ASDF_DIR (from ASDF_DIR)" {
run nu -c "
hide-env -i asdf
\$env.ASDF_DIR = ( pwd )
\$env.PATH = ( '$(cleaned_path)' | split row ':' )
\$env.ASDF_DIR = '$PWD'
source asdf.nu
echo \$env.ASDF_DIR"
[ "$status" -eq 0 ]
[ "$output" = "$PWD" ]
}
@test "defines the asdf or main function" {
run_nushell "which asdf | get path | to text"
[ "$status" -eq 0 ]
}
@test "function calls asdf command" {
run_nushell "asdf info"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
}
@test "parses the output of asdf plugin list" {
setup_repo
install_dummy_plugin
run_nushell "asdf plugin list | to csv -n"
[ "$status" -eq 0 ]
[ "$output" = "dummy" ]
}
@test "parses the output of asdf plugin list --urls" {
setup_repo
install_mock_plugin_repo "dummy"
asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
run_nushell "asdf plugin list --urls | to csv -n"
[ "$status" -eq 0 ]
local repo_url
repo_url=$(get_plugin_remote_url "dummy")
[ "$output" = "dummy,$repo_url" ]
}
@test "parses the output of asdf plugin list --refs" {
setup_repo
install_mock_plugin_repo "dummy"
asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
run_nushell "asdf plugin list --refs | to csv -n"
[ "$status" -eq 0 ]
local branch gitref
branch=$(get_plugin_remote_branch "dummy")
gitref=$(get_plugin_remote_gitref "dummy")
[ "$output" = "dummy,$branch,$gitref" ]
}
@test "parses the output of asdf plugin list --urls --refs" {
setup_repo
install_mock_plugin_repo "dummy"
asdf plugin add "dummy" "${BASE_DIR}/repo-dummy"
run_nushell "asdf plugin list --urls --refs | to csv -n"
[ "$status" -eq 0 ]
local repo_url branch gitref
repo_url=$(get_plugin_remote_url "dummy")
branch=$(get_plugin_remote_branch "dummy")
gitref=$(get_plugin_remote_gitref "dummy")
[ "$output" = "dummy,$repo_url,$branch,$gitref" ]
}
@test "parses the output of asdf plugin list all" {
setup_repo
install_dummy_plugin
run_nushell "asdf plugin list all | to csv -n"
[ "$status" -eq 0 ]
[ "$output" = "\
bar,false,http://example.com/bar
dummy,true,http://example.com/dummy
foo,false,http://example.com/foo" ]
}