]> pd.if.org Git - zpackage/blob - t/tap.sh
add tests for more package installs
[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         tap_return_value=$?
12         if [ $tap_return_value -ne 0 ]; then
13                 printf 'not ';
14         fi
15         tn=$((tn + 1))
16         printf 'ok %d - %s %s\n' $tn $program "$*"
17         if [ $tap_return_value -ne 0 ]; then
18                 cat test.out | diagstdin
19         fi
20         return $tap_return_value
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         return $rv
92 }
93
94 okstreq() {
95         note=
96         if [ "$1" != "$2" ]; then
97                 printf 'not ';
98                 note=$(printf 'got "%s" expected "%s"' "$1" "$2")
99         fi
100
101         shift;shift;
102         tn=$((tn + 1))
103         printf 'ok %d - %s\n' $tn "$*"
104         shownote
105 }
106
107 plan() {
108         planned=$1
109         printf '1..%d\n' $planned
110 }
111
112 finish() {
113         if [ $planned -eq 0 ]; then
114                 printf '1..%d\n' $tn
115         fi
116 }
117
118 skip() {
119         tap_skipping=$1
120         shift
121         while [ $tap_skipping -gt 0 ]; do
122                 tn=$((tn + 1))
123                 tap_skipping=$((tap_skipping - 1))
124                 printf 'ok %d - skip %s\n' $tn "$*"
125         done
126 }