xref: /openbsd/regress/usr.bin/jot/regress.m4 (revision 9b7c3dbb)
1# $OpenBSD: regress.m4,v 1.1 2016/07/30 13:55:54 tb Exp $
2# $FreeBSD: head/usr.bin/tests/regress.m4 263227 2014-03-16 08:04:06Z jmmv $
3
4dnl Originally /usr/src/usr.bin/tests/regress.m4 on FreeBSD
5dnl Merged into jot tests for OpenBSD by attila@stalphonsos.com
6
7dnl A library of routines for doing regression tests for userland utilities.
8
9dnl Start up.  We initialise the exit status to 0 (no failure) and change
10dnl into the directory specified by our first argument, which is the
11dnl directory to run the tests inside.
12
13dnl We need backticks and square brackets, use [[ ]] for m4 quoting
14changequote([[,]])
15
16dnl Set some things up before we start running tests
17define([[REGRESSION_START]],
18TESTDIR=$1
19if [ -z "$TESTDIR" ]; then
20  TESTDIR=.
21fi
22cd $TESTDIR
23
24TOTAL=0
25NFAILED=0
26FAILED=""
27STATUS=0
28)
29
30dnl Check $? to see if we passed or failed.  The first parameter is the test
31dnl which passed or failed.  It may be nil.
32define([[REGRESSION_PASSFAIL]],
33if [ $? -eq 0 ]; then
34  echo "ok - $1 # Test detected no regression. (in $TESTDIR)"
35else
36  STATUS=$?
37  NFAILED=`expr 1 + ${NFAILED}`
38  [ -n "${FAILED}" ] && FAILED="${FAILED} "
39  FAILED="${FAILED}$1"
40  SEE_ABOVE=""
41  if [ ${VERBOSE-0} != 0 ]; then
42    diff -u ${SRCDIR:-.}/regress.$1.out ./test.$1.out
43    SEE_ABOVE="See above. "
44  fi
45  echo "not ok - $1 # Test failed: regression detected. ${SEE_ABOVE}(in $TESTDIR)"
46fi)
47
48dnl An actual test.  The first parameter is the test name.  The second is the
49dnl command/commands to execute for the actual test.  Their exit status is
50dnl checked.  It is assumed that the test will output to stdout, and that the
51dnl output to be used to check for regression will be in regress.TESTNAME.out.
52define([[REGRESSION_TEST]],
53TOTAL=`expr 1 + ${TOTAL}`
54$2 >test.$1.out
55diff -q ${SRCDIR:-.}/regress.$1.out ./test.$1.out >/dev/null
56REGRESSION_PASSFAIL($1))
57
58dnl Cleanup.  Exit with the status code of the last failure.  Should probably
59dnl be the number of failed tests, but hey presto, this is what it does.  This
60dnl could also clean up potential droppings, if some forms of regression tests
61dnl end up using mktemp(1) or such.
62define([[REGRESSION_END]],
63if [ ${NFAILED} -ne 0 ]; then
64  echo "FAILED ${NFAILED} tests out of ${TOTAL}: ${FAILED}"
65else
66  echo "PASSED ${TOTAL} tests"
67fi
68exit $STATUS)
69