]> pd.if.org Git - zpackage/blob - t/tap.sh
add test file for install
[zpackage] / t / tap.sh
1 #!/bin/sh
2
3 tn=0
4 planned=0
5
6 tryrun() {
7         note="$@"
8         program=$1
9         shift
10         $program "$@" > test.out 2>&1
11         rv=$?
12         if [ $rv -ne 0 ]; then
13                 printf 'not ';
14         fi
15         tn=$((tn + 1))
16         printf 'ok %d - %s %s\n' $tn $program "$*"
17         if [ $rv -ne 0 ]; then
18                 cat test.out | diagstdin
19         fi
20         return $rv
21 }
22
23 require() {
24         note="$*"
25         program=$1
26         shift
27         $program "$@" > test.out 2>&1
28         rv=$?
29         tn=$((tn + 1))
30         if [ $rv -ne 0 ]; then
31                 printf 'not ok %d - %s %s\n' $tn $program "$*"
32                 cat test.out | diagstdin
33                 rm test.out
34                 bailout "exit status $rv";
35         fi
36         printf 'ok %d - %s %s\n' $tn $program "$*"
37
38 }
39
40 bailout() {
41         diag "$@"
42         printf "bail out!\n";
43         exit 255;
44 }
45
46 shownote() {
47         if [ "$note" != "" ]; then
48                 printf '# %s\n' "$note"
49         fi
50 }
51
52 diag() {
53         printf '# %s\n' "$@"
54 }
55
56 diagfile() {
57         sed -e 's/^/# /' $1
58 }
59
60 diagstdin() {
61         sed -e 's/^/# /'
62 }
63
64 okexit() {
65         exitwith 0 "$*"
66 }
67
68 failsok() {
69         rv=$?
70         note=
71         if [ $rv -eq 0 ]; then
72                 printf 'not ';
73                 note=$(printf 'got "%d" expected "%d"' "$rv" "0")
74         fi
75         tn=$((tn + 1))
76         printf 'ok %d - %s\n' $tn "$*"
77         shownote
78 }
79
80 exitwith() {
81         rv=$?
82         note=
83         if [ $rv -ne $1 ]; then
84                 printf 'not ';
85                 note=$(printf 'got "%d" expected "%d"' "$rv" "$1")
86         fi
87         shift
88         tn=$((tn + 1))
89         printf 'ok %d - %s\n' $tn "$*"
90         shownote
91 }
92
93 okstreq() {
94         note=
95         if [ "$1" != "$2" ]; then
96                 printf 'not ';
97                 note=$(printf 'got "%s" expected "%s"' "$1" "$2")
98         fi
99
100         shift;shift;
101         tn=$((tn + 1))
102         printf 'ok %d - %s\n' $tn "$*"
103         shownote
104 }
105
106 plan() {
107         planned=$1
108         printf '1..%d\n' $planned
109 }
110
111 finish() {
112         if [ $planned -eq 0 ]; then
113                 printf '1..%d\n' $tn
114         fi
115 }
116
117 skip() {
118         tap_skipping=$1
119         shift
120         while [ $tap_skipping -gt 0 ]; do
121                 tn=$((tn + 1))
122                 tap_skipping=$((tap_skipping - 1))
123                 printf 'ok %d - skip %s\n' $tn "$*"
124         done
125 }