-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtldr.bats
executable file
·204 lines (178 loc) · 7.52 KB
/
tldr.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env bats
# Tests expect the envvar PATH_TO_TLDR_CLIENT to be set, exits if not.
# If an update command exists, do it before running through tests.
setup_file() {
if [[ -z $PATH_TO_TLDR_CLIENT ]]
then
echo "Expected envvar PATH_TO_TLDR_CLIENT to be set. Exiting!"
return 1
fi
$PATH_TO_TLDR_CLIENT --update || :
}
# Set the language envvars to English explicitly.
setup() {
export LANG="en_US.UTF-8"
export LANGUAGE="en_GB:en"
echo -e "Running test suite for $PATH_TO_TLDR_CLIENT\n"
}
# Don't include curly braces in tests, clients are free to remove/replace them.
# bats test_tags=required
@test "REQUIRED: show tldr-page for tldr" {
run $PATH_TO_TLDR_CLIENT tldr
[[ $? -eq 0 ]]
[[ "$output" = *"Display simple help pages for command-line tools from the tldr-pages project."* ]]
[[ "$output" = *"https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#command-line-interface"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#page-names
# bats test_tags=required
@test "REQUIRED: show tldr-page for TLDR (must be treated as lowercase)" {
run $PATH_TO_TLDR_CLIENT TLDR
[[ $? -eq 0 ]]
[[ "$output" = *"Display simple help pages for command-line tools from the tldr-pages project."* ]]
[[ "$output" = *"https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#command-line-interface"* ]]
}
# bats test_tags=required
@test "REQUIRED: show tldr-page for git-switch (hyphenated page names)" {
run $PATH_TO_TLDR_CLIENT git-switch
[[ $? -eq 0 ]]
[[ "$output" = *"Switch between Git branches. Requires Git version 2.23+."* ]]
[[ "$output" = *"https://git-scm.com/docs/git-switch"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#page-names
# bats test_tags=required
@test "REQUIRED: show tldr-page for git switch (hyphen is implied and must be inserted transparently)" {
run $PATH_TO_TLDR_CLIENT git switch
[[ $? -eq 0 ]]
[[ "$output" = *"Switch between Git branches. Requires Git version 2.23+."* ]]
[[ "$output" = *"https://git-scm.com/docs/git-switch"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#if-a-page-is-not-found
# bats test_tags=required
@test "REQUIRED: non-zero exit status for page that does not exist" {
run $PATH_TO_TLDR_CLIENT this-page-will-never-exist
[[ $status -ne 0 ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#page-names
# bats test_tags=required
@test "REQUIRED: non-zero exit status when page that does exist is not first argument" {
run $PATH_TO_TLDR_CLIENT this-page-will-never-exist tldr
[[ $status -ne 0 ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=required
@test "REQUIRED: show client version with --version" {
run $PATH_TO_TLDR_CLIENT --version
[[ $? -eq 0 ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=required
@test "REQUIRED: show client version with -v (version shorthand)" {
run $PATH_TO_TLDR_CLIENT -v
[[ $? -eq 0 ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=required
@test "REQUIRED: show platform specific version of page with --platform" {
run $PATH_TO_TLDR_CLIENT --platform windows mkdir
[[ $? -eq 0 ]]
[[ "$output" = *"Creates a directory."* ]]
[[ "$output" = *"https://learn.microsoft.com/windows-server/administration/windows-commands/mkdir"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=required
@test "REQUIRED: show platform specific version of page with -p (platform shorthand)" {
run $PATH_TO_TLDR_CLIENT -p windows mkdir
[[ $? -eq 0 ]]
[[ "$output" = *"Creates a directory."* ]]
[[ "$output" = *"https://learn.microsoft.com/windows-server/administration/windows-commands/mkdir"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=required
@test "REQUIRED: non-zero exit status with -p (platform shorthand) should error without value" {
run $PATH_TO_TLDR_CLIENT -p
[[ $status -ne 0 ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=required
@test "REQUIRED: non-zero exit status with --platform (platform) should error without value" {
run $PATH_TO_TLDR_CLIENT --platform
[[ $status -ne 0 ]]
}
# If the -l or --list argument is supported, it must show one command per line.
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=required
@test "REQUIRED: if list argument supported, output shows one page per line (succeeds if not supported)" {
run $PATH_TO_TLDR_CLIENT --list
if [[ $status -ne 0 ]]
then
return 0
fi
LINES=$(echo "$output" | wc -l)
[[ $LINES -gt 1 ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#language
# bats test_tags=required
@test "REQUIRED: if LANG and LANGUAGE envvars are set to a supported language, output must use that language" {
export LANG="nl.UTF-8"
export LANGUAGE="nl"
$PATH_TO_TLDR_CLIENT --update || :
run $PATH_TO_TLDR_CLIENT 7z
[[ $status -eq 0 ]]
[[ "$output" = *"7z"* ]]
[[ "$output" = *"Een bestandsarchiveerder met een hoge compressieratio."* ]]
[[ "$output" = *"https://manned.org/7z"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#language
# bats test_tags=required
@test "REQUIRED: if LANG and LANGUAGE envvars are not set, output must be in English" {
export LANG=""
export LANGUAGE=""
run $PATH_TO_TLDR_CLIENT 7z
[[ $status -eq 0 ]]
[[ "$output" = *"7z"* ]]
[[ "$output" = *"File archiver with a high compression ratio."* ]]
[[ "$output" = *"https://manned.org/7z"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=optional
@test "OPTIONAL: supports --list argument to list all pages" {
run $PATH_TO_TLDR_CLIENT --list
[[ "$output" = *"tldr"* ]]
[[ "$output" = *"apt"* ]]
[[ "$output" = *"mkdir"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=optional
@test "OPTIONAL: supports -l (list shorthand) argument to list all pages" {
run $PATH_TO_TLDR_CLIENT --list
[[ "$output" = *"tldr"* ]]
[[ "$output" = *"apt"* ]]
[[ "$output" = *"mkdir"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=optional
@test "OPTIONAL: supports --language argument" {
run $PATH_TO_TLDR_CLIENT --language nl 7z
[[ $status -eq 0 ]]
[[ "$output" = *"7z"* ]]
[[ "$output" = *"Een bestandsarchiveerder met een hoge compressieratio."* ]]
[[ "$output" = *"https://manned.org/7z"* ]]
}
# Source: https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#arguments
# bats test_tags=optional
@test "OPTIONAL: supports -L (language shorthand) argument" {
run $PATH_TO_TLDR_CLIENT -L nl 7z
[[ $status -eq 0 ]]
[[ "$output" = *"7z"* ]]
[[ "$output" = *"Een bestandsarchiveerder met een hoge compressieratio."* ]]
[[ "$output" = *"https://manned.org/7z"* ]]
}
# https://github.com/tldr-pages/tldr/blob/main/CLIENT-SPECIFICATION.md#directory-structure
# bats_test_tags=recommends
@test "RECOMMENDS: treats macos platform as osx" {
run $PATH_TO_TLDR_CLIENT --platform macos applecamerad
[[ $status -eq 0 ]]
[[ "$output" = *"applecamerad"* ]]
[[ "$output" = *"Camera manager."* ]]
[[ "$output" = *"https://www.theiphonewiki.com/wiki/Services"* ]]
}