1 # This file is part of Autoconf. -*- Autoconf -*-
2 # M4 macros used in building test suites.
4 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free
5 # Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # As a special exception, the Free Software Foundation gives unlimited
21 # permission to copy, distribute and modify the configure scripts that
22 # are the output of Autoconf. You need not follow the terms of the GNU
23 # General Public License when using or distributing such scripts, even
24 # though portions of the text of Autoconf appear in them. The GNU
25 # General Public License (GPL) does govern all other use of the material
26 # that constitutes the Autoconf program.
28 # Certain portions of the Autoconf source text are designed to be copied
29 # (in certain cases, depending on the input) into the output of
30 # Autoconf. We call these the "data" portions. The rest of the Autoconf
31 # source text consists of comments plus executable code that decides which
32 # of the data portions to output in any given case. We call these
33 # comments and executable code the "non-data" portions. Autoconf never
34 # copies any of the non-data portions into its output.
36 # This special exception to the GPL applies to versions of Autoconf
37 # released by the Free Software Foundation. When you make and
38 # distribute a modified version of Autoconf, you may extend this special
39 # exception to the GPL to apply to your modified version as well, *unless*
40 # your modified version has the potential to copy into its output some
41 # of the text that was the non-data portion of the version that you started
42 # with. (In other words, unless your change moves or copies text from
43 # the non-data portions to the data portions.) If your modification has
44 # such potential, you must delete any notice of this special exception
45 # to the GPL from your modified version.
47 # _m4_divert(DIVERSION-NAME)
48 # --------------------------
49 # Convert a diversion name into its number. Otherwise, return
50 # DIVERSION-NAME which is supposed to be an actual diversion number.
51 # Of course it would be nicer to use m4_case here, instead of zillions
52 # of little macros, but it then takes twice longer to run `autoconf'!
69 # Overall initialization, value of $at_groups_all.
71 # Setup defaults required for option processing.
73 # Option processing. After AT_INIT, user options can be entered here as
74 # cases of a case statement.
76 # Finish up the option processing.
79 # Start printing the help message.
81 # Modes help text. Additional modes can be appended as self-contained
82 # cat'd here-docs as generated by AS_HELP_STRING.
84 # Tuning help text. Additional tuning options can be appended as
85 # self-contained cat'd here-docs as generated by AS_HELP_STRING.
87 # User help can be appended to this as self-contained cat'd here-docs.
89 # Finish up the help texts.
92 # Head of the handling of --version.
94 # Copyright notices for --version.
96 # Tail of the handling of --version.
99 # Like DEFAULTS but run after argument processing for purposes of
100 # optimization. Do anything else that needs to be done to prepare for
101 # tests. Sets up verbose and log file descriptors. Sets and logs PATH.
103 # The core of the test suite.
105 # tail of the core for;case, overall wrap up, generation of debugging
106 # scripts and statistics.
108 # The code for each test, the ``normal'' diversion
110 m4_define([_m4_divert(DEFAULTS)], 100)
111 m4_define([_m4_divert(PARSE_ARGS_BEGIN)], 200)
112 m4_define([_m4_divert(PARSE_ARGS)], 201)
113 m4_define([_m4_divert(PARSE_ARGS_END)], 202)
114 m4_define([_m4_divert(HELP)], 300)
115 m4_define([_m4_divert(HELP_MODES)], 301)
116 m4_define([_m4_divert(HELP_TUNING)], 302)
117 m4_define([_m4_divert(HELP_OTHER)], 303)
118 m4_define([_m4_divert(HELP_END)], 304)
119 m4_define([_m4_divert(VERSION)], 350)
120 m4_define([_m4_divert(VERSION_NOTICES)], 351)
121 m4_define([_m4_divert(VERSION_END)], 352)
122 m4_define([_m4_divert(PREPARE_TESTS)], 400)
123 m4_define([_m4_divert(TESTS)], 401)
124 m4_define([_m4_divert(TESTS_END)], 402)
125 m4_define([_m4_divert(TEST_SCRIPT)], 403)
130 # Return the current file sans directory, a colon, and the current
131 # line. Be sure to return a _quoted_ file name, so if, for instance,
132 # the user is lunatic enough to have a file named `dnl' (and I, for
133 # one, love to be brainless and stubborn sometimes), then we return a
136 # Gee, we can't use simply
138 # m4_bpatsubst(__file__, [^.*/\(.*\)], [[\1]])
140 # since then, since `dnl' doesn't match the pattern, it is returned
141 # with once quotation level less, so you lose! And since GNU M4
142 # is one of the biggest junk in the whole universe wrt regexp, don't
143 # even think about using `?' or `\?'. Bah, `*' will do.
144 # Pleeeeeeeease, Gary, provide us with dirname and ERE!
146 # M4 recompiles the regular expression for every m4_bpatsubst, but __file__
147 # rarely changes. Be fast - only compute the dirname when necessary; for
148 # autoconf alone, this shaves off several seconds in building testsuite.
149 m4_define([_AT_LINE_file])
150 m4_define([_AT_LINE_base])
152 [m4_if(m4_defn([_AT_LINE_file]), __file__, [],
153 [m4_do([m4_define([_AT_LINE_file], __file__)],
154 [m4_define([_AT_LINE_base],
155 m4_bpatsubst(__file__, [^.*/\([^/]*\)$],
157 m4_defn([_AT_LINE_base]):__line__])
160 # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR)
161 # ------------------------------------------
162 # Normalize SHELL-VAR so that its value has the same number of digits as
163 # all the other test group numbers.
164 m4_define([_AT_NORMALIZE_TEST_GROUP_NUMBER],
168 '"$at_format"'*) break;;
174 # _AT_CREATE_DEBUGGING_SCRIPT
175 # ---------------------------
176 # Create the debugging script $at_group_dir/run which will reproduce the
177 # current test group.
178 m4_define([_AT_CREATE_DEBUGGING_SCRIPT],
181 echo 'test "${ZSH_VERSION+set}" = set && alias -g '\''${1+"$[@]"}'\''='\''"$[@]"'\'''
182 AS_ECHO(["cd '$at_dir'"])
183 AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} $[0] -v -d $at_debug_args $at_group \${1+\"\$[@]\"}"])
186 chmod +x $at_group_dir/run
187 ])# _AT_CREATE_DEBUGGING_SCRIPT
190 # AT_INIT([TESTSUITE-NAME])
191 # -------------------------
194 [m4_pattern_forbid([^_?AT_])
195 m4_define([AT_TESTSUITE_NAME],
196 m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1], [: $1]))
197 m4_define([AT_ordinal], 0)
198 m4_define([AT_banner_ordinal], 0)
199 m4_define([AT_groups_all], [])
200 m4_define([AT_help_all], [])
202 m4_divert_push([DEFAULTS])dnl
204 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
206 This test suite is free software; the Free Software Foundation gives
207 unlimited permission to copy, distribute and modify it.])
210 SHELL=${CONFIG_SHELL-/bin/sh}
215 ## --------------- ##
216 ## Shell functions ##
217 ## --------------- ##
219 # at_func_check_newline COMMAND
220 # Test if COMMAND includes a newline and, if so, print a message and return exit code 1
221 at_func_check_newline ()
225 '*) echo 'Not enabling shell tracing (command contains an embedded newline)' ; return 1 ;;
230 # at_func_filter_trace EXIT-CODE
231 # Split the contents of file "$at_stder1" into the "set -x" trace (on stderr) and
232 # the other lines (on file "$at_stderr"). Return the exit code EXIT-CODE.
233 at_func_filter_trace ()
235 grep '^ *+' "$at_stder1" >&2
236 grep -v '^ *+' "$at_stder1" >"$at_stderr"
240 # at_func_log_failure FILE-LIST
241 # Copy the files in the list on stdout with a "> " prefix, and exit the shell
242 # with a failure exit code.
243 at_func_log_failure ()
246 do AS_ECHO(["$file:"]); sed 's/^/> /' "$file"; done
247 echo 1 > "$at_status_file"
251 # at_func_check_skip EXIT-CODE
252 # Check whether EXIT-CODE is the special exit code 77, and if so exit the shell
253 # with that same exit code.
254 at_func_check_skip () {
256 77) echo 77 > "$at_status_file"; exit 77;;
260 # at_func_check_status EXPECTED EXIT-CODE LINE
261 # Check whether EXIT-CODE is the expected exit code, and if so do nothing. Else,
262 # if it is 77 exit the shell with that same exit code; if it is anything else
263 # print an error message and fail the test.
264 at_func_check_status () {
265 dnl This order ensures that we don't `skip' if we are precisely checking $? = 77.
268 77) echo 77 > "$at_status_file"; exit 77;;
269 *) AS_ECHO(["$[3]: exit code was $[2], expected $[1]"])
274 # at_func_diff_devnull FILE
275 # Emit a diff between /dev/null and FILE. Uses "test -s" to avoid useless
277 at_func_diff_devnull () {
278 test -s "$[1]" || return 0
279 $at_diff "$at_devnull" "$[1]"
282 # Load the config file.
283 for at_file in atconfig atlocal
285 test -r $at_file || continue
286 . ./$at_file || AS_ERROR([invalid content: $at_file])
289 # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
290 : ${at_top_build_prefix=$at_top_builddir}
292 # atconfig delivers names relative to the directory the test suite is
293 # in, but the groups themselves are run in testsuite-dir/group-dir.
294 if test -n "$at_top_srcdir"; then
296 for at_dir in srcdir top_srcdir top_build_prefix
298 at_val=AS_VAR_GET([at_$at_dir])
300 [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
301 *) at_prefix=../../ ;;
303 AS_VAR_SET([$at_dir], [$at_prefix$at_val])
307 # Not all shells have the 'times' builtin; the subshell is needed to make
308 # sure we discard the 'times: not found' message from the shell.
310 (times) >/dev/null 2>&1 && at_times_p=:
312 # CLI Arguments to pass to the debugging scripts.
316 # Shall we be verbose? ':' means no, empty means yes.
320 # Shall we keep the debug scripts? Must be `:' when the suite is
321 # run by a debug script, so that the script doesn't remove itself.
323 # Display help message?
325 # Display the version message?
332 # The directory we are in.
334 # The directory the whole suite works in.
335 # Should be absolutely to let the user `cd' at will.
336 at_suite_dir=$at_dir/$as_me.dir
337 # The file containing the suite.
338 at_suite_log=$at_dir/$as_me.log
339 # The file containing the location of the last AT_CHECK.
340 at_check_line_file=$at_suite_dir/at-check-line
341 # The file containing the exit status of the last command.
342 at_status_file=$at_suite_dir/at-status
343 # The files containing the output of the tested commands.
344 at_stdout=$at_suite_dir/at-stdout
345 at_stder1=$at_suite_dir/at-stder1
346 at_stderr=$at_suite_dir/at-stderr
347 # The file containing dates.
348 at_times_file=$at_suite_dir/at-times
349 m4_divert_pop([DEFAULTS])dnl
350 m4_wrap([m4_divert_text([DEFAULTS],
352 # List of the tested programs.
353 at_tested='m4_ifdef([AT_tested], [AT_tested])'
354 # List of the all the test groups.
355 at_groups_all='AT_groups_all'
356 # As many question marks as there are digits in the last test group number.
357 # Used to normalize the test group numbers so that `ls' lists them in
359 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
360 # Description of all the test groups.
361 at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"])])dnl
362 m4_divert_push([PARSE_ARGS])dnl
367 # If the previous option needs an argument, assign it.
368 if test -n "$at_prev"; then
369 at_option=$at_prev=$at_option
374 *=*) at_optarg=`expr "x$at_option" : 'x[[^=]]*=\(.*\)'` ;;
378 # Accept the important Cygnus configure options, so we can diagnose typos.
394 test -d "$at_suite_dir" &&
395 find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
396 rm -f -r "$at_suite_dir" "$at_suite_log"
410 at_verbose=; at_quiet=:
414 at_traceon='set -x'; at_traceoff='set +x'
417 [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
418 at_groups="$at_groups$at_option "
422 [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
423 at_range_start=`echo $at_option |tr -d X-`
424 at_range=`AS_ECHO([" $at_groups_all "]) | \
425 sed -e 's/^.* \('$at_range_start' \)/\1/'`
426 at_groups="$at_groups$at_range "
429 [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
430 at_range_end=`echo $at_option |tr -d X-`
431 at_range=`AS_ECHO([" $at_groups_all "]) | \
432 sed -e 's/\( '$at_range_end'\) .*$/\1/'`
433 at_groups="$at_groups$at_range "
436 [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
437 [[0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9]] | \
438 [[0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
439 [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
440 [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
441 [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
442 at_range_start=`expr $at_option : '\(.*\)-'`
443 at_range_end=`expr $at_option : '.*-\(.*\)'`
444 if test $at_range_start -gt $at_range_end; then
446 at_range_end=$at_range_start
447 at_range_start=$at_tmp
449 at_range=`AS_ECHO([" $at_groups_all "]) | \
450 sed -e 's/^.*\( '$at_range_start' \)/\1/' \
451 -e 's/\( '$at_range_end'\) .*$/\1/'`
452 at_groups="$at_groups$at_range "
460 at_groups_selected=$at_help_all
472 at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
475 # It is on purpose that we match the test group titles too.
476 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
477 grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
479 # Smash the newlines.
480 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//' |
483 at_groups="$at_groups$at_groups_selected "
485 m4_divert_pop([PARSE_ARGS])dnl
486 dnl Process *=* last to allow for user specified --option=* type arguments.
487 m4_divert_push([PARSE_ARGS_END])dnl
490 at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
491 # Reject names that are not valid shell variable names.
492 expr "x$at_envvar" : "[.*[^_$as_cr_alnum]]" >/dev/null &&
493 AS_ERROR([invalid variable name: $at_envvar])
494 at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
495 eval "$at_envvar='$at_value'"
497 # Propagate to debug scripts.
498 at_debug_args="$at_debug_args $at_envvar='$at_value'"
501 *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
502 AS_ECHO(["Try \`$[0] --help' for more information."]) >&2
508 # Selected test groups.
509 if test -z "$at_groups"; then
510 at_groups=$at_groups_all
512 # Sort the tests, removing duplicates:
513 at_groups=`AS_ECHO(["$at_groups"]) | tr ' ' "$as_nl" | sort -nu`
514 # and add banners. (Passing at_groups_all is tricky--see the comment
515 # starting with "Passing at_groups is tricky.")
516 at_groups=`AS_ECHO(["$at_groups$as_nl $at_groups_all"]) |
517 awk ['BEGIN { FS = "@" } # Effectively switch off field splitting.
518 /^$/ { next } # Ignore the empty line.
519 !/ / { groups++; selected[$ 0] = 1; next }
520 # The last line, containing at_groups_all.
522 n = split($ 0, a, " ")
523 # If there are several tests, select their banners:
525 for (i = 1; i <= n; i++) {
526 if (a[i] ~ /^banner-/)
528 else if (banner != "" && selected[a[i]] == 1)
532 for (i = 1; i <= n; i++)
533 if (selected[a[i]] == 1)
538 m4_divert_pop([PARSE_ARGS_END])dnl
539 m4_divert_push([HELP])dnl
544 Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
546 Run all the tests, or the selected TESTS, given by numeric ranges, and
547 save a detailed log file. Upon failure, create debugging scripts.
549 You should not change environment variables unless explicitly passed
550 as command line arguments. Set \`AUTOTEST_PATH' to select the executables
551 to exercise. Each relative directory is expanded as build and source
552 directories relatively to the top level of this distribution. E.g.,
554 $ $[0] AUTOTEST_PATH=bin
556 possibly amounts into
558 PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH
560 m4_divert_pop([HELP])dnl
561 m4_divert_push([HELP_MODES])dnl
565 -h, --help print the help message, then exit
566 -V, --version print version number, then exit
567 -c, --clean remove all the files this test suite might create and exit
568 -l, --list describes all the tests, or the selected TESTS
570 m4_divert_pop([HELP_MODES])dnl
571 m4_divert_push([HELP_TUNING])dnl
574 dnl extra quoting prevents emacs whitespace mode from putting tabs in output
576 -k, --keywords=KEYWORDS
577 [ select the tests matching all the comma-separated KEYWORDS]
578 [ multiple \`-k' accumulate; prefixed \`!' negates a KEYWORD]
579 -e, --errexit abort as soon as a test fails; implies --debug
580 -v, --verbose force more detailed output
581 [ default for debugging scripts]
582 -d, --debug inhibit clean up and top-level logging
583 [ default for debugging scripts]
584 -x, --trace enable tests shell tracing
586 m4_divert_pop([HELP_TUNING])dnl
587 m4_divert_push([HELP_END])dnl
590 Report bugs to <AT_PACKAGE_BUGREPORT>.
598 AT_TESTSUITE_NAME test groups:
600 NUM: FILE-NAME:LINE TEST-GROUP-NAME
604 # Passing at_groups is tricky. We cannot use it to form a literal string
605 # or regexp because of the limitation of AIX awk. And Solaris' awk
606 # doesn't grok more than 99 fields in a record, so we have to use `split'.
607 AS_ECHO(["$at_groups$as_nl$at_help_all"]) |
608 awk 'BEGIN { FS = ";" }
610 for (n = split($ 0, a, " "); n; n--) selected[[a[n]]] = 1
614 if (selected[[$ 1]]) {
615 printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
616 if ($ 4) printf " %s\n", $ 4
621 m4_divert_pop([HELP_END])dnl
622 m4_divert_push([VERSION])dnl
623 if $at_version_p; then
624 AS_ECHO(["$as_me (AT_PACKAGE_STRING)"])
626 m4_divert_pop([VERSION])dnl
627 m4_divert_push([VERSION_END])dnl
631 m4_divert_pop([VERSION_END])dnl
632 m4_divert_push([PREPARE_TESTS])dnl
634 # Don't take risks: use only absolute directories in PATH.
636 # For stand-alone test suites, AUTOTEST_PATH is relative to `.'.
638 # For embedded test suites, AUTOTEST_PATH is relative to the top level
639 # of the package. Then expand it into build/src parts, since users
640 # may create executables in both places.
641 AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s|:|$PATH_SEPARATOR|g"`
643 _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
644 [test -n "$at_path" && at_path=$at_path$PATH_SEPARATOR
646 [[\\/]]* | ?:[[\\/]]* )
647 at_path=$at_path$as_dir
650 if test -z "$at_top_build_prefix"; then
651 # Stand-alone test suite.
652 at_path=$at_path$as_dir
654 # Embedded test suite.
655 at_path=$at_path$at_top_build_prefix$as_dir$PATH_SEPARATOR
656 at_path=$at_path$at_top_srcdir/$as_dir
661 # Now build and simplify PATH.
663 # There might be directories that don't exist, but don't redirect
664 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
666 _AS_PATH_WALK([$at_path],
667 [as_dir=`(cd "$as_dir" && pwd) 2>/dev/null`
668 test -d "$as_dir" || continue
669 case $PATH_SEPARATOR$at_new_path$PATH_SEPARATOR in
670 *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR*) ;;
671 $PATH_SEPARATOR$PATH_SEPARATOR) at_new_path=$as_dir ;;
672 *) at_new_path=$at_new_path$PATH_SEPARATOR$as_dir ;;
677 # Setting up the FDs.
678 # 5 is the log file. Not to be overwritten if `-d'.
679 m4_define([AS_MESSAGE_LOG_FD], [5])
681 at_suite_log=/dev/null
685 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
688 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
690 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
693 AS_ECHO(["$as_me: command line was:"])
694 AS_ECHO([" \$ $[0] $at_cli_args"])
697 # Try to find a few ChangeLogs in case it might help determining the
698 # exact version. Use the relative dir: if the top dir is a symlink,
699 # find will not follow it (and options to follow the links are not
700 # portable), which would result in no output here.
701 if test -n "$at_top_srcdir"; then
702 AS_BOX([ChangeLogs.])
704 for at_file in `find "$at_top_srcdir" -name ChangeLog -print`
706 AS_ECHO(["$as_me: $at_file:"])
707 sed 's/^/| /;10q' $at_file
715 # Contents of the config files.
716 for at_file in atconfig atlocal
718 test -r $at_file || continue
719 AS_ECHO(["$as_me: $at_file:"])
720 sed 's/^/| /' $at_file
724 AS_BOX([Tested programs.])
726 } >&AS_MESSAGE_LOG_FD
728 # Report what programs are being tested.
729 for at_program in : $at_tested
731 test "$at_program" = : && continue
732 _AS_PATH_WALK([$PATH], [test -f "$as_dir/$at_program" && break])
733 if test -f "$as_dir/$at_program"; then
735 AS_ECHO(["$at_srcdir/AT_LINE: $as_dir/$at_program --version"])
736 "$as_dir/$at_program" --version
738 } >&AS_MESSAGE_LOG_FD 2>&1
740 AS_ERROR([cannot find $at_program])
745 AS_BOX([Running the tests.])
746 } >&AS_MESSAGE_LOG_FD
749 at_start_time=`date +%s 2>/dev/null`
750 AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
757 m4_divert_pop([PREPARE_TESTS])dnl
758 m4_divert_push([TESTS])dnl
760 # Create the master directory if it doesn't already exist.
761 test -d "$at_suite_dir" ||
762 mkdir "$at_suite_dir" ||
763 AS_ERROR([cannot create '$at_suite_dir'])
765 # Can we diff with `/dev/null'? DU 5.0 refuses.
766 if diff /dev/null /dev/null >/dev/null 2>&1; then
769 at_devnull=$at_suite_dir/devnull
773 # Use `diff -u' when possible.
774 if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
782 for at_group in $at_groups
784 # Be sure to come back to the top test directory.
787 # Clearly separate the test groups when verbose.
788 test $at_group_count != 0 && $at_verbose echo
792 at_group_log=$at_suite_log
796 at_group_normalized=$at_group
797 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
799 # Create a fresh directory for the next test group, and enter.
800 at_group_dir=$at_suite_dir/$at_group_normalized
801 at_group_log=$at_group_dir/$as_me.log
802 if test -d "$at_group_dir"; then
803 find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
804 rm -fr "$at_group_dir" ||
805 AS_WARN([test directory could not be cleaned.])
807 # Be tolerant if the above `rm' was not able to remove the directory.
808 AS_MKDIR_P([$at_group_dir])
813 echo 0 > "$at_status_file"
815 # In verbose mode, append to the log file *and* show on
816 # the standard output; in quiet mode only write to the log
817 if test -z "$at_verbose"; then
818 at_tee_pipe='tee -a "$at_group_log"'
820 at_tee_pipe='cat >> "$at_group_log"'
824 dnl Test groups inserted here (TESTS).
825 m4_divert_pop([TESTS])[]dnl
826 m4_divert_push([TESTS_END])[]dnl
829 AS_ECHO(["$as_me: no such test group: $at_group"]) >&2
834 # Be sure to come back to the suite directory, in particular
835 # since below we might `rm' the group directory we are in currently.
841 if test ! -f "$at_check_line_file"; then
842 sed "s/^ */$as_me: warning: /" <<_ATEOF
843 A failure happened in a test group before any test could be
844 run. This means that test suite is improperly designed. Please
845 report this failure to <AT_PACKAGE_BUGREPORT>.
847 AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
849 at_group_count=`expr 1 + $at_group_count`
850 $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
851 AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
852 case $at_xfail:$at_status in
854 at_msg="UNEXPECTED PASS"
855 at_xpass_list="$at_xpass_list $at_group"
856 at_errexit=$at_errexit_p
860 at_pass_list="$at_pass_list $at_group"
864 at_msg='skipped ('`cat "$at_check_line_file"`')'
865 at_skip_list="$at_skip_list $at_group"
869 at_msg='expected failure ('`cat "$at_check_line_file"`')'
870 at_xfail_list="$at_xfail_list $at_group"
874 at_msg='FAILED ('`cat "$at_check_line_file"`')'
875 at_fail_list="$at_fail_list $at_group"
876 at_errexit=$at_errexit_p
879 # Make sure there is a separator even with long titles.
880 AS_ECHO([" $at_msg"])
881 at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
884 # $at_times_file is only available if the group succeeded.
885 # We're not including the group log, so the success message
886 # is written in the global log separately. But we also
887 # write to the group log in case they're using -d.
888 if test -f "$at_times_file"; then
889 at_log_msg="$at_log_msg ("`sed 1d "$at_times_file"`')'
890 rm -f "$at_times_file"
892 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
893 AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
895 # Cleanup the group directory, unless the user wants the files.
896 if $at_debug_p ; then
897 _AT_CREATE_DEBUGGING_SCRIPT
898 elif test -d "$at_group_dir"; then
899 find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
900 rm -fr "$at_group_dir"
904 # Upon failure, include the log into the testsuite's global
905 # log. The failure message is written in the group log. It
906 # is later included in the global log.
907 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
909 # Upon failure, keep the group directory for autopsy, and
910 # create the debugging script.
911 _AT_CREATE_DEBUGGING_SCRIPT
919 # Back to the top directory.
922 # Compute the duration of the suite.
924 at_stop_time=`date +%s 2>/dev/null`
925 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
926 case $at_start_time,$at_stop_time in
928 at_duration_s=`expr $at_stop_time - $at_start_time`
929 at_duration_m=`expr $at_duration_s / 60`
930 at_duration_h=`expr $at_duration_m / 60`
931 at_duration_s=`expr $at_duration_s % 60`
932 at_duration_m=`expr $at_duration_m % 60`
933 at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
934 AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
938 # Wrap up the test suite with summary statistics.
939 set X $at_skip_list; shift; at_skip_count=$[@%:@]
940 set X $at_fail_list; shift; at_fail_count=$[@%:@]
941 set X $at_xpass_list; shift; at_xpass_count=$[@%:@]
942 set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
944 at_run_count=`expr $at_group_count - $at_skip_count`
945 at_unexpected_count=`expr $at_xpass_count + $at_fail_count`
946 at_total_fail_count=`expr $at_xfail_count + $at_fail_count`
949 AS_BOX([Test results.])
953 AS_BOX([Test results.])
955 } >&AS_MESSAGE_LOG_FD
958 dnl FIXME: this code is as far from i18n-cleanness as man
961 if test $at_run_count = 1; then
965 at_result="$at_run_count tests"
968 if $at_errexit_p && test $at_unexpected_count != 0; then
969 if test $at_xpass_count = 1; then
970 at_result="$at_result $at_were run, one passed"
972 at_result="$at_result $at_were run, one failed"
974 at_result="$at_result unexpectedly and inhibited subsequent tests."
976 # Don't you just love exponential explosion of the number of cases?
977 case $at_xpass_count:$at_fail_count:$at_xfail_count in
979 0:0:0) at_result="$at_result $at_were successful." ;;
980 0:0:*) at_result="$at_result behaved as expected." ;;
982 # Some unexpected failures
983 0:*:0) at_result="$at_result $at_were run,
984 $at_fail_count failed unexpectedly." ;;
986 # Some failures, both expected and unexpected
987 0:*:1) at_result="$at_result $at_were run,
988 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
989 0:*:*) at_result="$at_result $at_were run,
990 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
992 # No unexpected failures, but some xpasses
993 *:0:*) at_result="$at_result $at_were run,
994 $at_xpass_count passed unexpectedly." ;;
996 # No expected failures, but failures and xpasses
997 *:1:0) at_result="$at_result $at_were run,
998 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failure)." ;;
999 *:*:0) at_result="$at_result $at_were run,
1000 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failures)." ;;
1003 *:*:1) at_result="$at_result $at_were run,
1004 $at_xpass_count passed unexpectedly,
1005 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1006 *:*:*) at_result="$at_result $at_were run,
1007 $at_xpass_count passed unexpectedly,
1008 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1011 if test $at_skip_count = 0 && test $at_run_count -gt 1; then
1012 at_result="All $at_result"
1016 # Now put skips in the mix.
1017 case $at_skip_count in
1019 1) at_result="$at_result
1020 1 test was skipped." ;;
1021 *) at_result="$at_result
1022 $at_skip_count tests were skipped." ;;
1025 if test $at_unexpected_count = 0; then
1027 echo "$at_result" >&AS_MESSAGE_LOG_FD
1029 echo "ERROR: $at_result" >&2
1030 echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
1033 AS_BOX([Summary of the failures.])
1035 # Summary of failed and skipped tests.
1036 if test $at_fail_count != 0; then
1037 echo "Failed tests:"
1038 $SHELL "$[0]" $at_fail_list --list
1041 if test $at_skip_count != 0; then
1042 echo "Skipped tests:"
1043 $SHELL "$[0]" $at_skip_list --list
1046 if test $at_xpass_count != 0; then
1047 echo "Unexpected passes:"
1048 $SHELL "$[0]" $at_xpass_list --list
1051 if test $at_fail_count != 0; then
1052 AS_BOX([Detailed failed tests.])
1054 for at_group in $at_fail_list
1056 at_group_normalized=$at_group
1057 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1058 cat "$at_suite_dir/$at_group_normalized/$as_me.log"
1063 if test -n "$at_top_srcdir"; then
1064 AS_BOX([${at_top_build_prefix}config.log])
1065 sed 's/^/| /' ${at_top_build_prefix}config.log
1068 } >&AS_MESSAGE_LOG_FD
1070 AS_BOX([$as_me.log was created.])
1073 AS_ECHO(["Please send \`${at_testdir+${at_testdir}/}$as_me.log' and all information you think might help:
1075 To: <AT_PACKAGE_BUGREPORT>
1076 Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me:dnl
1077 $at_fail_list${at_fail_list:+ failed${at_xpass_list:+,}}dnl
1078 $at_xpass_list${at_xpass_list:+ passed unexpectedly}
1080 if test $at_debug_p = false; then
1082 echo 'You may investigate any problem if you feel able to do so, in which'
1083 echo 'case the test suite provides a good starting point. Its output may'
1084 AS_ECHO(["be found below \`${at_testdir+${at_testdir}/}$as_me.dir'."])
1091 m4_divert_pop([TESTS_END])dnl
1092 dnl End of AT_INIT: divert to KILL, only test groups are to be
1093 dnl output, the rest is ignored. Current diversion is BODY, inherited
1095 m4_divert_pop([BODY])
1096 m4_divert_push([KILL])
1100 # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
1101 # [ACTION-IF-NOT-GIVEN])
1102 # ---------------------------------------------------------------------------
1103 # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
1104 m4_defun([_AT_ARG_OPTION],
1105 [m4_divert_once([HELP_OTHER],
1110 ])dnl m4_divert_once HELP_OTHER
1111 m4_divert_text([HELP_OTHER],
1115 dnl Turn our options into our desired strings
1116 m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
1117 m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
1118 m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
1119 m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
1120 m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
1121 [m4_define_default([AT_first_option],AT_option)dnl
1122 m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
1123 m4_append([AT_case_no],[--no]AT_option, [ | ])dnl
1124 m4_append([AT_case_arg],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
1125 ])dnl m4_foreach AT_option
1126 dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
1127 m4_divert_once([PARSE_ARGS_BEGIN],
1130 ## Set up package specific options.
1133 m4_divert_text([PARSE_ARGS_BEGIN],
1134 [dnl Provide a default value for options without arguments.
1135 m4_ifvaln([$3],,[at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false])dnl
1136 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=false
1137 ])dnl m4_divert_text DEFAULTS
1138 m4_ifval([$3],[m4_divert_once([PARSE_ARGS_END],
1141 ## Verify our last option didn't require an argument
1143 AS_IF([test -n "$at_prev"],[AS_ERROR([`$at_prev' requires an argument.])])])])
1144 m4_divert_text([PARSE_ARGS],
1145 [dnl Parse the options and args when necessary.
1148 at_prev=--m4_bpatsubst([AT_first_option], -, _)
1151 at_arg_[]m4_bpatsubst([AT_first_option], -, _)=$at_optarg
1152 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1157 at_arg_[]m4_bpatsubst([AT_first_option], -, _)=:
1158 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1159 m4_ifval([$4],[$4])dnl
1163 at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false
1164 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1165 m4_ifval([$4],[$4])dnl
1166 ;;])dnl m4_ifvaln $3
1167 ])dnl m4_divert_text PARSE_ARGS
1169 [m4_divert_once([PARSE_ARGS_END],
1172 ## Process package specific options when _not_ supplied.
1173 ##])dnl m4_divert_once PARSE_ARGS_END
1174 m4_divert_text([PARSE_ARGS_END],
1176 AS_IF([$at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)],,[$5])dnl
1177 ])dnl m4_divert_text PARSE_ARGS_END
1179 ])dnl _AT_ARG_OPTION
1182 # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1183 # ------------------------------------------------------------------------
1184 # Accept a set of OPTIONS with arguments. Add HELP-TEXT to the HELP_OTHER
1187 # Preceding dashes should not be passed into OPTIONS. Users will be required
1188 # to pass `--' before long options and `-' before single character options.
1190 # $at_arg_OPTION will be set to `:' if this option is received, `false' if
1191 # if --noOPTION is received, and `false' by default.
1193 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1194 # $at_optarg set to `:' or `false' as appropriate. $at_optarg is actually
1195 # just a copy of $at_arg_OPTION.
1197 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1198 # if no option from OPTIONS was found.
1199 m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
1202 # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1203 # ---------------------------------------------------------------------------
1204 # Accept a set of OPTIONS with arguments, seperated by commas. Add HELP-TEXT
1205 # to the HELP_OTHER diversion.
1207 # Preceding dashes should not be passed into OPTIONS. Users will be required
1208 # to pass `--' before long options and `-' before single character options.
1210 # By default, any argument to these options will be assigned to the shell
1211 # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
1212 # any `-' characters replaced with `_'.
1214 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1215 # $at_optarg set. $at_optarg is actually just a copy of $at_arg_OPTION.
1217 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1218 # if no option from OPTIONS was found.
1219 m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
1222 # AT_TESTED(PROGRAMS)
1223 # -------------------
1224 # Specify the list of programs exercised by the test suite. Their
1225 # versions are logged, and in the case of embedded test suite, they
1226 # must correspond to the version of the package. PATH should be
1227 # already preset so the proper executable will be selected.
1228 m4_define([AT_TESTED],
1229 [m4_append_uniq([AT_tested], [$1], [
1233 # AT_COPYRIGHT(TEXT)
1234 # ------------------
1235 # Emit TEXT, a copyright notice, in the top of the test suite and in
1236 # --version output. Macros in TEXT are evaluated once.
1237 m4_define([AT_COPYRIGHT],
1238 [AS_COPYRIGHT([$1])[]dnl
1239 m4_divert_text([VERSION_NOTICES],
1241 $1])])# AT_COPYRIGHT
1244 # AT_SETUP(DESCRIPTION)
1245 # ---------------------
1246 # Start a group of related tests, all to be executed in the same subshell.
1247 # The group is testing what DESCRIPTION says.
1248 m4_define([AT_SETUP],
1249 [m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
1250 m4_define([AT_capture_files], [])
1251 m4_define([AT_line], AT_LINE)
1252 m4_define([AT_xfail], [at_xfail=no])
1253 m4_define([AT_description], m4_quote($1))
1254 m4_define([AT_ordinal], m4_incr(AT_ordinal))
1255 m4_append([AT_groups_all], [ ]m4_defn([AT_ordinal]))
1256 m4_divert_push([TESTS])dnl
1257 AT_ordinal ) @%:@ AT_ordinal. m4_defn([AT_line]): m4_defn([AT_description])
1258 at_setup_line='m4_defn([AT_line])'
1259 at_desc="AS_ESCAPE(m4_dquote(m4_defn([AT_description])))"
1260 $at_quiet AS_ECHO_N(["m4_format([%3d: ], AT_ordinal)$at_desc"]dnl
1261 ["m4_format(%m4_eval(47 - m4_qlen(m4_defn([AT_description])))[s])"])
1262 m4_divert_push([TEST_SCRIPT])dnl
1266 # AT_XFAIL_IF(SHELL-EXPRESSION)
1267 # -----------------------------
1268 # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
1269 # true (exitcode = 0).
1270 m4_define([AT_XFAIL_IF],
1272 dnl Try to limit the amount of conditionals that we emit.
1276 [:], [m4_define([AT_xfail], [at_xfail=yes])],
1277 [true], [m4_define([AT_xfail], [at_xfail=yes])],
1278 [m4_append([AT_xfail], [
1279 $1 && at_xfail=yes])])])
1282 # AT_KEYWORDS(KEYWORDS)
1283 # ---------------------
1284 # Declare a list of keywords associated to the current test group.
1285 m4_define([AT_KEYWORDS],
1286 [m4_append_uniq([AT_keywords], [$1], [ ])])
1289 # AT_CAPTURE_FILE(FILE)
1290 # ---------------------
1291 # If the current test group does not behave as expected, save the contents of
1292 # FILE in the test suite log.
1293 m4_define([AT_CAPTURE_FILE],
1294 [m4_append_uniq([AT_capture_files], ["$1"], [ \
1300 # Complete a group of related tests.
1301 m4_define([AT_CLEANUP],
1302 [m4_append([AT_help_all],
1303 m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
1305 m4_divert_pop([TEST_SCRIPT])dnl Back to TESTS
1307 echo "# -*- compilation -*-" >> "$at_group_log"
1309 AS_ECHO(["AT_ordinal. m4_defn([AT_line]): testing $1..."])
1311 m4_undivert([TEST_SCRIPT])dnl Insert the code here
1313 $at_times_p && times >"$at_times_file"
1314 ) AS_MESSAGE_LOG_FD>&1 2>&1 | eval $at_tee_pipe
1315 at_status=`cat "$at_status_file"`
1318 m4_divert_pop([TESTS])dnl Back to KILL.
1324 # Output TEXT without any shell expansion.
1325 m4_define([AT_BANNER],
1326 [m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
1327 m4_append([AT_groups_all], [ banner-]m4_defn([AT_banner_ordinal]))
1328 m4_divert_text([TESTS],
1330 banner-AT_banner_ordinal ) @%:@ Banner AT_banner_ordinal. AT_LINE
1341 # AT_DATA(FILE, CONTENTS)
1342 # -----------------------
1343 # Initialize an input data FILE with given CONTENTS, which should end with
1345 # This macro is not robust to active symbols in CONTENTS *on purpose*.
1346 # If you don't want CONTENTS to be evaluated, quote it twice.
1347 m4_define([AT_DATA],
1353 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1354 # [RUN-IF-FAIL], [RUN-IF-PASS])
1355 # ------------------------------------------------
1356 # Execute a test by performing given shell COMMANDS. These commands
1357 # should normally exit with STATUS, while producing expected STDOUT and
1358 # STDERR contents. Shell metacharacters in STDOUT and STDERR are
1359 # _not_ processed by the shell, but are treated as string literals.
1361 # STATUS, STDOUT, and STDERR are not checked if equal to `ignore'.
1363 # If STDOUT is `expout', then stdout is compared to the content of the file
1364 # `expout'. Likewise for STDERR and `experr'.
1366 # If STDOUT is `stdout', then the stdout is left in the file `stdout',
1367 # likewise for STDERR and `stderr'. Don't do this:
1369 # AT_CHECK([command >out])
1370 # # Some checks on `out'
1374 # AT_CHECK([command], [], [stdout])
1375 # # Some checks on `stdout'
1377 # You might wonder why you can't just use `ignore', then directly use stdout
1378 # and stderr left by the test suite:
1380 # AT_CHECK([command], [], [ignore])
1381 # AT_CHECK([check stdout])
1383 # If the test suite always captured data in the file `stdout', then the
1384 # second command would be trying to read and write from the same file, with
1385 # undefined behavior. Therefore, the test suite actually captures data in
1386 # an internal file of a different name, and only creates `stdout' when
1387 # explicitly requested.
1389 # Any line of stderr starting with leading blanks and a `+' are filtered
1390 # out, since most shells when tracing include subshell traces in stderr.
1391 # This may cause spurious failures when the test suite is run with `-x'.
1393 m4_define([AT_CHECK],
1394 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6],1)])
1396 # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1397 # [RUN-IF-FAIL], [RUN-IF-PASS])
1398 # ---------------------------------------------------------
1399 # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
1400 # and STDERR arguments before running the comparison.
1401 m4_define([AT_CHECK_NOESCAPE],
1402 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6])])
1405 # _AT_DECIDE_TRACEABLE(COMMANDS)
1406 # ------------------------------
1407 # Worker for for _AT_CHECK that expands to shell code. If COMMANDS are safe to
1408 # trace with `set -x', the shell code will evaluate to true. Otherwise,
1409 # the shell code will print a message stating an aspect of COMMANDS that makes
1410 # tracing them unsafe, and evaluate to false.
1412 # Tracing COMMANDS is not safe if they contain a command that spans multiple
1413 # lines. When the test suite user passes `-x' or `--trace', the test suite
1414 # precedes every command with a `set -x'. Since most tests expect a specific
1415 # stderr, if only to confirm that it is empty, the test suite filters ^+ from
1416 # the captured stderr before comparing with the expected stderr. If a command
1417 # spans multiple lines, so will its trace, but a `+' only prefixes the first
1418 # line of that trace:
1429 # In a subset of cases, one could filter such extended shell traces from stderr.
1430 # Since test commands spanning several lines are rare, I chose instead to simply
1431 # not trace COMMANDS that could yield multiple trace lines. Distinguishing such
1432 # COMMANDS became the task at hand.
1434 # These features may cause a shell command to span multiple lines:
1436 # (a) A quoted literal newline.
1440 # M4 is a hostile language for the job of parsing COMMANDS to determine whether
1441 # each literal newline is quoted, so we simply disable tracing for all COMMANDS
1442 # that bear literal newlines.
1444 # (b) A command substitution not subject to word splitting.
1446 # var=$(printf 'foo\nbar')
1448 # echo "`printf 'foo\\nbar`"
1449 # One cannot know in general the number of lines a command substitution will
1450 # yield without executing the substituted command. As such, we disable tracing
1451 # for all COMMANDS containing these constructs.
1453 # (c) A parameter expansion not subject to word splitting.
1458 # Parameter expansions appear in COMMANDS with much greater frequency than do
1459 # newlines and command substitutions, so disabling tracing for all such COMMANDS
1460 # would much more substantially devalue `testsuite -x'. To determine which
1461 # parameter expansions yield multiple lines, we escape all ``', `"', and `\' in
1462 # a copy of COMMANDS and expand that string within double quotes at runtime. If
1463 # the result of that expansion contains multiple lines, the test suite disables
1464 # tracing for the command in question.
1466 # This method leads the test suite to expand some parameters that the shell
1467 # itself will never expand due to single-quotes or backslash escapes. This is
1468 # not a problem for `$foo' expansions, which will simply yield the empty string
1469 # or some unrelated value. A `${...}' expansion could actually form invalid
1470 # shell code, however; consider `${=foo}'. Therefore, we disable tracing for
1471 # all COMMANDS containing `${...}'. This affects few COMMANDS.
1473 # This macro falls in a very hot path; the Autoconf test suite expands it 1640
1474 # times as of this writing. To give a sense of the impact of the heuristics I
1475 # just described, the test suite preemptively disables tracing for 31 of those,
1476 # and 268 contain parameter expansions that require runtime evaluation. The
1477 # balance are always safe to trace.
1479 # _AT_CHECK expands COMMANDS, but the Autoconf language does not provide a way
1480 # to safely expand arbitrary COMMANDS in an argument list, so the below tests
1481 # examine COMMANDS unexpanded.
1482 m4_define([_AT_DECIDE_TRACEABLE],
1485 dnl Examine COMMANDS for a reason to never trace COMMANDS.
1486 [m4_pushdef([at_reason],
1487 m4_cond([m4_eval(m4_index([$1], [`]) >= 0)], [1],
1488 [[a `...` command substitution]],
1489 [m4_eval(m4_index([$1], [$(]) >= 0)], [1],
1490 [[a $(...) command substitution]],
1491 [m4_eval(m4_index([$1], [${]) >= 0)], [1],
1492 [[a ${...} parameter expansion]],
1493 [m4_eval(m4_index([$1], m4_newline) >= 0)], [1],
1494 [[an embedded newline]],
1498 m4_ifval(m4_defn([at_reason]),
1499 [{ echo 'Not enabling shell tracing (command contains ]m4_defn([at_reason])[)'; false; }],
1500 [m4_if(m4_index([$1], [$]), [-1],
1501 dnl We know at build time that tracing COMMANDS is always safe.
1502 [test -n "$at_traceon"],
1503 dnl COMMANDS may contain parameter expansions; expand them at runtime.
1504 [test -n "$at_traceon" && at_func_check_newline "AS_ESCAPE([$1], [`\"])"])])[]dnl
1505 m4_popdef([at_reason])])
1508 # AT_DIFF_STDERR/AT_DIFF_STDOUT
1509 # -----------------------------
1510 # These are subroutines of AT_CHECK. Using indirect dispatch is a tad
1511 # faster than using m4_case, and these are called very frequently.
1512 m4_define([AT_DIFF_STDERR(stderr)],
1513 [echo stderr:; tee stderr <"$at_stderr"])
1514 m4_define([AT_DIFF_STDERR(ignore)],
1515 [echo stderr:; cat "$at_stderr"])
1516 m4_define([AT_DIFF_STDERR(experr)],
1517 [$at_diff experr "$at_stderr" || at_failed=:])
1518 m4_define([AT_DIFF_STDERR()],
1519 [at_func_diff_devnull "$at_stderr" || at_failed=:])
1521 m4_define([AT_DIFF_STDOUT(stdout)],
1522 [echo stdout:; tee stdout <"$at_stdout"])
1523 m4_define([AT_DIFF_STDOUT(ignore)],
1524 [echo stdout:; cat "$at_stdout"])
1525 m4_define([AT_DIFF_STDOUT(expout)],
1526 [$at_diff expout "$at_stdout" || at_failed=:])
1527 m4_define([AT_DIFF_STDOUT()],
1528 [at_func_diff_devnull "$at_stdout" || at_failed=:])
1530 # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1531 # [RUN-IF-FAIL], [RUN-IF-PASS], SHELL_ESCAPE_IO)
1532 # ---------------------------------------------------------
1533 # Worker for AT_CHECK & AT_CHECK_NOESCAPE. The final SHELL-ESCAPE-IO
1534 # argument determines whether the STDOUT & STDERR arguments will be escaped or
1538 # Implementation Details
1539 # ----------------------
1540 # Ideally, we would like to run
1542 # ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
1544 # but we must group COMMANDS as it is not limited to a single command, and
1545 # then the shells will save the traces in at-stderr. So we have to filter
1546 # them out when checking stderr, and we must send them into the test suite's
1547 # stderr to honor -x properly. Since only the first line of the trace of a
1548 # multiline command starts with a `+', and I know of no straightforward way to
1549 # filter out the unadorned trace lines, we disable shell tracing entirely for
1550 # commands that could span multiple lines.
1552 # Limiting COMMANDS to a single command is not good either, since them
1553 # the user herself would use {} or (), and then we face the same problem.
1555 # But then, there is no point in running
1557 # ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
1559 # instead of the simpler
1561 # ( $at_traceon; $1 ) >at-stdout 2>at-stder1
1563 m4_define([_AT_CHECK],
1565 AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([$1])"])
1566 echo AT_LINE >"$at_check_line_file"
1568 if _AT_DECIDE_TRACEABLE([$1]); then
1569 ( $at_traceon; $1 ) >"$at_stdout" 2>"$at_stder1"
1570 at_func_filter_trace $?
1572 ( :; $1 ) >"$at_stdout" 2>"$at_stderr"
1576 m4_ifdef([AT_DIFF_STDERR($4)], [m4_indir([AT_DIFF_STDERR($4)])],
1577 [echo >>"$at_stderr"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$4])],[$4])"]) | \
1578 $at_diff - "$at_stderr" || at_failed=:])
1579 m4_ifdef([AT_DIFF_STDOUT($3)], [m4_indir([AT_DIFF_STDOUT($3)])],
1580 [echo >>"$at_stdout"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$3])],[$3])"]) | \
1581 $at_diff - "$at_stdout" || at_failed=:])
1582 m4_if([$2], [ignore], [at_func_check_skip],
1583 [at_func_check_status m4_default([$2], [0])]) dnl
1584 $at_status "$at_srcdir/AT_LINE"
1585 AS_IF($at_failed, [$5], [$6])
1586 $at_failed && at_func_log_failure AT_capture_files