]> pd.if.org Git - zpackage/blob - t/tap.sh
use lzma from xz 5.2.4
[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         if [ $? -ne 0 ]; then
12                 printf 'not ';
13         fi
14         tn=$((tn + 1))
15         printf 'ok %d - %s %s\n' $tn $program "$*"
16 }
17
18 require() {
19         note="$@"
20         program=$1
21         shift
22         $program "$@" >> test.out 2>&1
23         rv=$?
24         if [ $rv -ne 0 ]; then
25                 diag "bailing on $((tn + 1)) $program $*"
26                 printf "bail out! fail[$rv]: $@\n"
27                 exit 255;
28         fi
29         tn=$((tn + 1))
30         printf 'ok %d - %s %s\n' $tn $program "$*"
31
32 }
33
34 shownote() {
35         if [ "$note" != "" ]; then
36                 printf '# %s\n' "$note"
37         fi
38 }
39
40 diag() {
41         printf '# %s\n' "$@"
42 }
43
44 okexit() {
45         exitwith 0 "$*"
46 }
47
48 failsok() {
49         rv=$?
50         note=
51         if [ $rv -eq 0 ]; then
52                 printf 'not ';
53                 note=$(printf 'got "%d" expected "%d"' "$rv" "0")
54         fi
55         tn=$((tn + 1))
56         printf 'ok %d - %s\n' $tn "$*"
57         shownote
58 }
59
60 exitwith() {
61         rv=$?
62         note=
63         if [ $rv -ne $1 ]; then
64                 printf 'not ';
65                 note=$(printf '# got "%d" expected "%d"' "$rv" "$1")
66         fi
67         shift
68         tn=$((tn + 1))
69         printf 'ok %d - %s\n' $tn "$*"
70         shownote
71 }
72
73 okstreq() {
74         note=
75         if [ "$1" != "$2" ]; then
76                 printf 'not ';
77                 note=$(printf 'got "%s" expected "%s"' "$1" "$2")
78         fi
79
80         shift;shift;
81         tn=$((tn + 1))
82         printf 'ok %d - %s\n' $tn "$*"
83         shownote
84 }
85
86 plan() {
87         planned=$1
88         printf '1..%d\n' $planned
89 }
90
91 finish() {
92         if [ $planned -eq 0 ]; then
93                 printf '1..%d\n' $tn
94         fi
95 }