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