diff options
author | Zack Weinberg <zackw@panix.com> | 2020-10-28 17:04:22 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2020-10-29 11:15:48 -0400 |
commit | bc7bb0eba61183078330979684fd46788d24a581 (patch) | |
tree | 84f7c7a9a3107c206db4c36b1b304b8b1bd92ea3 /doc/autoconf.texi | |
parent | 5147a642966e2247827cfd9e6f71464439c6d773 (diff) | |
download | autoconf-bc7bb0eba61183078330979684fd46788d24a581.tar.gz |
Autotest: add official way to execute code before all/each test.zack/autotest-new-hooks
Currently, there isn’t any documented way for an Autotest testsuite to
add custom code to be run either right before the main driver loop, or
at the point of each AT_SETUP. For instance, there’s no good place to
put environment variable sanitization that should apply to the entire
testsuite (but isn’t universally relevant), or shell function
definitions to be used by custom test macros.
Autoconf’s test suite is poking shell functions directly into the
PREPARE_TESTS diversion, and doing environment variable sanitization
in each individual test. Both of these are obviously undesirable.
This patch adds three new AT_* macros that can be used to do these
things in an officially-supported way: AT_PREPARE_TESTS adds code to
be run right before the main driver loop, AT_PREPARE_EACH_TEST adds
code to be run at the beginning of each test, and AT_TEST_HELPER_FN
defines a shell function that will be available to each test. In
Autoconf’s test suite, I use AT_PREPARE_TESTS to factor out
environment variable sanitization that *ought* to apply across the
board, and AT_TEST_HELPER_FN for the helper function used by
AT_CHECK_ENV.
(This fixes the testsuite bug reported by Jannick at
https://lists.gnu.org/archive/html/autoconf/2020-10/msg00052.html .)
Comments requested particularly on the names and implementations of
the new macros. Also, it would be nice to have an example of when
AT_PREPARE_EACH_TEST is useful, but I didn’t find one in the autoconf
test suite.
* lib/autotest/general.m4 (AT_PREPARE_TESTS, AT_PREPARE_EACH_TEST)
(AT_TEST_HELPER_FN): New macros.
(AT_INIT, AT_TESTED): Emit the code to report tested programs only
if it’s needed, and make sure it’s after any code added by
AT_PREPARE_TESTS.
* tests/local.at: Add AT_PREPARE_TESTS block that ensures
$MAKE is set sensibly and $MAKEFLAGS and $CONFIG_SITE are unset.
Use AT_TEST_HELPER_FN for the helper function needed by AT_CHECK_ENV.
(AT_CHECK_MAKE): No need to sanitize $MAKE or $MAKEFLAGS here.
* tests/base.at, tests/compile.at, tests/m4sh.at, tests/torture.at:
No need to unset or neutralize $CONFIG_SITE in individual tests.
* tests/autotest.at: Add tests for new macros.
* doc/autoconf.texi, NEWS: Document new macros.
Diffstat (limited to 'doc/autoconf.texi')
-rw-r--r-- | doc/autoconf.texi | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/autoconf.texi b/doc/autoconf.texi index acc290b0..f1eff146 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -25463,6 +25463,41 @@ will still use shell variable expansion (@samp{$}), command substitution via @file{atlocal} or @file{atconfig}. @end defmac +@defmac AT_PREPARE_TESTS (@var{shell-code}) +@atindex{PREPARE_TESTS} +Execute @var{shell-code} in the main testsuite process, +after initializing the test suite and processing command-line options, +but before running any tests. If this macro is used several times, +all of the @var{shell-code}s will be executed, +in the order they appeared in @file{testsuite.at}. + +One reason to use @code{AT_PREPARE_TESTS} is when the programs under +test are sensitive to environment variables: you can unset all these +variables or reset them to safe values in @var{shell-code}. + +@var{shell-code} is only executed if at least one test is going to be +run. In particular, it will not be executed if any of the @option{--help}, +@option{--version}, @option{--list}, or @option{--clean} options are +given to @command{testsuite} (@pxref{testsuite Invocation}). +@end defmac + +@defmac AT_PREPARE_EACH_TEST (@var{shell-code}) +@atindex{AT_PREPARE_EACH_TEST} +Execute @var{shell-code} in each test group's subshell, at the point of +the @code{AT_SETUP} that starts the test group. +@end defmac + +@defmac AT_TEST_HELPER_FN (@var{name}, @var{args}, @var{description}, @var{code}) +Define a shell function that will be available to the code for each test +group. Its name will be @code{ath_fn_@var{name}}, and its body will be +@var{code}. (The prefix prevents name conflicts with shell functions +defined by M4sh and Autotest.) + +@var{args} should describe the function's arguments and @var{description} +what it does; these are used only for documentation comments in the +generated testsuite script. +@end defmac + @sp 1 @defmac AT_BANNER (@var{test-category-name}) |