]> pd.if.org Git - zpackage/commitdiff
move shell tap functions to separate file
authorNathan Wagner <nw@hydaspes.if.org>
Wed, 28 Sep 2016 00:45:56 +0000 (00:45 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Wed, 28 Sep 2016 00:45:56 +0000 (00:45 +0000)
t/tap.sh [new file with mode: 0755]

diff --git a/t/tap.sh b/t/tap.sh
new file mode 100755 (executable)
index 0000000..23c5299
--- /dev/null
+++ b/t/tap.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+tn=0
+planned=0
+
+tryrun() {
+       note="$@"
+       program=$1
+       shift
+       $program "$@"
+       if [ $? -ne 0 ]; then
+               printf 'not ';
+       fi
+       tn=$((tn + 1))
+       printf 'ok %d - %s %s\n' $tn $program "$*"
+}
+
+shownote() {
+       if [ "$note" != "" ]; then
+               printf '# %s\n' "$note"
+       fi
+}
+
+okexit() {
+       exitwith 0 "$*"
+}
+
+failsok() {
+       note=
+       if [ $? -eq 0 ]; then
+               printf 'not ';
+               note=$(printf '# got "%d" expected "%d"' "$1" "0")
+       fi
+       tn=$((tn + 1))
+       printf 'ok %d - %s\n' $tn "$*"
+       shownote
+}
+
+exitwith() {
+       note=
+       if [ $? -ne $1 ]; then
+               printf 'not ';
+               note=$(printf '# got "%d" expected "%d"' "$1" "$2")
+       fi
+       shift
+       tn=$((tn + 1))
+       printf 'ok %d - %s\n' $tn "$*"
+       shownote
+}
+
+okstreq() {
+       note=
+       if [ "$1" != "$2" ]; then
+               printf 'not ';
+               note=$(printf 'got "%s" expected "%s"' "$1" "$2")
+       fi
+
+       shift;shift;
+       tn=$((tn + 1))
+       printf 'ok %d - %s\n' $tn "$*"
+       shownote
+}
+
+plan() {
+       planned=$1
+       printf '1..%d\n' $planned
+}
+
+finish() {
+       if [ $planned -eq 0 ]; then
+               printf '1..%d\n' $tn
+       fi
+}