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