1 include(m4sh.m4) -*- Autoconf -*-
2 # M4 macros used in building test suites.
3 # Copyright 2000, 2001 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 # This script is part of Autotest. Unlimited permission to copy,
21 # distribute and modify the testing scripts that are the output of
22 # that Autotest script is given. You need not follow the terms of the
23 # GNU General Public License when using or distributing such scripts,
24 # even though portions of the text of Autotest appear in them. The
25 # GNU General Public License (GPL) does govern all other use of the
26 # material that constitutes the Autotest.
28 # Certain portions of the Autotest source text are designed to be
29 # copied (in certain cases, depending on the input) into the output of
30 # Autotest. We call these the "data" portions. The rest of the
31 # Autotest source text consists of comments plus executable code that
32 # decides which of the data portions to output in any given case. We
33 # call these comments and executable code the "non-data" portions.
34 # Autotest never copies any of the non-data portions into its output.
36 # This special exception to the GPL applies to versions of Autotest
37 # released by the Free Software Foundation. When you make and
38 # distribute a modified version of Autotest, you may extend this
39 # special exception to the GPL to apply to your modified version as
40 # well, *unless* your modified version has the potential to copy into
41 # its output some of the text that was the non-data portion of the
42 # version that you started with. (In other words, unless your change
43 # moves or copies text from the non-data portions to the data
44 # portions.) If your modification has such potential, you must delete
45 # any notice of this special exception to the GPL from your modified
52 # Overall initialization, value of $at_tests_all.
56 # Help message. Of course it is useless, you could just push into
57 # OPTIONS, but that's much clearer this way.
59 # Be ready to run the tests.
61 # The core of the test suite, the ``normal'' diversion.
63 # tail of the core for;case, overall wrap up, generation of debugging
64 # scripts and statistics.
66 m4_define([_m4_divert(DEFAULT)], 0)
67 m4_define([_m4_divert(OPTIONS)], 10)
68 m4_define([_m4_divert(HELP)], 20)
69 m4_define([_m4_divert(SETUP)], 30)
70 m4_define([_m4_divert(TESTS)], 50)
71 m4_define([_m4_divert(TAIL)], 60)
73 m4_divert_push([TESTS])
74 m4_divert_push([KILL])
79 # Return the current file sans directory, a colon, and the current line.
81 [m4_patsubst(__file__, ^.*/\(.*\), \1):__line__])
86 # Begin test suite, using PROGRAM to check version. The search path
87 # should be already preset so the proper executable will be selected.
89 [m4_define([AT_ordinal], 0)
90 m4_define([AT_banner_ordinal], 0)
91 m4_define([AT_data_files],
92 [stdout expout at-setup-line at-check-line at-stdout stderr experr
93 at-stder1 at-stderr ])
94 m4_divert_push([DEFAULT])dnl
98 SHELL=${CONFIG_SHELL-/bin/sh}
101 # Use absolute file notations, as the test might change directories.
102 at_srcdir=`cd "$srcdir" && pwd`
103 at_top_srcdir=`cd "$top_srcdir" && pwd`
105 # Don't take risks: use absolute path names.
109 for at_dir in $AUTOTEST_PATH $PATH; do
110 # There might be directories that don't exist, but don't redirect
111 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
112 at_dir=`(cd "$at_dir" && pwd) 2>/dev/null`
113 test -n "$at_dir" && at_path="$at_path$PATH_SEPARATOR$at_dir"
119 test -f atlocal && . ./atlocal
122 at_stop_on_error=false
123 # Shall we be verbose?
126 # Shall we keep the debug scripts? Must be `:' when testsuite is
127 # run by a debug script, so that the script doesn't remove itself.
129 # Display help message?
133 dnl Other vars inserted here (DEFAULT).
136 while test $[#] -gt 0; do
138 --help | -h) at_help=: ;;
139 --version) echo "$[0] ($at_package) $at_version"; exit 0 ;;
142 -e) at_stop_on_error=:;;
143 -v) at_verbose=echo; at_quiet=:;;
144 -x) at_traceon='set -vx'; at_traceoff='set +vx';;
146 [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
147 at_tests="$at_tests$[1] ";;
149 *) echo "$as_me: invalid option: $[1]" >&2
150 echo "Try \`$[0] --help' for more information." >&2
158 # If tests were specified, display only their title.
159 if test -z "$at_tests"; then
161 Usage: $[0] [[OPTION]]... [[TESTS]]
163 Run all the tests, or the selected TESTS.
166 -h Display this help message and the description of TESTS
167 -e Abort the full suite and inhibit normal clean up if a test fails
168 -v Force more detailed output, default for debugging scripts
169 -d Inhibit clean up and debug script creation, default for debugging scripts
170 -x Have the shell to trace command execution
175 # " 1 42 45 " => " (1|42|45): "
176 at_tests_pattern=`echo "$at_tests" | sed 's/^ *//;s/ *$//;s/ */|/g'`
177 at_tests_pattern=" (${at_tests_pattern}): "
179 egrep -e "$at_tests_pattern" <<EOF
180 m4_divert([HELP])dnl Help message inserted here.
181 m4_divert([SETUP])dnl
187 test -z "$at_tests" && at_tests=$at_tests_all
189 # Can we diff with `/dev/null'? DU 5.0 refuses.
190 if diff /dev/null /dev/null >/dev/null 2>&1; then
193 at_devnull=at-devnull
194 cp /dev/null $at_devnull
197 # Use `diff -u' when possible.
198 if diff -u $at_devnull $at_devnull >/dev/null 2>&1; then
205 if $1 --version | grep "$at_package.*$at_version" >/dev/null; then
206 AS_BOX([Test suite for $at_package $at_version])
208 AS_BOX([ERROR: Not using the proper version, no tests performed])
212 # Setting up the FDs.
213 # 5 is stdout conditioned by verbosity.
214 if test $at_verbose = echo; then
223 m4_divert([TESTS])dnl
225 for at_test in $at_tests
228 rm -rf $at_data_files
229 # Clearly separate the tests when verbose.
230 test $at_test_count != 0 && $at_verbose
232 dnl Tests inserted here (TESTS).
233 m4_divert([TAIL])[]dnl
236 echo $as_me: no such test: $at_test
243 if test ! -f at-check-line; then
244 echo "$as_me: warning: no at-check-line which means a failure happened"
245 echo "$as_me: warning: in a [AT_SETUP/AT_CLEANUP] pair before any"
246 echo "$as_me: warning: [AT_CHECK] could be run. This test suite is"
247 echo "$as_me: warning: improperly designed, please report to"
248 echo "$as_me: warning: <$at_bugreport>."
249 cp at-setup-line at-check-line
251 at_test_count=`expr 1 + $at_test_count`
252 $at_verbose $at_n "$at_test. $srcdir/`cat at-setup-line`: $at_c"
256 77) echo "ok (skipped near \``cat at-check-line`')"
257 at_skip_list="$at_skip_list $at_test"
259 *) echo "FAILED near \``cat at-check-line`'"
260 at_fail_list="$at_fail_list $at_test"
261 $at_stop_on_error && break
264 $at_debug || rm -rf $at_data_files
269 # Wrap up the test suite with summary statistics.
271 rm -f at-check-line at-setup-line
272 at_skip_count=`set dummy $at_skip_list; shift; echo $[#]`
273 at_fail_count=`set dummy $at_fail_list; shift; echo $[#]`
274 if test $at_fail_count = 0; then
275 if test $at_skip_count = 0; then
276 AS_BOX([All $at_test_count tests were successful])
278 AS_BOX([All $at_test_count tests were successful ($at_skip_count skipped)])
280 elif test $at_debug = false; then
281 if $at_stop_on_error; then
282 AS_BOX([ERROR: One of the tests failed, inhibiting subsequent tests])
284 AS_BOX([ERROR: Suite unsuccessful, $at_fail_count of $at_test_count tests failed])
287 # Remove any debugging script resulting from a previous run.
288 rm -f debug-*.sh $[0].log
290 echo $at_n "Writing \`debug-NN.sh' scripts, NN =$at_c"
291 for at_group in $at_fail_list; do
292 echo $at_n " $at_group$at_c"
294 echo 'exec ${CONFIG_SHELL-'"$SHELL"'} '"$[0]"' -v -d '"$at_group"' ${1+"$[@]"}'
296 ) >debug-$at_group.sh
297 chmod +x debug-$at_group.sh
301 echo 'You may investigate any problem if you feel able to do so, in which'
302 echo 'case the testsuite provide a good starting point.'
304 echo 'Now, failed tests will be executed again, verbosely, and logged'
305 echo 'in the file '$[0]'.log.'
308 AS_BOX([Test suite log for $at_package $at_version])
311 # Try to find a few ChangeLogs in case it might help determining the
313 find "$at_top_srcdir" -name ChangeLog \
314 -exec echo {} : ';' \
315 -exec sed 's/^/| /;10q' {} ';' \
318 # Summary of failed and skipped tests.
319 if test $at_fail_count != 0; then
321 $SHELL $[0] $at_fail_list --help
324 if test $at_skip_count != 0; then
325 echo "Skipped tests:"
326 $SHELL $[0] $at_skip_list --help
333 $SHELL $[0] -v -d $at_fail_list 2>&1 | tee -a $[0].log
334 AS_BOX([$[0].log is created])
337 echo "Please send \`$[0].log' to <$at_bugreport> together with all"
338 echo "the information you think might help."
344 m4_wrap([m4_divert_text([DEFAULT],
345 [# List of the tests.
346 at_tests_all="AT_TESTS_ALL "])])dnl
347 m4_wrap([m4_divert_text([SETUP],
348 [# List of the output files.
349 at_data_files="AT_data_files "])])dnl
354 # AT_SETUP(DESCRIPTION)
355 # ---------------------
356 # Start a group of related tests, all to be executed in the same subshell.
357 # The group is testing what DESCRIPTION says.
358 m4_define([AT_SETUP],
359 [m4_define([AT_ordinal], m4_incr(AT_ordinal))
360 m4_append([AT_TESTS_ALL], [ ]m4_defn([AT_ordinal]))
361 m4_divert_text([HELP],
362 [m4_format([ %3d: %-15s %s], AT_ordinal, AT_LINE, [$1])])
363 m4_divert_push([TESTS])dnl
364 AT_ordinal ) [#] AT_ordinal. AT_LINE: $1
365 echo AT_LINE >at-setup-line
366 $at_verbose "AT_ordinal. $srcdir/AT_LINE: testing $1..."
367 $at_quiet $at_n "m4_format([%3d: %-18s], AT_ordinal, AT_LINE)[]$at_c"
373 # AT_CLEANUP_FILE_IFELSE(FILE, IF-REGISTERED, IF-NOT-REGISTERED)
374 # --------------------------------------------------------------
375 # We try to build a regular expression matching `[', `]', `*', and
376 # `.', i.e., the regexp active characters.
378 # Novices would write, `[[]*.]', which sure fails since the character
379 # class ends with the first closing braquet.
380 # M4 gurus will sure write `[\[\]*.]', but it will fail too because
381 # regexp does not support this and understands `\' per se.
382 # Regexp gurus will write `[][*.]' which is indeed what Regexp expects,
383 # but it will fail for M4 reasons: it's the same as `[*.]'.
385 # So the question is:
387 # Can you write a regexp that matches those four characters,
388 # and respects the M4 quotation contraints?
390 # The answer is: (rot13) tvira va gur ertrkc orybj, lbh vqvbg!
391 m4_define([AT_CLEANUP_FILE_IFELSE],
392 [m4_if(m4_regexp(AT_data_files, m4_patsubst([ $1 ], [[[]\|[]]\|[*.]], [\\\&])),
397 # AT_CLEANUP_FILE(FILE)
398 # ---------------------
399 # Register FILE for AT_CLEANUP.
400 m4_define([AT_CLEANUP_FILE],
401 [AT_CLEANUP_FILE_IFELSE([$1], [],
402 [m4_append([AT_data_files], [$1 ])])])
405 # AT_CLEANUP_FILES(FILES)
406 # -----------------------
407 # Declare a list of FILES to clean.
408 m4_define([AT_CLEANUP_FILES],
409 [m4_foreach([AT_File], m4_quote(m4_patsubst([$1], [ *], [,])),
410 [AT_CLEANUP_FILE(AT_File)])])
415 # Complete a group of related tests, recursively remove those FILES
416 # created within the test. There is no need to list files created with
418 m4_define([AT_CLEANUP],
419 [AT_CLEANUP_FILES([$1])dnl
424 m4_divert([TESTS])[]dnl
431 # Output TEXT without any shell expansion.
432 m4_define([AT_BANNER],
433 [m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
434 m4_append([AT_TESTS_ALL], [ banner-]m4_defn([AT_banner_ordinal]))
435 m4_divert_push([TESTS])dnl
436 banner-AT_banner_ordinal ) [#] Banner AT_banner_ordinal. AT_LINE
448 # AT_DATA(FILE, CONTENTS)
449 # -----------------------
450 # Initialize an input data FILE with given CONTENTS, which should end with
452 # This macro is not robust to active symbols in CONTENTS *on purpose*.
453 # If you don't want CONTENT to be evaluated, quote it twice.
455 [AT_CLEANUP_FILES([$1])dnl
461 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR)
462 # ------------------------------------------------
463 # Execute a test by performing given shell COMMANDS. These commands
464 # should normally exit with STATUS, while producing expected STDOUT and
467 # STATUS, STDOUT, and STDERR are not checked if equal to `ignore'.
469 # If STDOUT is `expout', then stdout is compared to the content of the file
470 # `expout'. Likewise for STDERR and `experr'.
472 # If STDOUT is `stdout', then the stdout is left in the file `stdout',
473 # likewise for STDERR and `stderr'. Don't do this:
475 # AT_CHECK([command >out])
476 # # Some checks on `out'
480 # AT_CHECK([command], [], [stdout])
481 # # Some checks on `stdout'
483 # This is an unfortunate limitation inherited from Ultrix which will not
484 # let you redirect several times the same FD (see the Autoconf documentation).
485 # If you use the `AT_CHECK([command >out])' be sure to have the test
486 # suite introduces spurious failures.
488 # You might wander why not just use `ignore' and directly use stdout and
489 # stderr left by the test suite. Firstly because the names of these files
490 # is an internal detail, and secondly, because
492 # AT_CHECK([command], [], [ignore])
493 # AT_CHECK([check stdout])
495 # will use `stdout' both in input and output: undefined behavior would
496 # certainly result. That's why the test suite will save them in `at-stdout'
497 # and `at-stderr', and will provide you with `stdout' and `stderr'.
499 # Any line of stderr starting with leading blanks and a `+' are filtered
500 # out, since most shells when tracing include subshell traces in stderr.
501 # This may cause spurious failures when the test suite is run with `-x'.
504 # Implementation Details
505 # ----------------------
506 # Ideally, we would like to run
508 # ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
510 # but we must group COMMANDS as it is not limited to a single command, and
511 # then the shells will save the traces in at-stderr. So we have to filter
512 # them out when checking stderr, and we must send them into the test suite's
513 # stderr to honor -x properly.
515 # Limiting COMMANDS to a single command is not good either, since them
516 # the user herself would use {} or (), and then we face the same problem.
518 # But then, there is no point in running
520 # ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
522 # instead of the simpler
524 # ( $at_traceon; $1 ) >at-stdout 2>at-stder1
526 m4_define([AT_CHECK],
528 $at_verbose "$srcdir/AT_LINE: AS_ESCAPE([$1])"
529 echo AT_LINE >at-check-line
530 ( $at_traceon; $1 ) >at-stdout 2>at-stder1
532 egrep '^ *\+' at-stder1 >&2
533 egrep -v '^ *\+' at-stder1 >at-stderr
537 stderr, [(echo stderr:; tee stderr <at-stderr) >&5],
538 ignore, [(echo stderr:; cat at-stderr) >&5],
539 experr, [$at_diff experr at-stderr >&5 || at_failed=:],
540 [], [$at_diff $at_devnull at-stderr >&5 || at_failed=:],
541 [echo >>at-stderr; echo "AS_ESCAPE([$4])" | $at_diff - at-stderr >&5 || at_failed=:])
544 stdout, [(echo stdout:; tee stdout <at-stdout) >&5],
545 ignore, [(echo stdout:; cat at-stdout) >&5],
546 expout, [$at_diff expout at-stdout >&5 || at_failed=:],
547 [], [$at_diff $at_devnull at-stdout >&5 || at_failed=:],
548 [echo >>at-stdout; echo "AS_ESCAPE([$3])" | $at_diff - at-stdout >&5 || at_failed=:])
549 dnl Check exit val. Don't `skip' if we are precisely checking $? = 77.
559 [ m4_default([$2], [0])) ;;
560 *) $at_verbose "$srcdir/AT_LINE: exit code was $at_status, expected m4_default([$2], [0])" >&2
563 AS_IF($at_failed, [$5], [$6])