]> pd.if.org Git - zpackage/blob - t/tap.sh
move shell tap functions to separate file
[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 shownote() {
19         if [ "$note" != "" ]; then
20                 printf '# %s\n' "$note"
21         fi
22 }
23
24 okexit() {
25         exitwith 0 "$*"
26 }
27
28 failsok() {
29         note=
30         if [ $? -eq 0 ]; then
31                 printf 'not ';
32                 note=$(printf '# got "%d" expected "%d"' "$1" "0")
33         fi
34         tn=$((tn + 1))
35         printf 'ok %d - %s\n' $tn "$*"
36         shownote
37 }
38
39 exitwith() {
40         note=
41         if [ $? -ne $1 ]; then
42                 printf 'not ';
43                 note=$(printf '# got "%d" expected "%d"' "$1" "$2")
44         fi
45         shift
46         tn=$((tn + 1))
47         printf 'ok %d - %s\n' $tn "$*"
48         shownote
49 }
50
51 okstreq() {
52         note=
53         if [ "$1" != "$2" ]; then
54                 printf 'not ';
55                 note=$(printf 'got "%s" expected "%s"' "$1" "$2")
56         fi
57
58         shift;shift;
59         tn=$((tn + 1))
60         printf 'ok %d - %s\n' $tn "$*"
61         shownote
62 }
63
64 plan() {
65         planned=$1
66         printf '1..%d\n' $planned
67 }
68
69 finish() {
70         if [ $planned -eq 0 ]; then
71                 printf '1..%d\n' $tn
72         fi
73 }