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 # Output shell initialization for the associative array of banner text.
101 # Like DEFAULTS but run after argument processing for purposes of
102 # optimization. Do anything else that needs to be done to prepare for
103 # tests. Sets up verbose and log file descriptors. Sets and logs PATH.
104 # Declares functions shared among the tests.
106 # The core of the test suite.
109 # The collector for code for each test, the ``normal'' diversion, but
110 # undiverted into other locations before final output.
113 # Contents of each test group. The tests deliberately occur after the
114 # end of the shell script, so that the shell need not spend time parsing
115 # commands it will not execute.
117 m4_define([_m4_divert(DEFAULTS)], 100)
118 m4_define([_m4_divert(PARSE_ARGS_BEGIN)], 200)
119 m4_define([_m4_divert(PARSE_ARGS)], 201)
120 m4_define([_m4_divert(PARSE_ARGS_END)], 202)
121 m4_define([_m4_divert(HELP)], 300)
122 m4_define([_m4_divert(HELP_MODES)], 301)
123 m4_define([_m4_divert(HELP_TUNING)], 302)
124 m4_define([_m4_divert(HELP_OTHER)], 303)
125 m4_define([_m4_divert(HELP_END)], 304)
126 m4_define([_m4_divert(VERSION)], 350)
127 m4_define([_m4_divert(VERSION_NOTICES)], 351)
128 m4_define([_m4_divert(VERSION_END)], 352)
129 m4_define([_m4_divert(BANNERS)], 400)
130 m4_define([_m4_divert(PREPARE_TESTS)], 401)
131 m4_define([_m4_divert(TESTS)], 402)
132 m4_define([_m4_divert(TEST_SCRIPT)], 450)
133 m4_define([_m4_divert(TEST_GROUPS)], 500)
138 # Return the current file sans directory, a colon, and the current
139 # line. Be sure to return a _quoted_ file name, so if, for instance,
140 # the user is lunatic enough to have a file named `dnl' (and I, for
141 # one, love to be brainless and stubborn sometimes), then we return a
144 # Gee, we can't use simply
146 # m4_bpatsubst(__file__, [^.*/\(.*\)], [[\1]])
148 # since then, since `dnl' doesn't match the pattern, it is returned
149 # with once quotation level less, so you lose! And since GNU M4
150 # is one of the biggest junk in the whole universe wrt regexp, don't
151 # even think about using `?' or `\?'. Bah, `*' will do.
152 # Pleeeeeeeease, Gary, provide us with dirname and ERE!
154 # M4 recompiles the regular expression for every m4_bpatsubst, but __file__
155 # rarely changes. Be fast - only compute the dirname when necessary; for
156 # autoconf alone, this shaves off several seconds in building testsuite.
157 m4_define([_AT_LINE_file])
158 m4_define([_AT_LINE_base])
160 [m4_if(m4_defn([_AT_LINE_file]), __file__, [],
161 [m4_do([m4_define([_AT_LINE_file], __file__)],
162 [m4_define([_AT_LINE_base],
163 m4_bpatsubst(__file__, [^.*/\([^/]*\)$],
165 m4_defn([_AT_LINE_base]):__line__])
168 # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR)
169 # ------------------------------------------
170 # Normalize SHELL-VAR so that its value has the same number of digits as
171 # all the other test group numbers.
172 m4_define([_AT_NORMALIZE_TEST_GROUP_NUMBER],
176 '"$at_format"'*) break;;
183 # AT_INIT([TESTSUITE-NAME])
184 # -------------------------
187 [m4_pattern_forbid([^_?AT_])
188 m4_define([AT_TESTSUITE_NAME],
189 m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1], [: $1]))
190 m4_define([AT_ordinal], 0)
191 m4_define([AT_banner_ordinal], 0)
192 m4_define([AT_groups_all], [])
193 m4_define([AT_help_all], [])
195 m4_divert_push([DEFAULTS])dnl
197 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
199 This test suite is free software; the Free Software Foundation gives
200 unlimited permission to copy, distribute and modify it.])
203 SHELL=${CONFIG_SHELL-/bin/sh}
208 m4_divert_push([BANNERS])dnl
210 # Should we print banners? at_groups is space-separated for entire test,
211 # newline-separated if only a subset of the testsuite is run.
213 *' '*' '* | *"$as_nl"*"$as_nl"* )
214 at_print_banners=: ;;
215 * ) at_print_banners=false ;;
217 # Text for banner N, set to empty once printed.
218 m4_divert_pop([BANNERS])dnl back to DEFAULTS
219 m4_divert_push([PREPARE_TESTS])dnl
221 ## --------------- ##
222 ## Shell functions ##
223 ## --------------- ##
225 # at_func_banner NUMBER
226 # ---------------------
227 # Output banner NUMBER, provided the testsuite is running multiple groups
228 # and this particular banner has not yet been printed.
231 $at_print_banners || return 0
232 eval at_banner_text=\$at_banner_text_$[1]
233 test "x$at_banner_text" = x && return 0
234 eval at_banner_text_$[1]=
235 AS_ECHO(["$as_nl$at_banner_text$as_nl"])
238 # at_func_check_newline COMMAND
239 # -----------------------------
240 # Test if COMMAND includes a newline and, if so, print a message and return
242 at_func_check_newline ()
246 '*) echo 'Not enabling shell tracing (command contains an embedded newline)'
252 # at_func_filter_trace EXIT-CODE
253 # ------------------------------
254 # Split the contents of file "$at_stder1" into the "set -x" trace (on stderr)
255 # and the other lines (on file "$at_stderr"). Return the exit code EXIT-CODE.
256 at_func_filter_trace ()
258 grep '^ *+' "$at_stder1" >&2
259 grep -v '^ *+' "$at_stder1" >"$at_stderr"
263 # at_func_log_failure FILE-LIST
264 # -----------------------------
265 # Copy the files in the list on stdout with a "> " prefix, and exit the shell
266 # with a failure exit code.
267 at_func_log_failure ()
270 do AS_ECHO(["$file:"]); sed 's/^/> /' "$file"; done
271 echo 1 > "$at_status_file"
275 # at_func_check_skip EXIT-CODE
276 # ----------------------------
277 # Check whether EXIT-CODE is the special exit code 77, and if so exit the shell
278 # with that same exit code.
279 at_func_check_skip ()
282 77) echo 77 > "$at_status_file"; exit 77;;
286 # at_func_check_status EXPECTED EXIT-CODE LINE
287 # --------------------------------------------
288 # Check whether EXIT-CODE is the expected exit code, and if so do nothing.
289 # Otherwise, if it is 77 exit the shell with that same exit code; if it is
290 # anything else print an error message and fail the test.
291 at_func_check_status ()
293 dnl This order ensures that we don't `skip' if we are precisely checking
297 77) echo 77 > "$at_status_file"; exit 77;;
298 *) AS_ECHO(["$[3]: exit code was $[2], expected $[1]"])
303 # at_func_diff_devnull FILE
304 # -------------------------
305 # Emit a diff between /dev/null and FILE. Uses "test -s" to avoid useless
307 at_func_diff_devnull ()
309 test -s "$[1]" || return 0
310 $at_diff "$at_devnull" "$[1]"
313 # at_func_test NUMBER
314 # -------------------
315 # Parse out test NUMBER from the tail of this file.
318 sed -n '/^@%:@AT_START_'$[1]'$/,/^@%:@AT_STOP_'$[1]'$/p' "$at_myself" \
322 # at_func_create_debugging_script
323 # -------------------------------
324 # Create the debugging script $at_group_dir/run which will reproduce the
325 # current test group.
326 at_func_create_debugging_script ()
330 echo 'test "${ZSH_VERSION+set}" = set dnl
331 && alias -g '\''${1+"$[@]"}'\''='\''"$[@]"'\'''
332 AS_ECHO(["cd '$at_dir'"])
333 AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} $[0] -v -d ]dnl
334 [$at_debug_args $at_group \${1+\"\$[@]\"}"])
337 chmod +x $at_group_dir/run
342 # Arithmetic evaluation, avoids expr if the shell is sane.
344 # subshell and eval are needed to keep Solaris sh from bailing out:
345 if ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then
346 [#] With "$[@]", bash does not split positional parameters:
347 eval 'at_func_arith ()
349 at_func_arith_result=$(( $[*] ))
354 at_func_arith_result=`expr "$[@]"`
358 ## ---------------------- ##
359 ## End of shell functions ##
360 ## ---------------------- ##
361 m4_divert_pop([PREPARE_TESTS])dnl back to DEFAULTS
363 # Load the config file.
364 for at_file in atconfig atlocal
366 test -r $at_file || continue
367 . ./$at_file || AS_ERROR([invalid content: $at_file])
370 # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
371 : ${at_top_build_prefix=$at_top_builddir}
373 # atconfig delivers names relative to the directory the test suite is
374 # in, but the groups themselves are run in testsuite-dir/group-dir.
375 if test -n "$at_top_srcdir"; then
377 for at_dir in srcdir top_srcdir top_build_prefix
379 at_val=AS_VAR_GET([at_$at_dir])
381 [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
382 *) at_prefix=../../ ;;
384 AS_VAR_SET([$at_dir], [$at_prefix$at_val])
388 # Not all shells have the 'times' builtin; the subshell is needed to make
389 # sure we discard the 'times: not found' message from the shell.
391 (times) >/dev/null 2>&1 && at_times_p=:
393 # CLI Arguments to pass to the debugging scripts.
397 # Shall we be verbose? ':' means no, empty means yes.
401 # Shall we keep the debug scripts? Must be `:' when the suite is
402 # run by a debug script, so that the script doesn't remove itself.
404 # Display help message?
406 # Display the version message?
413 # The directory we are in.
415 # An absolute reference to this testsuite script.
416 dnl m4-double quote, to preserve []
418 [\\/]* | ?:[\\/]* ) at_myself=$as_myself ;;
419 * ) at_myself=$at_dir/$as_myself ;;
421 # The directory the whole suite works in.
422 # Should be absolute to let the user `cd' at will.
423 at_suite_dir=$at_dir/$as_me.dir
424 # The file containing the suite.
425 at_suite_log=$at_dir/$as_me.log
426 # The file containing the location of the last AT_CHECK.
427 at_check_line_file=$at_suite_dir/at-check-line
428 # The file containing the exit status of the last command.
429 at_status_file=$at_suite_dir/at-status
430 # The files containing the output of the tested commands.
431 at_stdout=$at_suite_dir/at-stdout
432 at_stder1=$at_suite_dir/at-stder1
433 at_stderr=$at_suite_dir/at-stderr
434 # The file containing the function to run a test group.
435 at_test_source=$at_suite_dir/at-test-source
436 # The file containing dates.
437 at_times_file=$at_suite_dir/at-times
438 m4_divert_pop([DEFAULTS])dnl
439 m4_wrap([m4_divert_text([DEFAULTS],
441 # List of the tested programs.
442 at_tested='m4_ifdef([AT_tested],
443 [m4_translit(m4_dquote(m4_defn([AT_tested])), [ ], m4_newline)])'
444 # List of the all the test groups.
445 at_groups_all='AT_groups_all'
446 # As many question marks as there are digits in the last test group number.
447 # Used to normalize the test group numbers so that `ls' lists them in
449 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
450 # Description of all the test groups.
451 at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"
453 # at_func_validate_ranges [N...]
454 # ------------------------------
455 # validate test group ranges
456 at_func_validate_ranges ()
460 if test $at_grp -lt 1 || test $at_grp -gt AT_ordinal; then
461 AS_ECHO(["invalid test group: $at_grp"]) >&2
466 m4_divert_push([PARSE_ARGS])dnl
471 # If the previous option needs an argument, assign it.
472 if test -n "$at_prev"; then
473 at_option=$at_prev=$at_option
478 *=*) at_optarg=`expr "x$at_option" : 'x[[^=]]*=\(.*\)'` ;;
482 # Accept the important Cygnus configure options, so we can diagnose typos.
498 test -d "$at_suite_dir" &&
499 find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
500 rm -f -r "$at_suite_dir" "$at_suite_log"
514 at_verbose=; at_quiet=:
518 at_traceon='set -x'; at_traceoff='set +x'
521 [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
522 at_func_validate_ranges $at_option
523 at_groups="$at_groups$at_option "
527 [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
528 at_range_start=`echo $at_option |tr -d X-`
529 at_func_validate_ranges $at_range_start
530 at_range=`AS_ECHO([" $at_groups_all "]) | \
531 sed -e 's/^.* \('$at_range_start' \)/\1/'`
532 at_groups="$at_groups$at_range "
535 [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
536 at_range_end=`echo $at_option |tr -d X-`
537 at_func_validate_ranges $at_range_end
538 at_range=`AS_ECHO([" $at_groups_all "]) | \
539 sed -e 's/\( '$at_range_end'\) .*$/\1/'`
540 at_groups="$at_groups$at_range "
543 [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
544 [[0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9]] | \
545 [[0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
546 [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
547 [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
548 [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
549 at_range_start=`expr $at_option : '\(.*\)-'`
550 at_range_end=`expr $at_option : '.*-\(.*\)'`
551 if test $at_range_start -gt $at_range_end; then
553 at_range_end=$at_range_start
554 at_range_start=$at_tmp
556 at_func_validate_ranges $at_range_start $at_range_end
557 at_range=`AS_ECHO([" $at_groups_all "]) | \
558 sed -e 's/^.*\( '$at_range_start' \)/\1/' \
559 -e 's/\( '$at_range_end'\) .*$/\1/'`
560 at_groups="$at_groups$at_range "
568 at_groups_selected=$at_help_all
580 at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
583 # It is on purpose that we match the test group titles too.
584 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
585 grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
587 # Smash the newlines.
588 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//' |
591 at_groups="$at_groups$at_groups_selected "
593 m4_divert_pop([PARSE_ARGS])dnl
594 dnl Process *=* last to allow for user specified --option=* type arguments.
595 m4_divert_push([PARSE_ARGS_END])dnl
598 at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
599 # Reject names that are not valid shell variable names.
600 expr "x$at_envvar" : "[.*[^_$as_cr_alnum]]" >/dev/null &&
601 AS_ERROR([invalid variable name: $at_envvar])
602 at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
603 eval "$at_envvar='$at_value'"
605 # Propagate to debug scripts.
606 at_debug_args="$at_debug_args $at_envvar='$at_value'"
609 *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
610 AS_ECHO(["Try \`$[0] --help' for more information."]) >&2
616 # Selected test groups.
617 if test -z "$at_groups"; then
618 at_groups=$at_groups_all
620 # Sort the tests, removing duplicates.
621 at_groups=`AS_ECHO(["$at_groups"]) | tr ' ' "$as_nl" | sort -nu`
623 m4_divert_pop([PARSE_ARGS_END])dnl
624 m4_divert_push([HELP])dnl
629 Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
631 Run all the tests, or the selected TESTS, given by numeric ranges, and
632 save a detailed log file. Upon failure, create debugging scripts.
634 You should not change environment variables unless explicitly passed
635 as command line arguments. Set \`AUTOTEST_PATH' to select the executables
636 to exercise. Each relative directory is expanded as build and source
637 directories relatively to the top level of this distribution. E.g.,
639 $ $[0] AUTOTEST_PATH=bin
641 possibly amounts into
643 PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH
645 m4_divert_pop([HELP])dnl
646 m4_divert_push([HELP_MODES])dnl
650 -h, --help print the help message, then exit
651 -V, --version print version number, then exit
652 -c, --clean remove all the files this test suite might create and exit
653 -l, --list describes all the tests, or the selected TESTS
655 m4_divert_pop([HELP_MODES])dnl
656 m4_divert_push([HELP_TUNING])dnl
659 dnl extra quoting prevents emacs whitespace mode from putting tabs in output
661 -k, --keywords=KEYWORDS
662 [ select the tests matching all the comma-separated KEYWORDS]
663 [ multiple \`-k' accumulate; prefixed \`!' negates a KEYWORD]
664 -e, --errexit abort as soon as a test fails; implies --debug
665 -v, --verbose force more detailed output
666 [ default for debugging scripts]
667 -d, --debug inhibit clean up and top-level logging
668 [ default for debugging scripts]
669 -x, --trace enable tests shell tracing
671 m4_divert_pop([HELP_TUNING])dnl
672 m4_divert_push([HELP_END])dnl
675 Report bugs to <AT_PACKAGE_BUGREPORT>.
683 AT_TESTSUITE_NAME test groups:
685 NUM: FILE-NAME:LINE TEST-GROUP-NAME
689 # Passing at_groups is tricky. We cannot use it to form a literal string
690 # or regexp because of the limitation of AIX awk. And Solaris' awk
691 # doesn't grok more than 99 fields in a record, so we have to use `split'.
692 # at_groups needs to be space-separated for this script to work.
695 at_groups=`AS_ECHO(["$at_groups"]) | tr "$as_nl" ' '` ;;
697 AS_ECHO(["$at_groups$as_nl$at_help_all"]) |
698 awk 'BEGIN { FS = ";" }
700 for (n = split($ 0, a, " "); n; n--) selected[[a[n]]] = 1
704 if (selected[[$ 1]]) {
705 printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
706 if ($ 4) printf " %s\n", $ 4
711 m4_divert_pop([HELP_END])dnl
712 m4_divert_push([VERSION])dnl
713 if $at_version_p; then
714 AS_ECHO(["$as_me (AT_PACKAGE_STRING)"])
716 m4_divert_pop([VERSION])dnl
717 m4_divert_push([VERSION_END])dnl
721 m4_divert_pop([VERSION_END])dnl
722 m4_divert_push([PREPARE_TESTS])dnl
724 # Don't take risks: use only absolute directories in PATH.
726 # For stand-alone test suites, AUTOTEST_PATH is relative to `.'.
728 # For embedded test suites, AUTOTEST_PATH is relative to the top level
729 # of the package. Then expand it into build/src parts, since users
730 # may create executables in both places.
731 AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s|:|$PATH_SEPARATOR|g"`
733 _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
734 [test -n "$at_path" && at_path=$at_path$PATH_SEPARATOR
736 [[\\/]]* | ?:[[\\/]]* )
737 at_path=$at_path$as_dir
740 if test -z "$at_top_build_prefix"; then
741 # Stand-alone test suite.
742 at_path=$at_path$as_dir
744 # Embedded test suite.
745 at_path=$at_path$at_top_build_prefix$as_dir$PATH_SEPARATOR
746 at_path=$at_path$at_top_srcdir/$as_dir
751 # Now build and simplify PATH.
753 # There might be directories that don't exist, but don't redirect
754 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
756 _AS_PATH_WALK([$at_path],
757 [as_dir=`(cd "$as_dir" && pwd) 2>/dev/null`
758 test -d "$as_dir" || continue
759 case $PATH_SEPARATOR$at_new_path$PATH_SEPARATOR in
760 *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR*) ;;
761 $PATH_SEPARATOR$PATH_SEPARATOR) at_new_path=$as_dir ;;
762 *) at_new_path=$at_new_path$PATH_SEPARATOR$as_dir ;;
767 # Setting up the FDs.
768 # 5 is the log file. Not to be overwritten if `-d'.
769 m4_define([AS_MESSAGE_LOG_FD], [5])
771 at_suite_log=/dev/null
775 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
778 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
780 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
783 AS_ECHO(["$as_me: command line was:"])
784 AS_ECHO([" \$ $[0] $at_cli_args"])
787 # Try to find a few ChangeLogs in case it might help determining the
788 # exact version. Use the relative dir: if the top dir is a symlink,
789 # find will not follow it (and options to follow the links are not
790 # portable), which would result in no output here. Prune directories
791 # matching the package tarname, since they tend to be leftovers from
792 # `make dist' or `make distcheck' and contain redundant or stale logs.
793 if test -n "$at_top_srcdir"; then
794 AS_BOX([ChangeLogs.])
796 for at_file in `find "$at_top_srcdir" m4_ifdef([AT_PACKAGE_TARNAME],
797 [-name "AT_PACKAGE_TARNAME-*" -prune -o ])-name ChangeLog -print`
799 AS_ECHO(["$as_me: $at_file:"])
800 sed 's/^/| /;10q' $at_file
808 # Contents of the config files.
809 for at_file in atconfig atlocal
811 test -r $at_file || continue
812 AS_ECHO(["$as_me: $at_file:"])
813 sed 's/^/| /' $at_file
817 AS_BOX([Tested programs.])
819 } >&AS_MESSAGE_LOG_FD
821 # Report what programs are being tested.
822 for at_program in : $at_tested
824 test "$at_program" = : && continue
825 _AS_PATH_WALK([$PATH], [test -f "$as_dir/$at_program" && break])
826 if test -f "$as_dir/$at_program"; then
828 AS_ECHO(["$at_srcdir/AT_LINE: $as_dir/$at_program --version"])
829 "$as_dir/$at_program" --version </dev/null
831 } >&AS_MESSAGE_LOG_FD 2>&1
833 AS_ERROR([cannot find $at_program])
838 AS_BOX([Running the tests.])
839 } >&AS_MESSAGE_LOG_FD
842 at_start_time=`date +%s 2>/dev/null`
843 AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
850 m4_divert_pop([PREPARE_TESTS])dnl
851 m4_divert_push([TESTS])dnl
853 # Create the master directory if it doesn't already exist.
854 test -d "$at_suite_dir" ||
855 mkdir "$at_suite_dir" ||
856 AS_ERROR([cannot create '$at_suite_dir'])
858 # Can we diff with `/dev/null'? DU 5.0 refuses.
859 if diff /dev/null /dev/null >/dev/null 2>&1; then
862 at_devnull=$at_suite_dir/devnull
866 # Use `diff -u' when possible.
867 if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
875 m4_text_box([Driver loop.])
876 for at_group in $at_groups
878 # Be sure to come back to the top test directory.
881 # Clearly separate the test groups when verbose.
882 test $at_group_count != 0 && $at_verbose echo
884 at_group_normalized=$at_group
885 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
887 # Create a fresh directory for the next test group, and enter.
888 at_group_dir=$at_suite_dir/$at_group_normalized
889 at_group_log=$at_group_dir/$as_me.log
890 if test -d "$at_group_dir"; then
891 find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
892 rm -fr "$at_group_dir" ||
893 AS_WARN([test directory could not be cleaned.])
895 # Be tolerant if the above `rm' was not able to remove the directory.
896 AS_MKDIR_P([$at_group_dir])
899 echo 0 > "$at_status_file"
901 # In verbose mode, append to the log file *and* show on
902 # the standard output; in quiet mode only write to the log
903 if test -z "$at_verbose"; then
904 at_tee_pipe='tee -a "$at_group_log"'
906 at_tee_pipe='cat >> "$at_group_log"'
909 if at_func_test $at_group && . "$at_test_source"; then :; else
910 AS_ECHO(["$as_me: unable to parse test group: $at_group"]) >&2
914 # Be sure to come back to the suite directory, in particular
915 # since below we might `rm' the group directory we are in currently.
918 if test ! -f "$at_check_line_file"; then
919 sed "s/^ */$as_me: warning: /" <<_ATEOF
920 A failure happened in a test group before any test could be
921 run. This means that test suite is improperly designed. Please
922 report this failure to <AT_PACKAGE_BUGREPORT>.
924 AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
926 at_func_arith 1 + $at_group_count
927 at_group_count=$at_func_arith_result
928 $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
929 AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
930 case $at_xfail:$at_status in
932 at_msg="UNEXPECTED PASS"
933 at_xpass_list="$at_xpass_list $at_group"
934 at_errexit=$at_errexit_p
938 at_pass_list="$at_pass_list $at_group"
942 at_msg='skipped ('`cat "$at_check_line_file"`')'
943 at_skip_list="$at_skip_list $at_group"
947 at_msg='expected failure ('`cat "$at_check_line_file"`')'
948 at_xfail_list="$at_xfail_list $at_group"
952 at_msg='FAILED ('`cat "$at_check_line_file"`')'
953 at_fail_list="$at_fail_list $at_group"
954 at_errexit=$at_errexit_p
957 # Make sure there is a separator even with long titles.
958 AS_ECHO([" $at_msg"])
959 at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
962 # $at_times_file is only available if the group succeeded.
963 # We're not including the group log, so the success message
964 # is written in the global log separately. But we also
965 # write to the group log in case they're using -d.
966 if test -f "$at_times_file"; then
967 at_log_msg="$at_log_msg ("`sed 1d "$at_times_file"`')'
968 rm -f "$at_times_file"
970 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
971 AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
973 # Cleanup the group directory, unless the user wants the files.
974 if $at_debug_p ; then
975 at_func_create_debugging_script
976 elif test -d "$at_group_dir"; then
977 find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
978 rm -fr "$at_group_dir"
982 # Upon failure, include the log into the testsuite's global
983 # log. The failure message is written in the group log. It
984 # is later included in the global log.
985 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
987 # Upon failure, keep the group directory for autopsy, and
988 # create the debugging script.
989 at_func_create_debugging_script
995 # Back to the top directory.
998 # Compute the duration of the suite.
1000 at_stop_time=`date +%s 2>/dev/null`
1001 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
1002 case $at_start_time,$at_stop_time in
1004 at_func_arith $at_stop_time - $at_start_time
1005 at_duration_s=$at_func_arith_result
1006 at_func_arith $at_duration_s / 60
1007 at_duration_m=$at_func_arith_result
1008 at_func_arith $at_duration_m / 60
1009 at_duration_h=$at_func_arith_result
1010 at_func_arith $at_duration_s % 60
1011 at_duration_s=$at_func_arith_result
1012 at_func_arith $at_duration_m % 60
1013 at_duration_m=$at_func_arith_result
1014 at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
1015 AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
1019 # Wrap up the test suite with summary statistics.
1020 set X $at_skip_list; shift; at_skip_count=$[@%:@]
1021 set X $at_fail_list; shift; at_fail_count=$[@%:@]
1022 set X $at_xpass_list; shift; at_xpass_count=$[@%:@]
1023 set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
1025 at_func_arith $at_group_count - $at_skip_count
1026 at_run_count=$at_func_arith_result
1027 at_func_arith $at_xpass_count + $at_fail_count
1028 at_unexpected_count=$at_func_arith_result
1029 at_func_arith $at_xfail_count + $at_fail_count
1030 at_total_fail_count=$at_func_arith_result
1033 AS_BOX([Test results.])
1037 AS_BOX([Test results.])
1039 } >&AS_MESSAGE_LOG_FD
1042 dnl FIXME: this code is as far from i18n-cleanness as man
1043 dnl could imagine...
1045 if test $at_run_count = 1; then
1049 at_result="$at_run_count tests"
1052 if $at_errexit_p && test $at_unexpected_count != 0; then
1053 if test $at_xpass_count = 1; then
1054 at_result="$at_result $at_were run, one passed"
1056 at_result="$at_result $at_were run, one failed"
1058 at_result="$at_result unexpectedly and inhibited subsequent tests."
1060 # Don't you just love exponential explosion of the number of cases?
1061 case $at_xpass_count:$at_fail_count:$at_xfail_count in
1063 0:0:0) at_result="$at_result $at_were successful." ;;
1064 0:0:*) at_result="$at_result behaved as expected." ;;
1066 # Some unexpected failures
1067 0:*:0) at_result="$at_result $at_were run,
1068 $at_fail_count failed unexpectedly." ;;
1070 # Some failures, both expected and unexpected
1071 0:*:1) at_result="$at_result $at_were run,
1072 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1073 0:*:*) at_result="$at_result $at_were run,
1074 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1076 # No unexpected failures, but some xpasses
1077 *:0:*) at_result="$at_result $at_were run,
1078 $at_xpass_count passed unexpectedly." ;;
1080 # No expected failures, but failures and xpasses
1081 *:1:0) at_result="$at_result $at_were run,
1082 $at_unexpected_count did not behave as expected dnl
1083 ($at_fail_count unexpected failure)." ;;
1084 *:*:0) at_result="$at_result $at_were run,
1085 $at_unexpected_count did not behave as expected dnl
1086 ($at_fail_count unexpected failures)." ;;
1089 *:*:1) at_result="$at_result $at_were run,
1090 $at_xpass_count passed unexpectedly,
1091 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1092 *:*:*) at_result="$at_result $at_were run,
1093 $at_xpass_count passed unexpectedly,
1094 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1097 if test $at_skip_count = 0 && test $at_run_count -gt 1; then
1098 at_result="All $at_result"
1102 # Now put skips in the mix.
1103 case $at_skip_count in
1105 1) at_result="$at_result
1106 1 test was skipped." ;;
1107 *) at_result="$at_result
1108 $at_skip_count tests were skipped." ;;
1111 if test $at_unexpected_count = 0; then
1113 echo "$at_result" >&AS_MESSAGE_LOG_FD
1115 echo "ERROR: $at_result" >&2
1116 echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
1119 AS_BOX([Summary of the failures.])
1121 # Summary of failed and skipped tests.
1122 if test $at_fail_count != 0; then
1123 echo "Failed tests:"
1124 $SHELL "$[0]" $at_fail_list --list
1127 if test $at_skip_count != 0; then
1128 echo "Skipped tests:"
1129 $SHELL "$[0]" $at_skip_list --list
1132 if test $at_xpass_count != 0; then
1133 echo "Unexpected passes:"
1134 $SHELL "$[0]" $at_xpass_list --list
1137 if test $at_fail_count != 0; then
1138 AS_BOX([Detailed failed tests.])
1140 for at_group in $at_fail_list
1142 at_group_normalized=$at_group
1143 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1144 cat "$at_suite_dir/$at_group_normalized/$as_me.log"
1149 if test -n "$at_top_srcdir"; then
1150 AS_BOX([${at_top_build_prefix}config.log])
1151 sed 's/^/| /' ${at_top_build_prefix}config.log
1154 } >&AS_MESSAGE_LOG_FD
1156 AS_BOX([$as_me.log was created.])
1159 AS_ECHO(["Please send \`${at_testdir+${at_testdir}/}$as_me.log' ]dnl
1160 [and all information you think might help:
1162 To: <AT_PACKAGE_BUGREPORT>
1163 Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me:dnl
1164 $at_fail_list${at_fail_list:+ failed${at_xpass_list:+,}}dnl
1165 $at_xpass_list${at_xpass_list:+ passed unexpectedly}
1167 if test $at_debug_p = false; then
1169 echo 'You may investigate any problem if you feel able to do so, in which'
1170 echo 'case the test suite provides a good starting point. Its output may'
1171 AS_ECHO(["be found below \`${at_testdir+${at_testdir}/}$as_me.dir'."])
1179 m4_text_box([Actual tests.])
1180 m4_divert_pop([TESTS])dnl
1181 dnl End of AT_INIT: divert to KILL, only test groups are to be
1182 dnl output, the rest is ignored. Current diversion is BODY, inherited
1184 m4_divert_pop([BODY])
1185 m4_divert_push([KILL])
1189 # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
1190 # [ACTION-IF-NOT-GIVEN])
1191 # ---------------------------------------------------------------------------
1192 # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
1193 m4_defun([_AT_ARG_OPTION],
1194 [m4_divert_once([HELP_OTHER],
1199 ])dnl m4_divert_once HELP_OTHER
1200 m4_divert_text([HELP_OTHER],
1204 dnl Turn our options into our desired strings
1205 m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
1206 m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
1207 m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
1208 m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
1209 m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
1210 [m4_define_default([AT_first_option],AT_option)dnl
1211 m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
1212 m4_append([AT_case_no],[--no]AT_option, [ | ])dnl
1213 m4_append([AT_case_arg],
1214 m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
1215 ])dnl m4_foreach AT_option
1216 dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
1217 m4_divert_once([PARSE_ARGS_BEGIN],
1220 ## Set up package specific options.
1223 m4_divert_text([PARSE_ARGS_BEGIN],
1224 [dnl Provide a default value for options without arguments.
1225 m4_ifvaln([$3],,[at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false])dnl
1226 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=false
1227 ])dnl m4_divert_text DEFAULTS
1228 m4_ifval([$3],[m4_divert_once([PARSE_ARGS_END],
1231 ## Verify our last option didn't require an argument
1233 AS_IF([test -n "$at_prev"],[AS_ERROR([`$at_prev' requires an argument.])])])])
1234 m4_divert_text([PARSE_ARGS],
1235 [dnl Parse the options and args when necessary.
1238 at_prev=--m4_bpatsubst([AT_first_option], -, _)
1241 at_arg_[]m4_bpatsubst([AT_first_option], -, _)=$at_optarg
1242 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1247 at_arg_[]m4_bpatsubst([AT_first_option], -, _)=:
1248 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1249 m4_ifval([$4],[$4])dnl
1253 at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false
1254 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1255 m4_ifval([$4],[$4])dnl
1256 ;;])dnl m4_ifvaln $3
1257 ])dnl m4_divert_text PARSE_ARGS
1259 [m4_divert_once([PARSE_ARGS_END],
1262 ## Process package specific options when _not_ supplied.
1263 ##])dnl m4_divert_once PARSE_ARGS_END
1264 m4_divert_text([PARSE_ARGS_END],
1266 AS_IF([$at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)],,[$5])dnl
1267 ])dnl m4_divert_text PARSE_ARGS_END
1269 ])dnl _AT_ARG_OPTION
1272 # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1273 # ------------------------------------------------------------------------
1274 # Accept a set of OPTIONS with arguments. Add HELP-TEXT to the HELP_OTHER
1277 # Preceding dashes should not be passed into OPTIONS. Users will be required
1278 # to pass `--' before long options and `-' before single character options.
1280 # $at_arg_OPTION will be set to `:' if this option is received, `false' if
1281 # if --noOPTION is received, and `false' by default.
1283 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1284 # $at_optarg set to `:' or `false' as appropriate. $at_optarg is actually
1285 # just a copy of $at_arg_OPTION.
1287 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1288 # if no option from OPTIONS was found.
1289 m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
1292 # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1293 # ---------------------------------------------------------------------------
1294 # Accept a set of OPTIONS with arguments, seperated by commas. Add HELP-TEXT
1295 # to the HELP_OTHER diversion.
1297 # Preceding dashes should not be passed into OPTIONS. Users will be required
1298 # to pass `--' before long options and `-' before single character options.
1300 # By default, any argument to these options will be assigned to the shell
1301 # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
1302 # any `-' characters replaced with `_'.
1304 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1305 # $at_optarg set. $at_optarg is actually just a copy of $at_arg_OPTION.
1307 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1308 # if no option from OPTIONS was found.
1309 m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
1312 # AT_TESTED(PROGRAMS)
1313 # -------------------
1314 # Specify the list of programs exercised by the test suite. Their
1315 # versions are logged, and in the case of embedded test suite, they
1316 # must correspond to the version of the package. PATH should be
1317 # already preset so the proper executable will be selected.
1318 m4_define([AT_TESTED],
1319 [m4_append_uniq_w([AT_tested], [$1])])
1322 # AT_COPYRIGHT(TEXT)
1323 # ------------------
1324 # Emit TEXT, a copyright notice, in the top of the test suite and in
1325 # --version output. Macros in TEXT are evaluated once.
1326 m4_define([AT_COPYRIGHT],
1327 [AS_COPYRIGHT([$1])[]dnl
1328 m4_divert_text([VERSION_NOTICES],
1330 $1])])# AT_COPYRIGHT
1333 # AT_SETUP(DESCRIPTION)
1334 # ---------------------
1335 # Start a group of related tests, all to be executed in the same subshell.
1336 # The group is testing what DESCRIPTION says.
1337 m4_define([AT_SETUP],
1338 [m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
1339 m4_define([AT_capture_files], [])
1340 m4_define([AT_line], AT_LINE)
1341 m4_define([AT_xfail], [at_xfail=no])
1342 m4_define([AT_description], m4_expand([$1]))
1343 m4_define([AT_ordinal], m4_incr(AT_ordinal))
1344 m4_append([AT_groups_all], [ ]m4_defn([AT_ordinal]))
1345 m4_divert_push([TEST_GROUPS])dnl
1346 [#AT_START_]AT_ordinal
1347 @%:@ AT_ordinal. m4_defn([AT_line]): m4_defn([AT_description])
1348 at_setup_line='m4_defn([AT_line])'
1349 m4_if(AT_banner_ordinal, [0], [], [at_func_banner AT_banner_ordinal
1351 at_desc="AS_ESCAPE(m4_dquote(m4_defn([AT_description])))"
1352 $at_quiet AS_ECHO_N([m4_format(["%3d: $at_desc%*s"], AT_ordinal,
1353 m4_max(0, m4_eval(47 - m4_qlen(m4_defn([AT_description])))), [])])
1354 m4_divert_push([TEST_SCRIPT])dnl
1358 # AT_XFAIL_IF(SHELL-EXPRESSION)
1359 # -----------------------------
1360 # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
1361 # true (exitcode = 0).
1362 m4_define([AT_XFAIL_IF],
1364 dnl Try to limit the amount of conditionals that we emit.
1368 [:], [m4_define([AT_xfail], [at_xfail=yes])],
1369 [true], [m4_define([AT_xfail], [at_xfail=yes])],
1370 [m4_append([AT_xfail], [
1371 $1 && at_xfail=yes])])])
1374 # AT_KEYWORDS(KEYWORDS)
1375 # ---------------------
1376 # Declare a list of keywords associated to the current test group.
1377 # The list is stored in lower case, since the -k option is case-insensitive.
1378 m4_define([AT_KEYWORDS],
1379 [m4_append_uniq_w([AT_keywords], m4_tolower([[$1]]))])
1382 # AT_CAPTURE_FILE(FILE)
1383 # ---------------------
1384 # If the current test group does not behave as expected, save the contents of
1385 # FILE in the test suite log.
1386 m4_define([AT_CAPTURE_FILE],
1387 [m4_append_uniq([AT_capture_files], ["$1"], [ \
1393 # Complete a group of related tests.
1394 m4_define([AT_CLEANUP],
1395 [m4_append([AT_help_all],
1396 m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);dnl
1397 m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
1399 m4_divert_pop([TEST_SCRIPT])dnl Back to TEST_GROUPS
1401 echo "# -*- compilation -*-" >> "$at_group_log"
1403 AS_ECHO(["AT_ordinal. m4_defn([AT_line]): testing $1..."])
1405 m4_undivert([TEST_SCRIPT])dnl Insert the code here
1407 $at_times_p && times >"$at_times_file"
1408 ) AS_MESSAGE_LOG_FD>&1 2>&1 | eval $at_tee_pipe
1409 at_status=`cat "$at_status_file"`
1410 [#AT_STOP_]AT_ordinal
1411 m4_divert_pop([TEST_GROUPS])dnl Back to KILL.
1417 # Start a category of related test groups. If multiple groups are executed,
1418 # output TEXT as a banner without any shell expansion, prior to any test
1419 # from the category. If TEXT is empty, no banner is printed.
1420 m4_define([AT_BANNER],
1421 [m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
1422 m4_divert_text([BANNERS],
1423 [@%:@ Banner AT_banner_ordinal. AT_LINE
1424 @%:@ Category starts at test group m4_incr(AT_ordinal).
1425 at_banner_text_[]AT_banner_ordinal="AS_ESCAPE([$1])"])dnl
1429 # AT_DATA(FILE, CONTENTS)
1430 # -----------------------
1431 # Initialize an input data FILE with given CONTENTS, which should end with
1433 # This macro is not robust to active symbols in CONTENTS *on purpose*.
1434 # If you don't want CONTENTS to be evaluated, quote it twice.
1435 m4_define([AT_DATA],
1441 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1442 # [RUN-IF-FAIL], [RUN-IF-PASS])
1443 # ------------------------------------------------
1444 # Execute a test by performing given shell COMMANDS. These commands
1445 # should normally exit with STATUS, while producing expected STDOUT and
1446 # STDERR contents. Shell metacharacters in STDOUT and STDERR are
1447 # _not_ processed by the shell, but are treated as string literals.
1449 # STATUS, STDOUT, and STDERR are not checked if equal to `ignore'.
1451 # If STDOUT is `expout', then stdout is compared to the content of the file
1452 # `expout'. Likewise for STDERR and `experr'.
1454 # If STDOUT is `stdout', then the stdout is left in the file `stdout',
1455 # likewise for STDERR and `stderr'. Don't do this:
1457 # AT_CHECK([command >out])
1458 # # Some checks on `out'
1462 # AT_CHECK([command], [], [stdout])
1463 # # Some checks on `stdout'
1465 # You might wonder why you can't just use `ignore', then directly use stdout
1466 # and stderr left by the test suite:
1468 # AT_CHECK([command], [], [ignore])
1469 # AT_CHECK([check stdout])
1471 # If the test suite always captured data in the file `stdout', then the
1472 # second command would be trying to read and write from the same file, with
1473 # undefined behavior. Therefore, the test suite actually captures data in
1474 # an internal file of a different name, and only creates `stdout' when
1475 # explicitly requested.
1477 # Any line of stderr starting with leading blanks and a `+' are filtered
1478 # out, since most shells when tracing include subshell traces in stderr.
1479 # This may cause spurious failures when the test suite is run with `-x'.
1481 m4_define([AT_CHECK],
1482 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6],1)])
1484 # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1485 # [RUN-IF-FAIL], [RUN-IF-PASS])
1486 # ---------------------------------------------------------
1487 # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
1488 # and STDERR arguments before running the comparison.
1489 m4_define([AT_CHECK_NOESCAPE],
1490 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6])])
1493 # _AT_DECIDE_TRACEABLE(COMMANDS)
1494 # ------------------------------
1495 # Worker for for _AT_CHECK that expands to shell code. If COMMANDS are safe to
1496 # trace with `set -x', the shell code will evaluate to true. Otherwise,
1497 # the shell code will print a message stating an aspect of COMMANDS that makes
1498 # tracing them unsafe, and evaluate to false.
1500 # Tracing COMMANDS is not safe if they contain a command that spans multiple
1501 # lines. When the test suite user passes `-x' or `--trace', the test suite
1502 # precedes every command with a `set -x'. Since most tests expect a specific
1503 # stderr, if only to confirm that it is empty, the test suite filters ^+ from
1504 # the captured stderr before comparing with the expected stderr. If a command
1505 # spans multiple lines, so will its trace, but a `+' only prefixes the first
1506 # line of that trace:
1517 # In a subset of cases, one could filter such extended shell traces from
1518 # stderr. Since test commands spanning several lines are rare, I chose
1519 # instead to simply not trace COMMANDS that could yield multiple trace lines.
1520 # Distinguishing such COMMANDS became the task at hand.
1522 # These features may cause a shell command to span multiple lines:
1524 # (a) A quoted literal newline.
1528 # M4 is a hostile language for the job of parsing COMMANDS to determine whether
1529 # each literal newline is quoted, so we simply disable tracing for all COMMANDS
1530 # that bear literal newlines.
1532 # (b) A command substitution not subject to word splitting.
1534 # var=$(printf 'foo\nbar')
1536 # echo "`printf 'foo\\nbar`"
1537 # One cannot know in general the number of lines a command substitution will
1538 # yield without executing the substituted command. As such, we disable tracing
1539 # for all COMMANDS containing these constructs.
1541 # (c) A parameter expansion not subject to word splitting.
1546 # Parameter expansions appear in COMMANDS with much greater frequency than do
1547 # newlines and command substitutions, so disabling tracing for all such
1548 # COMMANDS would much more substantially devalue `testsuite -x'. To determine
1549 # which parameter expansions yield multiple lines, we escape all ``', `"',
1550 # and `\' in a copy of COMMANDS and expand that string within double quotes
1551 # at runtime. If the result of that expansion contains multiple lines, the
1552 # test suite disables tracing for the command in question.
1554 # This method leads the test suite to expand some parameters that the shell
1555 # itself will never expand due to single-quotes or backslash escapes. This is
1556 # not a problem for `$foo' expansions, which will simply yield the empty string
1557 # or some unrelated value. A `${...}' expansion could actually form invalid
1558 # shell code, however; consider `${=foo}'. Therefore, we disable tracing for
1559 # all COMMANDS containing `${...}'. This affects few COMMANDS.
1561 # This macro falls in a very hot path; the Autoconf test suite expands it 1640
1562 # times as of this writing. To give a sense of the impact of the heuristics I
1563 # just described, the test suite preemptively disables tracing for 31 of those,
1564 # and 268 contain parameter expansions that require runtime evaluation. The
1565 # balance are always safe to trace.
1567 # _AT_CHECK expands COMMANDS, but the Autoconf language does not provide a way
1568 # to safely expand arbitrary COMMANDS in an argument list, so the below tests
1569 # examine COMMANDS unexpanded.
1570 m4_define([_AT_DECIDE_TRACEABLE],
1573 dnl Examine COMMANDS for a reason to never trace COMMANDS.
1574 [m4_pushdef([at_reason],
1575 m4_cond([m4_eval(m4_index([$1], [`]) >= 0)], [1],
1576 [[a `...` command substitution]],
1577 [m4_eval(m4_index([$1], [$(]) >= 0)], [1],
1578 [[a $(...) command substitution]],
1579 [m4_eval(m4_index([$1], [${]) >= 0)], [1],
1580 [[a ${...} parameter expansion]],
1581 [m4_eval(m4_index([$1], m4_newline) >= 0)], [1],
1582 [[an embedded newline]],
1586 m4_ifval(m4_defn([at_reason]),
1587 [{ echo 'Not enabling shell tracing (command contains ]m4_defn([at_reason])[)'
1589 [m4_if(m4_index([$1], [$]), [-1],
1590 dnl We know at build time that tracing COMMANDS is always safe.
1591 [test -n "$at_traceon"],
1592 dnl COMMANDS may contain parameter expansions; expand them at runtime.
1593 [test -n "$at_traceon" \
1594 && at_func_check_newline "AS_ESCAPE([$1], [`\"])"])])[]dnl
1595 m4_popdef([at_reason])])
1598 # AT_DIFF_STDERR/AT_DIFF_STDOUT
1599 # -----------------------------
1600 # These are subroutines of AT_CHECK. Using indirect dispatch is a tad
1601 # faster than using m4_case, and these are called very frequently.
1602 m4_define([AT_DIFF_STDERR(stderr)],
1603 [echo stderr:; tee stderr <"$at_stderr"])
1604 m4_define([AT_DIFF_STDERR(ignore)],
1605 [echo stderr:; cat "$at_stderr"])
1606 m4_define([AT_DIFF_STDERR(experr)],
1607 [$at_diff experr "$at_stderr" || at_failed=:])
1608 m4_define([AT_DIFF_STDERR()],
1609 [at_func_diff_devnull "$at_stderr" || at_failed=:])
1611 m4_define([AT_DIFF_STDOUT(stdout)],
1612 [echo stdout:; tee stdout <"$at_stdout"])
1613 m4_define([AT_DIFF_STDOUT(ignore)],
1614 [echo stdout:; cat "$at_stdout"])
1615 m4_define([AT_DIFF_STDOUT(expout)],
1616 [$at_diff expout "$at_stdout" || at_failed=:])
1617 m4_define([AT_DIFF_STDOUT()],
1618 [at_func_diff_devnull "$at_stdout" || at_failed=:])
1620 # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1621 # [RUN-IF-FAIL], [RUN-IF-PASS], SHELL_ESCAPE_IO)
1622 # ---------------------------------------------------------
1623 # Worker for AT_CHECK & AT_CHECK_NOESCAPE. The final SHELL-ESCAPE-IO
1624 # argument determines whether the STDOUT & STDERR arguments will be escaped or
1628 # Implementation Details
1629 # ----------------------
1630 # Ideally, we would like to run
1632 # ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
1634 # but we must group COMMANDS as it is not limited to a single command, and
1635 # then the shells will save the traces in at-stderr. So we have to filter
1636 # them out when checking stderr, and we must send them into the test suite's
1637 # stderr to honor -x properly. Since only the first line of the trace of a
1638 # multiline command starts with a `+', and I know of no straightforward way to
1639 # filter out the unadorned trace lines, we disable shell tracing entirely for
1640 # commands that could span multiple lines.
1642 # Limiting COMMANDS to a single command is not good either, since them
1643 # the user herself would use {} or (), and then we face the same problem.
1645 # But then, there is no point in running
1647 # ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
1649 # instead of the simpler
1651 # ( $at_traceon; $1 ) >at-stdout 2>at-stder1
1653 m4_define([_AT_CHECK],
1655 AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([$1])"])
1656 echo AT_LINE >"$at_check_line_file"
1658 if _AT_DECIDE_TRACEABLE([$1]); then
1659 ( $at_traceon; $1 ) >"$at_stdout" 2>"$at_stder1"
1660 at_func_filter_trace $?
1662 ( :; $1 ) >"$at_stdout" 2>"$at_stderr"
1666 m4_ifdef([AT_DIFF_STDERR($4)], [m4_indir([AT_DIFF_STDERR($4)])],
1667 [echo >>"$at_stderr"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$4])],[$4])"]) | \
1668 $at_diff - "$at_stderr" || at_failed=:])
1669 m4_ifdef([AT_DIFF_STDOUT($3)], [m4_indir([AT_DIFF_STDOUT($3)])],
1670 [echo >>"$at_stdout"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$3])],[$3])"]) | \
1671 $at_diff - "$at_stdout" || at_failed=:])
1672 m4_if([$2], [ignore], [at_func_check_skip],
1673 [at_func_check_status m4_default([$2], [0])]) dnl
1674 $at_status "$at_srcdir/AT_LINE"
1675 AS_IF($at_failed, [$5], [$6])
1676 $at_failed && at_func_log_failure AT_capture_files