open-adventure/tests/tapdiffer
2023-03-22 00:05:58 -04:00

37 lines
699 B
Bash
Executable file

#! /bin/sh
#
# tapdiffer - Render diff between input and checkfile as a TAP report
#
# Usage: tapdiffer LEGEND CHECKFILE
#
# Output is a TAP report, ok if the diff is empty and not ok otherwise.
# A nonempty diff is shipped as a TAP YAML block following "not ok"
# unless QUIET=1 in the environment.
#
if [ "$1" = "-w" ]
then
diffopts=-ubZ
shift
else
diffopts=-u
fi
legend=$1
checkfile=$2
trap 'rm /tmp/tapdiff$$' EXIT HUP INT QUIT TERM
if diff --text "${diffopts}" ${checkfile} - >/tmp/tapdiff$$
then
echo "ok - ${legend}"
else
echo "not ok - ${checkfile}: ${legend}"
if [ ! "${QUIET}" = 1 ]
then
echo " --- |"
sed </tmp/tapdiff$$ -e 's/^/ /'
echo " ..."
fi
fi
# end