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