]> git.draconx.ca Git - dxcommon.git/blob - snippet/test-tap.at
DX_C_ALIGNAS: Work around bash-5 parsing bug.
[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]
21   AS_CASE([$program],
22     [*/*], [program=`expr "$program" : '[.*/\([^.]*\)]'`],
23     [*.*], [program=`expr "$program" : '[\([^.]*\)]'`])
24   "$[@]" >"$program.tap"
25   status=$?
26   cat "$program.tap"
27   # Older versions of prove do not support the -e option so the
28   # "test" must be a perl script.
29   :; { echo 'print <<EOF'; cat "$program.tap"; echo 'EOF'; } >"$program.pl"
30   { prove "$program.pl"; } 2>&1
31   return $status
32 }
33 m4_divert_pop([PREPARE_TESTS])])
34
35 dnl TEST_TAP([application])
36 dnl
37 dnl Run the given TAP application.  The exit status indicates the overall
38 dnl success/failure of the test, while the application's TAP-formatted
39 dnl output is logged with details of individual test results.
40 m4_defun([TEST_TAP], [m4_require([_TEST_TAP_PREPARE])dnl
41 AT_CHECK([test_run_tap $1], [0], [ignore])])
42
43 dnl TEST_TAP_SIMPLE([name], [application], [setup], [keywords])
44 dnl
45 dnl Convenience macro to define a complete test group based around one
46 dnl application.  The test group is created with the given name and
47 dnl (optionally) keywords.  The optional setup defines additional code
48 dnl to run before the actual test, and finally the application is
49 dnl run using TEST_TAP.
50 m4_define([TEST_TAP_SIMPLE], [dnl
51 AT_SETUP([$1])
52 AT_KEYWORDS([$4])dnl
53 m4_n([$3])dnl
54 TEST_TAP([$2])
55 AT_CLEANUP])