-
Notifications
You must be signed in to change notification settings - Fork 49
/
test
executable file
·75 lines (60 loc) · 1.32 KB
/
test
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
#!/bin/bash
tests=(
'tldr -h'
'tldr tar'
'tldr abcdefg'
'tldr git config'
'tldr --list'
)
if [ "$TLDR_NETWORK_TESTS" = "true" ]; then
tests+=(
'tldr -u; printf "Update exit code: %d\n" $?'
)
fi
run_all() {
target=$1
shift
ln -sf "$target" .tldr-ephemeral-runner
for t in "$@"; do
./${t/tldr/.tldr-ephemeral-runner} 2>/dev/null
done
rm .tldr-ephemeral-runner
}
expected=$(run_all ./tldr "${tests[@]}")
test_shell() {
shell=$1
tldr=./.tldr--$shell
shellPath="$(command -v $shell)"
if [ -z "$shellPath" ]; then
false
return
fi
# the next line is, y'know, annoying, but it's a reliable way to
# guarantee we run under that shell
sed "1s:#!/bin/bash:#!$shellPath:" ./tldr >$tldr
chmod +x $tldr
result=$(run_all $tldr "${tests[@]}")
rm $tldr
if [ "$result" != "$expected" ]; then
diff -U 0 <(echo "$expected") <(echo "$result") |
tail +4 >fail-$shell.log
false
else
true
fi
}
test_shells() {
fmt="%s\t%s\n"
for shell in "$@"; do
if test_shell $shell; then
printf $fmt $shell PASS
else
printf $fmt $shell FAIL
fi
done
}
# On Debian based distros, most of these shells can be installed via:
# sudo apt install csh tcsh bash dash ksh zsh
# `gosh` is written in Go, and can be installed using:
# go install mvdan.cc/sh/v3/cmd/gosh@latest
test_shells sh bash dash zsh ksh csh tcsh gosh