]> git.draconx.ca Git - dxcommon.git/blob - snippet/test-tap.at
test-tap.at: Fix regression passing program arguments.
[dxcommon.git] / snippet / test-tap.at
1 # Copyright © 2015, 2022-2024 Nick Bowler
2 #
3 # Helper macros for executing the TAP-like applications in an autotest
4 # test suite.
5 #
6 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
7 # This is free software: you are free to do what the fuck you want to.
8 # There is NO WARRANTY, to the extent permitted by law.
9
10 m4_defun([_TEST_TAP_PREPARE], [m4_divert_push([PREPARE_TESTS])dnl
11 {
12   echo "% prove --version"
13   prove --version </dev/null
14   echo
15 } >&AS_MESSAGE_LOG_FD 2>&1
16
17 # Run a test program, and, if prove is installed, use it to interpret the
18 # TAP-formatted output.
19 test_run_tap () {
20   program=$[1]; shift
21
22   "$builddir/t/$program" "$[@]" >"$program.tap"
23   status=$?
24   cat "$program.tap"
25   # Older versions of prove do not support the -e option so the
26   # "test" must be a perl script.
27   :; { echo 'print <<EOF'; cat "$program.tap"; echo 'EOF'; } >"$program.pl"
28   { prove "$program.pl"; } 2>&1
29   return $status
30 }
31 m4_divert_pop([PREPARE_TESTS])])
32
33 dnl TEST_TAP([application])
34 dnl
35 dnl Run the given TAP application.  The exit status indicates the overall
36 dnl success/failure of the test, while the application's TAP-formatted
37 dnl output is logged with details of individual test results.
38 m4_defun([TEST_TAP], [m4_require([_TEST_TAP_PREPARE])dnl
39 AT_CHECK([test_run_tap $1], [0], [ignore])])
40
41 dnl TEST_TAP_SIMPLE([name], [application], [setup], [keywords])
42 dnl
43 dnl Convenience macro to define a complete test group based around one
44 dnl application.  The test group is created with the given name and
45 dnl (optionally) keywords.  The optional setup defines additional code
46 dnl to run before the actual test, and finally the application is
47 dnl run using TEST_TAP.
48 m4_define([TEST_TAP_SIMPLE], [dnl
49 AT_SETUP([$1])
50 AT_KEYWORDS([$4])dnl
51 m4_n([$3])dnl
52 TEST_TAP([$2])
53 AT_CLEANUP])