X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=t%2Ftap.sh;h=e3a345784092fb12475e02d4bdd2b4395ae76cd4;hb=27f7fa2a8566beb45fc813fcd8ff3f1e7c738883;hp=0d03831bcf03cbb41d63ba198d8ab1f0a96f61a5;hpb=4f60c538ec7111597176984e32d3996e4b5adb17;p=zpackage diff --git a/t/tap.sh b/t/tap.sh index 0d03831..e3a3457 100755 --- a/t/tap.sh +++ b/t/tap.sh @@ -4,37 +4,41 @@ tn=0 planned=0 tryrun() { - note="$@" + if [ "$1" = "-v" ]; then + allout=1 + shift + else + allout=0 + fi + program=$1 shift + $program "$@" > test.out 2>&1 - rv=$? - if [ $rv -ne 0 ]; then + tap_rv=$? + tn=$((tn + 1)) + + if [ $tap_rv -ne 0 ]; then printf 'not '; fi - tn=$((tn + 1)) printf 'ok %d - %s %s\n' $tn $program "$*" - if [ $rv -ne 0 ]; then - cat test.out | diagstdin + + if [ $allout -eq 1 ] || [ $tap_rv -ne 0 ]; then + if test -s test.out; then + cat test.out | diagstdin + fi + rm test.out fi - return $rv + + return $tap_rv } require() { - note="$*" - program=$1 - shift - $program "$@" > test.out 2>&1 + tryrun "$@" rv=$? - tn=$((tn + 1)) if [ $rv -ne 0 ]; then - printf 'not ok %d - %s %s\n' $tn $program "$*" - cat test.out | diagstdin - rm test.out bailout "exit status $rv"; fi - printf 'ok %d - %s %s\n' $tn $program "$*" - } bailout() { @@ -70,7 +74,7 @@ failsok() { note= if [ $rv -eq 0 ]; then printf 'not '; - note=$(printf 'got "%d" expected "%d"' "$rv" "0") + note=$(printf 'got "%d" expected non-zero' "$rv") fi tn=$((tn + 1)) printf 'ok %d - %s\n' $tn "$*" @@ -88,13 +92,14 @@ exitwith() { tn=$((tn + 1)) printf 'ok %d - %s\n' $tn "$*" shownote + return $rv } okstreq() { note= if [ "$1" != "$2" ]; then printf 'not '; - note=$(printf 'got "%s" expected "%s"' "$1" "$2") + note=$(printf 'got "%s"\n# expected "%s"' "$1" "$2") fi shift;shift; @@ -120,6 +125,26 @@ skip() { while [ $tap_skipping -gt 0 ]; do tn=$((tn + 1)) tap_skipping=$((tap_skipping - 1)) - printf 'ok %d - skip %s\n' $tn "$*" + printf 'ok %d - # skip %s\n' $tn "$*" + #ok '# skip ' "$*" done } + +ok() { + rv=$1 + shift + if [ $rv = 1 ]; then + printf 'not ' + fi + tn=$((tn + 1)) + printf 'ok %d - %s\n' $tn "$*" + return $rv +} + +pass() { + ok 0 "$@" +} + +fail() { + ok 1 "$@" +}