f48bcc336ed5437e687f75364adb8ccb12ff4a1d
[open-adventure.git] / tests / tapdiffer
1 #! /bin/sh
2 #
3 # tapdiffer - Render diff between input and checkfile as a TAP report
4 #
5 # Usage: tapdiffer LEGEND CHECKFILE
6 #
7 # Output is a TAP report, ok if the diff is empty and not ok otherwise.
8 # A nonempty diff is shipped as a TAP YAML block following "not ok" 
9 # unless QUIET=1 in the environment.
10 #
11 if [ "$1" = "-w" ]
12 then
13     diffopts=-ubZ
14     shift
15 else
16     diffopts=-u
17 fi
18
19 legend=$1
20 checkfile=$2
21
22 trap 'rm /tmp/tapdiff$$' EXIT HUP INT QUIT TERM
23
24 if diff --text "${diffopts}" ${checkfile} - >/tmp/tapdiff$$
25 then
26         echo "ok - ${legend}"
27 else
28         echo "not ok - ${checkfile}: ${legend}"
29         if [ ! "${QUIET}" = 1 ]
30         then
31                 echo "  --- |"
32                 sed </tmp/tapdiff$$ -e 's/^/  /'
33                 echo "  ..."
34         fi
35 fi
36
37 # end