]> git.draconx.ca Git - dxcommon.git/commitdiff
Move TAP testsuite macros into snippets.
authorNick Bowler <nbowler@draconx.ca>
Tue, 13 Jun 2023 01:14:19 +0000 (21:14 -0400)
committerNick Bowler <nbowler@draconx.ca>
Tue, 13 Jun 2023 01:14:19 +0000 (21:14 -0400)
That way we can share these macros more easily.  Furthermore, merge in
some compatibility improvements w/ old perl that were implemented in
rrace.

snippet/test-tap.at [new file with mode: 0644]
tests/functions.at
testsuite.at

diff --git a/snippet/test-tap.at b/snippet/test-tap.at
new file mode 100644 (file)
index 0000000..7941cb7
--- /dev/null
@@ -0,0 +1,52 @@
+# Copyright © 2015, 2022-2023 Nick Bowler
+#
+# Helper macros for executing the TAP-like applications in an autotest
+# test suite.
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
+
+m4_divert_push([PREPARE_TESTS])dnl
+{
+  echo "% prove --version"
+  prove --version </dev/null
+  echo
+} >&AS_MESSAGE_LOG_FD 2>&1
+
+# Run a test program, and, if prove is installed, use it to interpret the
+# TAP-formatted output.
+test_run_tap () {
+  program=$1; shift
+
+  "$builddir/t/$program" "$@" >"$program.tap"
+  status=$?
+  cat "$program.tap"
+  # Older versions of prove do not support the -e option so the
+  # "test" must be a perl script.
+  :; { echo 'print <<EOF'; cat "$program.tap"; echo 'EOF'; } >"$program.pl"
+  prove "$program.pl" 2>&1
+  return $status
+}
+m4_divert_pop([PREPARE_TESTS])
+
+dnl TEST_TAP([application])
+dnl
+dnl Run the given TAP application.  The exit status indicates the overall
+dnl success/failure of the test, while the application's TAP-formatted
+dnl output is logged with details of individual test results.
+m4_define([TEST_TAP], [AT_CHECK([test_run_tap $1], [0], [ignore])])
+
+dnl TEST_TAP_SIMPLE([name], [application], [setup], [keywords])
+dnl
+dnl Convenience macro to define a complete test group based around one
+dnl application.  The test group is created with the given name and
+dnl (optionally) keywords.  The optional setup defines additional code
+dnl to run before the actual test, and finally the application is
+dnl run using TEST_TAP.
+m4_define([TEST_TAP_SIMPLE], [dnl
+AT_SETUP([$1])
+AT_KEYWORDS([$4])dnl
+m4_n([$3])dnl
+TEST_TAP([$2])
+AT_CLEANUP])
index ec7b6f3184078846c5cc57a2a9b858aa7ecfd7c1..165376c97f59cf23d1c6c865e7003f1a78776850 100644 (file)
@@ -4,24 +4,6 @@ dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
 dnl There is NO WARRANTY, to the extent permitted by law.
 
-m4_divert_push([PREPARE_TESTS])dnl
-test_run_tap () {
-  "$builddir/t/$1" > "$1.tap"
-  status=$?
-  cat "$1.tap"
-  prove -e cat "$1.tap"
-  return $status
-}
-m4_divert_pop([PREPARE_TESTS])
-
-m4_define([TEST_TAP], [AT_CHECK([test_run_tap "$1"], [0], [ignore])])
-m4_define([TEST_TAP_SIMPLE], [dnl
-AT_SETUP([$1])
-AT_KEYWORDS([$4])dnl
-m4_n([$3])dnl
-TEST_TAP([$2])
-AT_CLEANUP])
-
 AT_BANNER([Binary packing functions])
 
 TEST_TAP_SIMPLE([signed unpacking], [packtests], [], [pack])
index badb6de9315718b8d215d5f5b3685664bbc66ff9..2076d70e637550118d19c5620f334cd70e87fe0c 100644 (file)
@@ -7,13 +7,9 @@ There is NO WARRANTY, to the extent permitted by law.])
 AT_INIT
 AT_COLOR_TESTS
 
-m4_divert_push([PREPARE_TESTS])dnl
-{
-  AS_ECHO(["% prove --version"])
-  prove --version </dev/null
-  echo
-} >&AS_MESSAGE_LOG_FD 2>&1
+m4_include([snippet/test-tap.at])
 
+m4_divert_push([PREPARE_TESTS])dnl
 # Reduce influence from the toplevel "make" invocation on test cases.
 AS_UNSET([MAKEFLAGS])
 AS_UNSET([MAKELEVEL])