| 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 |
# This code is intended to be embedded in your project. The author |
| 12 |
# grants permission for it to be distributed under the prevailing |
| 13 |
# license of your project if you choose, provided that license is |
| 14 |
# OSD-compliant; otherwise the following SPDX tag incorporates the |
| 15 |
# MIT No Attribution license by reference. |
| 16 |
# |
| 17 |
# SPDX-FileCopyrightText: (C) Eric S. Raymond <[email protected]> |
| 18 |
# SPDX-License-Identifier: MIT-0 |
| 19 |
# |
| 20 |
# A newer version may be available at https://gitlab.com/esr/tapview |
| 21 |
# Check your last commit dqte for this file against the commit list |
| 22 |
# there to see if it might be a good idea to update. |
| 23 |
# |
| 24 |
diffopts=-u |
| 25 |
while getopts bn opt |
| 26 |
do |
| 27 |
case $opt in |
| 28 |
b) diffopts=-ub;; |
| 29 |
*) echo "tapdiffer: unknown option ${opt}."; exit 1;; |
| 30 |
esac |
| 31 |
done |
| 32 |
# shellcheck disable=SC2004 |
| 33 |
shift $(($OPTIND - 1)) |
| 34 |
|
| 35 |
legend=$1 |
| 36 |
checkfile=$2 |
| 37 |
|
| 38 |
trap 'rm /tmp/tapdiff$$' EXIT HUP INT QUIT TERM |
| 39 |
|
| 40 |
if diff --text "${diffopts}" "${checkfile}" - >/tmp/tapdiff$$ |
| 41 |
then |
| 42 |
echo "ok - ${legend}" |
| 43 |
else |
| 44 |
echo "not ok - ${legend}" |
| 45 |
if [ ! "${QUIET}" = 1 ] |
| 46 |
then |
| 47 |
echo " --- |" |
| 48 |
sed </tmp/tapdiff$$ -e 's/^/ /' |
| 49 |
echo " ..." |
| 50 |
fi |
| 51 |
fi |
| 52 |
|
| 53 |
# end |