forked from asdf-vm/asdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasdf_pwsh.bats
96 lines (76 loc) · 2.06 KB
/
asdf_pwsh.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
#!/usr/bin/env bats
# shellcheck disable=SC2164
load test_helpers
setup() {
cd "$(dirname "$BATS_TEST_DIRNAME")"
if ! command -v pwsh &>/dev/null && [ -z "$GITHUB_ACTIONS" ]; then
skip "Powershell Core is not installed"
fi
}
cleaned_path() {
echo "$PATH" | tr ':' '\n' | grep -v "asdf" | tr '\n' ':'
}
@test "exports ASDF_DIR" {
run pwsh -Command "
function asdf() {} # checkstyle-ignore
Remove-item Function:asdf
\$Env:ASDF_DIR = ''
\$Env:ASDF_DATA_DIR = ''
\$Env:PATH = \"$(cleaned_path)\"
. ./asdf.ps1
Write-Output \"\$env:ASDF_DIR\""
[ "$status" -eq 0 ]
[ "$output" != "" ]
}
@test "adds asdf dirs to PATH" {
run pwsh -Command "
function asdf() {} # checkstyle-ignore
Remove-item Function:asdf
\$Env:ASDF_DIR = ''
\$Env:ASDF_DATA_DIR = ''
\$Env:PATH = \"$(cleaned_path)\"
. ./asdf.ps1
Write-Output \$Env:PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "asdf")
[ "$result" != "" ]
}
@test "does not add paths to PATH more than once" {
run pwsh -Command "
function asdf() {} # checkstyle-ignore
Remove-item Function:asdf
\$Env:ASDF_DIR = ''
\$Env:ASDF_DATA_DIR = ''
\$Env:PATH = \"$(cleaned_path)\"
. ./asdf.ps1
. ./asdf.ps1
Write-Output \$Env:PATH"
[ "$status" -eq 0 ]
result=$(echo "$output" | tr ' ' '\n' | grep "asdf" | sort | uniq -d)
[ "$result" = "" ]
}
@test "defines the asdf function" {
run pwsh -Command "
function asdf() {} # checkstyle-ignore
Remove-item Function:asdf
\$Env:ASDF_DIR = ''
\$Env:ASDF_DATA_DIR = ''
\$Env:PATH = \"$(cleaned_path)\"
./ asdf.ps1
\$(Get-Command -CommandType asdf).Name"
[ "$status" -eq 0 ]
[[ "$output" =~ "asdf" ]]
}
@test "function calls asdf command" {
run pwsh -Command "
function asdf() {} # checkstyle-ignore
Remove-item Function:asdf
\$Env:ASDF_DIR = ''
\$Env:ASDF_DATA_DIR = ''
\$Env:PATH = \"$(cleaned_path)\"
. ./asdf.ps1
asdf info"
[ "$status" -eq 0 ]
result=$(echo "$output" | grep "ASDF INSTALLED PLUGINS:")
[ "$result" != "" ]
}