Ready to ship 2.8
[super-star-trek.git] / test / tapdiffer
1 #! /bin/sh
2 # SPDX-FileCopyrightText: (C) 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 diffopts=-u
24 while getopts bn opt
25 do
26     case $opt in
27         b) diffopts=-ub;;
28         *) echo "tapdiffer: unknown option ${opt}."; exit 1;;
29     esac
30 done
31 # shellcheck disable=SC2004
32 shift $(($OPTIND - 1))
33
34 legend=$1
35 checkfile=$2
36
37 trap 'rm /tmp/tapdiff$$' EXIT HUP INT QUIT TERM
38
39 if diff --text "${diffopts}" "${checkfile}" - >/tmp/tapdiff$$
40 then
41         echo "ok - ${legend}"
42 else
43         echo "not ok - ${legend}"
44         if [ ! "${QUIET}" = 1 ]
45         then
46                 echo "  --- |"
47                 sed </tmp/tapdiff$$ -e 's/^/  /'
48                 echo "  ..."
49         fi
50 fi
51
52 # end