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