495427e6aa5b8cccb272f4a4dc1b7c2f14c62095
[open-adventure.git] / tests / tapdiffer
1 #! /bin/sh
2 # SPDX-FileCopyrightText: Eric S. Raymond <esr@thyrsus.com>
3 # SPDX-License-Identifier: MIT-0
4 #
5 # tapdiffer - Render diff between input and checkfile as a TAP report
6 #
7 # Usage: tapdiffer LEGEND CHECKFILE
8 #
9 # Output is a TAP report, ok if the diff is empty and not ok otherwise.
10 # A nonempty diff is shipped as a TAP YAML block following "not ok" 
11 # unless QUIET=1 in the environment.
12 #
13 # This code is intended to be embedded in your project. The author
14 # grants permission for it to be distributed under the prevailing
15 # license of your project if you choose, provided that license is
16 # OSD-compliant; otherwise the following SPDX tag incorporates the
17 # MIT No Attribution license by reference.
18 #
19 # A newer version may be available at https://gitlab.com/esr/tapview
20 # Check your last commit dqte for this file against the commit list
21 # there to see if it might be a good idea to update.
22 #
23 if [ "$1" = "-b" ]
24 then
25     diffopts=-ub
26     shift
27 else
28     diffopts=-u
29 fi
30
31 legend=$1
32 checkfile=$2
33
34 trap 'rm /tmp/tapdiff$$' EXIT HUP INT QUIT TERM
35
36 if diff --text "${diffopts}" "${checkfile}" - >/tmp/tapdiff$$
37 then
38         echo "ok - ${legend}"
39 else
40         echo "not ok - ${checkfile}: ${legend}"
41         if [ ! "${QUIET}" = 1 ]
42         then
43                 echo "  --- |"
44                 sed </tmp/tapdiff$$ -e 's/^/  /'
45                 echo "  ..."
46         fi
47 fi
48
49 # end