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
| fails=0 checks=0
check() { name=$1; shift
checks=$((checks + 1))
if "$@"; then echo "dash-test: ok $name"
else echo "dash-test: FAIL $name"; fails=$((fails + 1)); fi
}
eq() { [ "$1" = "$2" ] || { echo " got '$1', want '$2'"; return 1; }; }
echo "dash-test: dash running, pid $$"
x=6
check arithmetic eq "$((x * 7))" 42
s=; for i in 1 2 3; do s="$s$i"; done
check for-loop eq "$s" 123
f() { echo "$#:$*"; return 3; }
out=$(f a b c); st=$?
check function-and-return eq "$out/$st" "3:a b c/3"
case foo.txt in *.txt) c=yes ;; *) c=no ;; esac
check case-glob eq "$c" yes
n=0; for p in /mnt/disk0/bin/*; do n=$((n + 1)); done
echo "dash-test: $n programs in /mnt/disk0/bin"
check pipe-to-rust-grep eq "$(printf 'apple\nbanana\n' | grep ban)" banana
echo "written by dash" > /tmp/dash-test.txt
read line < /tmp/dash-test.txt
check redirect-and-read eq "$line" "written by dash"
cat /tmp/no-such-file 2>/dev/null; st=$?
check missing-file-status [ "$st" -ne 0 ]
heredoc=$(cat <<END
here $x
END
)
check here-document eq "$heredoc" "here 6"
(exit 7); st=$?
check subshell-exit-status eq "$st" 7
sleep 1 &
bg=$!
wait "$bg"; st=$?
check background-and-wait eq "$st" 0
tests() { [ -d /tmp ] && [ -x /mnt/disk0/bin/dash ] && [ ! -e /tmp/nope ]; }
check test-builtins tests
got=; trap 'got=USR1' USR1; kill -USR1 $$
check trap-signal eq "$got" USR1
rm /tmp/dash-test.txt
check rm-rust-tool [ ! -e /tmp/dash-test.txt ]
v=$(sh_var=inner; echo "$sh_var"); check command-substitution eq "$v" inner
set -- one "two words" three
check positional-params eq "$#:$2" "3:two words"
if [ $fails = 0 ]; then echo "dash-test: all $checks checks passed"
else echo "dash-test: $fails of $checks checks FAILED"; fi
exit $fails
|