xref: /freebsd/usr.bin/tests/regress.m4 (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1
2dnl A library of routines for doing regression tests for userland utilities.
3
4dnl Start up.  We initialise the exit status to 0 (no failure) and change
5dnl into the directory specified by our first argument, which is the
6dnl directory to run the tests inside.
7define(`REGRESSION_START',
8TESTDIR=$1
9if [ -z "$TESTDIR" ]; then
10  TESTDIR=.
11fi
12cd $TESTDIR
13
14STATUS=0)
15
16dnl Check $? to see if we passed or failed.  The first parameter is the test
17dnl which passed or failed.  It may be nil.
18define(`REGRESSION_PASSFAIL',
19if [ $? -eq 0 ]; then
20  echo "ok - $1 # Test detected no regression. (in $TESTDIR)"
21else
22  STATUS=$?
23  echo "not ok - $1 # Test failed: regression detected.  See above. (in $TESTDIR)"
24fi)
25
26dnl An actual test.  The first parameter is the test name.  The second is the
27dnl command/commands to execute for the actual test.  Their exit status is
28dnl checked.  It is assumed that the test will output to stdout, and that the
29dnl output to be used to check for regression will be in regress.TESTNAME.out.
30define(`REGRESSION_TEST',
31$2 | diff -u ${SRCDIR:-.}/regress.$1.out -
32REGRESSION_PASSFAIL($1))
33
34dnl A freeform regression test.  Only exit status is checked.
35define(`REGRESSION_TEST_FREEFORM',
36$2
37REGRESSION_PASSFAIL($1))
38
39dnl A regression test like REGRESSION_TEST, except only regress.out is used
40dnl for checking output differences.  The first argument is the command, the
41dnl second argument (which may be empty) is the test name.
42define(`REGRESSION_TEST_ONE',
43$1 | diff -u ${SRCDIR:-.}/regress.out -
44REGRESSION_PASSFAIL($2))
45
46dnl A fatal error.  This will exit with the given status (first argument) and
47dnl print the message (second argument) prefixed with the string "FATAL :" to
48dnl the error stream.
49define(`REGRESSION_FATAL',
50echo "Bail out! $2 (in $TESTDIR)" > /dev/stderr
51exit $1)
52
53dnl Cleanup.  Exit with the status code of the last failure.  Should probably
54dnl be the number of failed tests, but hey presto, this is what it does.  This
55dnl could also clean up potential droppings, if some forms of regression tests
56dnl end up using mktemp(1) or such.
57define(`REGRESSION_END',
58exit $STATUS)
59