]> pd.if.org Git - zpackage/blob - t/tap.sh
add required test to tap
[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 "$@"
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 okexit() {
39         exitwith 0 "$*"
40 }
41
42 failsok() {
43         rv=$?
44         note=
45         if [ $rv -eq 0 ]; then
46                 printf 'not ';
47                 note=$(printf 'got "%d" expected "%d"' "$rv" "0")
48         fi
49         tn=$((tn + 1))
50         printf 'ok %d - %s\n' $tn "$*"
51         shownote
52 }
53
54 exitwith() {
55         rv=$?
56         note=
57         if [ $rv -ne $1 ]; then
58                 printf 'not ';
59                 note=$(printf '# got "%d" expected "%d"' "$1" "$2")
60         fi
61         shift
62         tn=$((tn + 1))
63         printf 'ok %d - %s\n' $tn "$*"
64         shownote
65 }
66
67 okstreq() {
68         note=
69         if [ "$1" != "$2" ]; then
70                 printf 'not ';
71                 note=$(printf 'got "%s" expected "%s"' "$1" "$2")
72         fi
73
74         shift;shift;
75         tn=$((tn + 1))
76         printf 'ok %d - %s\n' $tn "$*"
77         shownote
78 }
79
80 plan() {
81         planned=$1
82         printf '1..%d\n' $planned
83 }
84
85 finish() {
86         if [ $planned -eq 0 ]; then
87                 printf '1..%d\n' $tn
88         fi
89 }