1 # This file is part of Autoconf. -*- Autoconf -*-
2 # M4 macros used in building test suites.
3 m4_define([_AT_COPYRIGHT_YEARS], [
4 Copyright (C) 2000-2017, 2020-2024 Free Software Foundation, Inc.
7 # This file is part of Autoconf. This program is free
8 # software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the
10 # Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # Under Section 7 of GPL version 3, you are granted additional
19 # permissions described in the Autoconf Configure Script Exception,
20 # version 3.0, as published by the Free Software Foundation.
22 # You should have received a copy of the GNU General Public License
23 # and a copy of the Autoconf Configure Script Exception along with
24 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
25 # respectively. If not, see <https://www.gnu.org/licenses/>.
28 # _m4_divert(DIVERSION-NAME)
29 # --------------------------
30 # Convert a diversion name into its number. Otherwise, return
31 # DIVERSION-NAME which is supposed to be an actual diversion number.
32 # Of course it would be nicer to use m4_case here, instead of zillions
33 # of little macros, but it then takes twice longer to run 'autoconf'!
50 # Overall initialization, value of $at_groups_all.
52 # Setup defaults required for option processing.
54 # Option processing. After AT_INIT, user options can be entered here as
55 # cases of a case statement.
57 # Finish up the option processing.
60 # Start printing the help message.
62 # Modes help text. Additional modes can be appended as self-contained
63 # cat'd here-docs as generated by AS_HELP_STRING.
65 # Tuning help text. This is for Autotest-provided text.
67 # Additional tuning options' help text can be appended here as
68 # self-contained cat'd here-docs as generated by AS_HELP_STRING.
70 # User help can be appended to this as self-contained cat'd here-docs.
72 # Finish up the help texts.
75 # Head of the handling of --version.
77 # Copyright notices for --version.
79 # Tail of the handling of --version.
82 # Output shell initialization for the associative array of banner text.
84 # Like DEFAULTS but run after argument processing for purposes of
85 # optimization. Do anything else that needs to be done to prepare for
86 # tests. Sets up verbose and log file descriptors. Sets and logs PATH.
88 # Declares functions shared among the tests. Perform any user
89 # initialization to be shared among all tests.
91 # The core of the test suite.
94 # The collector for code for each test, the "normal" diversion, but
95 # undiverted into other locations before final output.
98 # Contents of each test group. The tests deliberately occur after the
99 # end of the shell script, so that the shell need not spend time parsing
100 # commands it will not execute.
102 m4_define([_m4_divert(DEFAULTS)], 100)
103 m4_define([_m4_divert(PARSE_ARGS_BEGIN)], 200)
104 m4_define([_m4_divert(PARSE_ARGS)], 201)
105 m4_define([_m4_divert(PARSE_ARGS_END)], 202)
106 m4_define([_m4_divert(HELP)], 300)
107 m4_define([_m4_divert(HELP_MODES)], 301)
108 m4_define([_m4_divert(HELP_TUNING_BEGIN)], 302)
109 m4_define([_m4_divert(HELP_TUNING)], 303)
110 m4_define([_m4_divert(HELP_OTHER)], 304)
111 m4_define([_m4_divert(HELP_END)], 305)
112 m4_define([_m4_divert(VERSION)], 350)
113 m4_define([_m4_divert(VERSION_NOTICES)], 351)
114 m4_define([_m4_divert(VERSION_END)], 352)
115 m4_define([_m4_divert(BANNERS)], 400)
116 m4_define([_m4_divert(TESTS_BEGIN)], 401)
117 m4_define([_m4_divert(PREPARE_TESTS)], 402)
118 m4_define([_m4_divert(TESTS)], 403)
119 m4_define([_m4_divert(TEST_SCRIPT)], 450)
120 m4_define([_m4_divert(TEST_GROUPS)], 500)
125 # Return the current file sans directory, a colon, and the current
126 # line. Be sure to return a _quoted_ file name, so if, for instance,
127 # the user is lunatic enough to have a file named 'dnl' (and I, for
128 # one, love to be brainless and stubborn sometimes), then we return a
131 # Gee, we can't use simply
133 # m4_bpatsubst(__file__, [^.*/\(.*\)], [[\1]])
135 # since then, since 'dnl' doesn't match the pattern, it is returned
136 # with once quotation level less, so you lose! And since GNU M4
137 # is one of the biggest junk in the whole universe wrt regexp, don't
138 # even think about using '?' or '\?'. Bah, '*' will do.
139 # Pleeeeeeeease, Gary, provide us with dirname and ERE!
141 # M4 recompiles the regular expression for every m4_bpatsubst, but __file__
142 # rarely changes. Be fast - only compute the dirname when necessary; for
143 # autoconf alone, this shaves off several seconds in building testsuite.
144 m4_define([_AT_LINE_file])
145 m4_define([_AT_LINE_base])
147 [m4_if(m4_defn([_AT_LINE_file]), __file__, [],
148 [m4_do([m4_define([_AT_LINE_file], __file__)],
149 [m4_define([_AT_LINE_base],
150 m4_bregexp(/__file__, [/\([^/]*\)$], [[\1]]))])])dnl
151 m4_defn([_AT_LINE_base]):__line__])
155 # Same as AT_LINE, but already escaped for the shell.
156 m4_define([_AT_LINE_ESCAPED], ["AS_ESCAPE(m4_dquote(AT_LINE))"])
159 # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR)
160 # ------------------------------------------
161 # Normalize SHELL-VAR so that its value has the same number of digits as
162 # all the other test group numbers.
163 m4_define([_AT_NORMALIZE_TEST_GROUP_NUMBER],
167 '"$at_format"'*) break;;
173 # _AT_DEFINE_INIT(NAME, [DEFINITION])
174 # -----------------------------------
175 # Define macro NAME to die if invoked prior to AT_INIT, and to DEFINITION
177 m4_define([_AT_DEFINE_INIT],
178 [m4_define($@)m4_pushdef([$1], [m4_fatal([$1: missing AT_INIT detected])])dnl
179 m4_append([_AT_DEFINE_INIT_LIST], [[$1]], [,])])
181 # _AT_DEFINE_SETUP(NAME, [DEFINITION])
182 # ------------------------------------
183 # Define macro NAME to die if invoked outside AT_SETUP/AT_CLEANUP, and
184 # to DEFINITION otherwise.
185 m4_define([_AT_DEFINE_SETUP],
186 [m4_define([$1], [m4_ifndef([AT_ingroup],
187 [m4_fatal([$1: missing AT_SETUP detected])])$2])])
191 # File descriptor open on the log file. This needs to be defined
192 # unconditionally, so that AT_TESTS_PREPARE code can use it. Usage
193 # prior to the point where the log file is opened will crash the
195 m4_define([AS_MESSAGE_LOG_FD], [5])
197 # AT_JOB_FIFO_{IN,OUT}_FD
199 # Used by the parallel test driver.
200 # The parent needs two fds to the same fifo, otherwise, there is a race
201 # where the parent can read the fifo before a child opens it for writing
202 _AT_DEFINE_INIT([AT_JOB_FIFO_IN_FD], [6])
203 _AT_DEFINE_INIT([AT_JOB_FIFO_OUT_FD], [7])
205 # AT_INIT([TESTSUITE-NAME])
206 # -------------------------
209 [m4_pushdef([AT_INIT], [m4_fatal([$0: invoked multiple times])])]
210 [m4_pattern_forbid([^_?AT_])]
211 [m4_pattern_allow([^_ATEOF$])]
212 [m4_ifndef([AT_PACKAGE_BUGREPORT], [m4_fatal(
213 [$1: AT_PACKAGE_BUGREPORT is missing, consider writing package.m4])])]
214 [m4_define([AT_TESTSUITE_NAME],
215 m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1],
216 [m4_expand([: $1])]))]
217 [m4_define([AT_ordinal], 0)]
218 [m4_define([AT_banner_ordinal], 0)]
219 [m4_define([AT_help_all], [])]
220 [m4_map_args([_m4_popdef], _AT_DEFINE_INIT_LIST)]
221 [m4_wrap([_AT_FINISH])]
223 dnl We don't use m4sh's BODY diversion, but AS_INIT sticks a banner there.
224 dnl This trick removes that banner, since it adds nothing to autotest.
225 [m4_cleardivert([BODY])]dnl
227 [m4_divert_push([DEFAULTS])]dnl
228 [AT_COPYRIGHT(m4_defn([_AT_COPYRIGHT_YEARS]), [
229 m4_copyright_condense])]
231 [This test suite is free software; the Free Software Foundation gives
232 unlimited permission to copy, distribute and modify it.], [m4_echo])]
235 SHELL=${CONFIG_SHELL-/bin/sh}
240 m4_divert_push([BANNERS])dnl
242 # Should we print banners? Yes if more than one test is run.
243 case $at_groups in #(
245 at_print_banners=: ;; #(
246 * ) at_print_banners=false ;;
248 # Text for banner N, set to a single space once printed.
249 m4_divert_pop([BANNERS])dnl back to DEFAULTS
250 m4_divert_push([PREPARE_TESTS])dnl
252 m4_text_box([Autotest shell functions.])
254 AS_FUNCTION_DESCRIBE([at_fn_banner], [NUMBER],
255 [Output banner NUMBER, provided the testsuite is running multiple groups
256 and this particular banner has not yet been printed.])
259 $at_print_banners || return 0
260 eval at_banner_text=\$at_banner_text_$[1]
261 test "x$at_banner_text" = "x " && return 0
262 eval "at_banner_text_$[1]=\" \""
263 if test -z "$at_banner_text"; then
266 AS_ECHO(["$as_nl$at_banner_text$as_nl"])
270 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_notrace], [REASON LINE],
271 [Perform AT_CHECK preparations for the command at LINE for an
272 untraceable command; REASON is the reason for disabling tracing.])
273 at_fn_check_prepare_notrace ()
275 $at_trace_echo "Not enabling shell tracing (command contains $[1])"
276 AS_ECHO(["$[2]"]) >"$at_check_line_file"
277 at_check_trace=: at_check_filter=:
278 : >"$at_stdout"; : >"$at_stderr"
281 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_trace], [LINE],
282 [Perform AT_CHECK preparations for the command at LINE for a traceable
284 at_fn_check_prepare_trace ()
286 AS_ECHO(["$[1]"]) >"$at_check_line_file"
287 at_check_trace=$at_traceon at_check_filter=$at_check_filter_trace
288 : >"$at_stdout"; : >"$at_stderr"
291 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_dynamic], [COMMAND LINE],
292 [Decide if COMMAND at LINE is traceable at runtime, and call the
293 appropriate preparation function.])
294 at_fn_check_prepare_dynamic ()
298 at_fn_check_prepare_notrace 'an embedded newline' "$[2]" ;;
300 at_fn_check_prepare_trace "$[2]" ;;
304 AS_FUNCTION_DESCRIBE([at_fn_filter_trace], [],
305 [Remove the lines in the file "$at_stderr" generated by "set -x" and print
307 at_fn_filter_trace ()
309 mv "$at_stderr" "$at_stder1"
310 grep '^ *+' "$at_stder1" >&2
311 grep -v '^ *+' "$at_stder1" >"$at_stderr"
314 AS_FUNCTION_DESCRIBE([at_fn_log_failure], [FILE-LIST],
315 [Copy the files in the list on stdout with a "> " prefix, and exit the shell
316 with a failure exit code.])
320 do AS_ECHO(["$file:"]); sed 's/^/> /' "$file"; done
321 echo 1 > "$at_status_file"
325 AS_FUNCTION_DESCRIBE([at_fn_check_skip], [EXIT-CODE LINE],
326 [Check whether EXIT-CODE is a special exit code (77 or 99), and if so exit
327 the test group subshell with that same exit code. Use LINE in any report
328 about test failure.])
332 99) echo 99 > "$at_status_file"; at_failed=:
333 AS_ECHO(["$[2]: hard failure"]); exit 99;;
334 77) echo 77 > "$at_status_file"; exit 77;;
338 AS_FUNCTION_DESCRIBE([at_fn_check_status], [EXPECTED EXIT-CODE LINE],
339 [Check whether EXIT-CODE is the EXPECTED exit code, and if so do nothing.
340 Otherwise, if it is 77 or 99, exit the test group subshell with that same
341 exit code; if it is anything else print an error message referring to LINE,
343 at_fn_check_status ()
345 dnl This order ensures that we don't 'skip' if we are precisely checking
346 dnl $? = 77 or $? = 99.
349 77) echo 77 > "$at_status_file"; exit 77;;
350 99) echo 99 > "$at_status_file"; at_failed=:
351 AS_ECHO(["$[3]: hard failure"]); exit 99;;
352 *) AS_ECHO(["$[3]: exit code was $[2], expected $[1]"])
357 AS_FUNCTION_DESCRIBE([at_fn_diff_devnull], [FILE],
358 [Emit a diff between /dev/null and FILE. Uses "test -s" to avoid useless
360 at_fn_diff_devnull ()
362 test -s "$[1]" || return 0
363 $at_diff "$at_devnull" "$[1]"
366 AS_FUNCTION_DESCRIBE([at_fn_test], [NUMBER],
367 [Parse out test NUMBER from the tail of this file.])
370 eval at_sed=\$at_sed$[1]
371 sed "$at_sed" "$at_myself" > "$at_test_source"
374 AS_FUNCTION_DESCRIBE([at_fn_create_debugging_script], [],
375 [Create the debugging script $at_group_dir/run which will reproduce the
376 current test group.])
377 at_fn_create_debugging_script ()
381 AS_ECHO(["cd '$at_dir'"]) &&
382 AS_ECHO(['case $[#] in']) &&
383 AS_ECHO([" 0) exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
384 [$at_debug_args $at_group ;;"]) &&
385 AS_ECHO([" *) exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
386 [$at_debug_args $at_group \"\$[@]\" ;;"]) &&
389 } >"$at_group_dir/run" &&
390 chmod +x "$at_group_dir/run"
393 m4_text_box([End of autotest shell functions.])
394 m4_divert_pop([PREPARE_TESTS])dnl back to DEFAULTS
396 # Not all shells have the 'times' builtin; the subshell is needed to make
397 # sure we discard the 'times: not found' message from the shell.
399 (times) >/dev/null 2>&1 && at_times_p=:
401 # CLI Arguments to pass to the debugging scripts.
405 # Shall we be verbose? ':' means no, empty means yes.
408 # Running several jobs in parallel, 0 means as many as test groups.
412 at_check_filter_trace=:
414 # Shall we keep the debug scripts? Must be ':' when the suite is
415 # run by a debug script, so that the script doesn't remove itself.
417 # Display help message?
419 # Display the version message?
427 # Whether to rerun failed tests.
429 # Whether a write failure occurred
432 # The directory we run the suite in. Default to . if no -C option.
434 # An absolute reference to this testsuite script.
435 dnl m4-double quote, to preserve []
437 [\\/]* | ?:[\\/]* ) at_myself=$as_myself ;;
438 * ) at_myself=$at_dir/$as_myself ;;
440 # Whether -C is in effect.
442 m4_divert_pop([DEFAULTS])dnl
443 m4_define([_AT_FINISH],
444 [m4_ifdef([AT_ingroup], [m4_fatal([missing AT_CLEANUP detected])])dnl
445 m4_divert_text([DEFAULTS],
447 # Whether to enable colored test results.
448 at_color=m4_ifdef([AT_color], [AT_color], [no])
449 # As many question marks as there are digits in the last test group number.
450 # Used to normalize the test group numbers so that 'ls' lists them in
452 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
453 # Description of all the test groups.
454 at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"
455 # List of the all the test groups.
456 at_groups_all=`AS_ECHO(["$at_help_all"]) | sed 's/;.*//'`
458 AS_FUNCTION_DESCRIBE([at_fn_validate_ranges], [NAME...],
459 [Validate and normalize the test group number contained in each
460 variable NAME. Leading zeroes are treated as decimal.])
461 at_fn_validate_ranges ()
465 eval at_value=\$$at_grp
466 if test $at_value -lt 1 || test $at_value -gt AT_ordinal; then
467 AS_ECHO(["invalid test group: $at_value"]) >&2
471 0*) # We want to treat leading 0 as decimal, like expr and test, but
472 # AS_VAR_ARITH treats it as octal if it uses $(( )).
473 # With XSI shells, ${at_value#${at_value%%[1-9]*}} avoids the
474 # expr fork, but it is not worth the effort to determine if the
475 # shell supports XSI when the user can just avoid leading 0.
476 eval $at_grp='`expr $at_value + 0`' ;;
480 m4_divert_push([PARSE_ARGS])dnl
485 # If the previous option needs an argument, assign it.
486 if test -n "$at_prev"; then
487 at_option=$at_prev=$at_option
492 *=?*) at_optarg=`expr "X$at_option" : '[[^=]]*=\(.*\)'` ;;
518 no | never | none) at_color=never ;;
519 auto | tty | if-tty) at_color=auto ;;
520 always | yes | force) at_color=always ;;
521 *) at_optname=`echo " $at_option" | sed 's/^ //; s/=.*//'`
522 AS_ERROR([unrecognized argument to $at_optname: $at_optarg]) ;;
536 at_verbose=; at_quiet=:
542 at_check_filter_trace=at_fn_filter_trace
545 [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
546 at_fn_validate_ranges at_option
547 AS_VAR_APPEND([at_groups], ["$at_option$as_nl"])
551 [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
552 at_range_start=`echo $at_option |tr -d X-`
553 at_fn_validate_ranges at_range_start
554 at_range=`AS_ECHO(["$at_groups_all"]) | \
555 sed -ne '/^'$at_range_start'$/,$p'`
556 AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
559 [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
560 at_range_end=`echo $at_option |tr -d X-`
561 at_fn_validate_ranges at_range_end
562 at_range=`AS_ECHO(["$at_groups_all"]) | \
563 sed -ne '1,/^'$at_range_end'$/p'`
564 AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
567 [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
568 [[0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9]] | \
569 [[0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
570 [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
571 [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
572 [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
573 at_range_start=`expr $at_option : '\(.*\)-'`
574 at_range_end=`expr $at_option : '.*-\(.*\)'`
575 if test $at_range_start -gt $at_range_end; then
577 at_range_end=$at_range_start
578 at_range_start=$at_tmp
580 at_fn_validate_ranges at_range_start at_range_end
581 at_range=`AS_ECHO(["$at_groups_all"]) | \
582 sed -ne '/^'$at_range_start'$/,/^'$at_range_end'$/p'`
583 AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
586 # Directory selection.
593 if test x- = "x$at_dir" ; then
598 # Parallel execution.
602 --jobs=* | -j[[0-9]]* )
603 if test -n "$at_optarg"; then
606 at_jobs=`expr X$at_option : 'X-j\(.*\)'`
608 case $at_jobs in *[[!0-9]]*)
609 at_optname=`echo " $at_option" | sed 's/^ //; s/[[0-9=]].*//'`
610 AS_ERROR([non-numeric argument to $at_optname: $at_jobs]) ;;
619 at_groups_selected=$at_help_all
631 at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
634 # It is on purpose that we match the test group titles too.
635 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
636 grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
638 # Smash the keywords.
639 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//'`
640 AS_VAR_APPEND([at_groups], ["$at_groups_selected$as_nl"])
645 m4_divert_pop([PARSE_ARGS])dnl
646 dnl Process *=* last to allow for user specified --option=* type arguments.
647 m4_divert_push([PARSE_ARGS_END])dnl
650 at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
651 # Reject names that are not valid shell variable names.
653 '' | [[0-9]]* | *[[!_$as_cr_alnum]]* )
654 AS_ERROR([invalid variable name: '$at_envvar']) ;;
656 at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
657 # Export now, but save eval for later and for debug scripts.
659 AS_VAR_APPEND([at_debug_args], [" $at_envvar='$at_value'"])
662 *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
663 AS_ECHO(["Try '$[0] --help' for more information."]) >&2
669 # Verify our last option didn't require an argument
670 AS_IF([test -n "$at_prev"], [AS_ERROR(['$at_prev' requires an argument])])
672 # The file containing the suite.
673 at_suite_log=$at_dir/$as_me.log
675 # Selected test groups.
676 if test -z "$at_groups$at_recheck"; then
677 at_groups=$at_groups_all
679 if test -n "$at_recheck" && test -r "$at_suite_log"; then
680 at_oldfails=`sed -n ['
681 /^Failed tests:$/,/^Skipped tests:$/{
682 s/^[ ]*\([1-9][0-9]*\):.*/\1/p
684 /^Unexpected passes:$/,/^## Detailed failed tests/{
685 s/^[ ]*\([1-9][0-9]*\):.*/\1/p
687 /^## Detailed failed tests/q
689 AS_VAR_APPEND([at_groups], ["$at_oldfails$as_nl"])
691 # Sort the tests, removing duplicates.
692 at_groups=`AS_ECHO(["$at_groups"]) | sort -nu | sed '/^$/d'`
695 if test x"$at_color" = xalways \
696 || { test x"$at_color" = xauto && test -t 1; }; then
697 at_red=`printf '\033@<:@0;31m'`
698 at_grn=`printf '\033@<:@0;32m'`
699 at_lgn=`printf '\033@<:@1;32m'`
700 at_blu=`printf '\033@<:@1;34m'`
701 at_std=`printf '\033@<:@m'`
703 at_red= at_grn= at_lgn= at_blu= at_std=
705 m4_divert_pop([PARSE_ARGS_END])dnl
706 m4_divert_push([HELP])dnl
710 cat <<_ATEOF || at_write_fail=1
711 Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
713 Run all the tests, or the selected TESTS, given by numeric ranges, and
714 save a detailed log file. Upon failure, create debugging scripts.
716 Do not change environment variables directly. Instead, set them via
717 command line arguments. Set 'AUTOTEST_PATH' to select the executables
718 to exercise. Each relative directory is expanded as build and source
719 directories relative to the top level of this distribution.
720 E.g., from within the build directory /tmp/foo-1.0, invoking this:
722 $ $[0] AUTOTEST_PATH=bin
724 is equivalent to the following, assuming the source directory is /src/foo-1.0:
726 PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH $[0]
728 m4_divert_pop([HELP])dnl
729 m4_divert_push([HELP_MODES])dnl
730 cat <<_ATEOF || at_write_fail=1
733 -h, --help print the help message, then exit
734 -V, --version print version number, then exit
735 -c, --clean remove all the files this test suite might create and exit
736 -l, --list describes all the tests, or the selected TESTS
738 m4_divert_pop([HELP_MODES])dnl
739 m4_wrap([m4_divert_push([HELP_TUNING_BEGIN])dnl
740 cat <<_ATEOF || at_write_fail=1
742 dnl extra quoting prevents emacs whitespace mode from putting tabs in output
745 [ change to directory DIR before starting]
746 --color[[=never|auto|always]]
747 [ ]m4_ifdef([AT_color],
748 [disable colored test results, or enable even without terminal],
749 [enable colored test results on terminal, or always])
751 [ Allow N jobs at once; infinite jobs with no arg (default 1)]
752 -k, --keywords=KEYWORDS
753 [ select the tests matching all the comma-separated KEYWORDS]
754 [ multiple '-k' accumulate; prefixed '!' negates a KEYWORD]
755 --recheck select all tests that failed or passed unexpectedly last time
756 -e, --errexit abort as soon as a test fails; implies --debug
757 -v, --verbose force more detailed output
758 [ default for debugging scripts]
759 -d, --debug inhibit clean up and top-level logging
760 [ default for debugging scripts]
761 -x, --trace enable tests shell tracing
763 m4_divert_pop([HELP_TUNING_BEGIN])])dnl
764 m4_divert_push([HELP_END])dnl
765 cat <<_ATEOF || at_write_fail=1
767 Report bugs to <AT_PACKAGE_BUGREPORT>.dnl
768 m4_ifdef([AT_PACKAGE_NAME],
769 [m4_ifset([AT_PACKAGE_URL], [
770 m4_defn([AT_PACKAGE_NAME]) home page: <AT_PACKAGE_URL>.])dnl
771 m4_if(m4_index(m4_defn([AT_PACKAGE_NAME]), [GNU ]), [0], [
772 General help using GNU software: <https://www.gnu.org/gethelp/>.])])
779 cat <<_ATEOF || at_write_fail=1
780 AT_TESTSUITE_NAME test groups:
782 NUM: FILE-NAME:LINE TEST-GROUP-NAME
786 # Pass an empty line as separator between selected groups and help.
787 AS_ECHO(["$at_groups$as_nl$as_nl$at_help_all"]) |
788 awk 'NF == 1 && FS != ";" {
794 if (selected[[$ 1]]) {
795 printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
801 n = split ($ 4, a, " ")
802 for (i = 1; i <= n; i++) {
803 l = length (a[[i]]) + 1
804 if (i > 1 && len + l > lmax) {
806 line = indent " " a[[i]]
809 line = line " " a[[i]]
817 }' || at_write_fail=1
820 m4_divert_pop([HELP_END])dnl
821 m4_divert_push([VERSION])dnl
822 if $at_version_p; then
823 AS_ECHO(["$as_me (AT_PACKAGE_STRING)"]) &&
824 cat <<\_ATEOF || at_write_fail=1
825 m4_divert_pop([VERSION])dnl
826 m4_divert_push([VERSION_END])dnl
830 m4_divert_pop([VERSION_END])dnl
831 m4_divert_push([TESTS_BEGIN])dnl
833 # Take any -C into account.
834 if $at_change_dir ; then
835 test x != "x$at_dir" && cd "$at_dir" \
836 || AS_ERROR([unable to change directory])
840 # Load the config files for any default variable assignments.
841 for at_file in atconfig atlocal
843 test -r $at_file || continue
844 . ./$at_file || AS_ERROR([invalid content: $at_file])
847 # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
848 : "${at_top_build_prefix=$at_top_builddir}"
850 # Perform any assignments requested during argument parsing.
851 eval "$at_debug_args"
853 # atconfig delivers names relative to the directory the test suite is
854 # in, but the groups themselves are run in testsuite-dir/group-dir.
855 if test -n "$at_top_srcdir"; then
857 for at_dir_var in srcdir top_srcdir top_build_prefix
859 AS_VAR_COPY([at_val], [at_$at_dir_var])
861 [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
862 *) at_prefix=../../ ;;
864 AS_VAR_SET([$at_dir_var], [$at_prefix$at_val])
868 m4_text_box([Directory structure.])
870 # This is the set of directories and files used by this script
871 # (non-literals are capitalized):
873 # TESTSUITE - the testsuite
874 # TESTSUITE.log - summarizes the complete testsuite run
875 # TESTSUITE.dir/ - created during a run, remains after -d or failed test
876 # + at-groups/ - during a run: status of all groups in run
877 # | + NNN/ - during a run: meta-data about test group NNN
878 # | | + check-line - location (source file and line) of current AT_CHECK
879 # | | + status - exit status of current AT_CHECK
880 # | | + stdout - stdout of current AT_CHECK
881 # | | + stder1 - stderr, including trace
882 # | | + stderr - stderr, with trace filtered out
883 # | | + test-source - portion of testsuite that defines group
884 # | | + times - timestamps for computing duration
885 # | | + pass - created if group passed
886 # | | + xpass - created if group xpassed
887 # | | + fail - created if group failed
888 # | | + xfail - created if group xfailed
889 # | | + skip - created if group skipped
890 # + at-stop - during a run: end the run if this file exists
891 # + at-source-lines - during a run: cache of TESTSUITE line numbers for extraction
892 # + 0..NNN/ - created for each group NNN, remains after -d or failed test
893 # | + TESTSUITE.log - summarizes the group results
894 # | + ... - files created during the group
896 # The directory the whole suite works in.
897 # Should be absolute to let the user 'cd' at will.
898 at_suite_dir=$at_dir/$as_me.dir
899 # The file containing the suite ($at_dir might have changed since earlier).
900 at_suite_log=$at_dir/$as_me.log
901 # The directory containing helper files per test group.
902 at_helper_dir=$at_suite_dir/at-groups
903 # Stop file: if it exists, do not start new jobs.
904 at_stop_file=$at_suite_dir/at-stop
905 # The fifo used for the job dispatcher.
906 at_job_fifo=$at_suite_dir/at-job-fifo
909 test -d "$at_suite_dir" &&
910 find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
911 rm -f -r "$at_suite_dir" "$at_suite_log"
915 # Don't take risks: use only absolute directories in PATH.
917 # For stand-alone test suites (ie. atconfig was not found),
918 # AUTOTEST_PATH is relative to '.'.
920 # For embedded test suites, AUTOTEST_PATH is relative to the top level
921 # of the package. Then expand it into build/src parts, since users
922 # may create executables in both places.
923 AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s|:|$PATH_SEPARATOR|g"`
925 _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
926 [test -n "$at_path" && AS_VAR_APPEND([at_path], [$PATH_SEPARATOR])
928 [[\\/]]* | ?:[[\\/]]* )
929 AS_VAR_APPEND([at_path], ["$as_dir"])
932 if test -z "$at_top_build_prefix"; then
933 # Stand-alone test suite.
934 AS_VAR_APPEND([at_path], ["$as_dir"])
936 # Embedded test suite.
937 AS_VAR_APPEND([at_path], ["$at_top_build_prefix$as_dir$PATH_SEPARATOR"])
938 AS_VAR_APPEND([at_path], ["$at_top_srcdir/$as_dir"])
943 # Now build and simplify PATH.
945 # There might be directories that don't exist, but don't redirect
946 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
948 _AS_PATH_WALK([$at_path],
949 [test -d "$as_dir" || continue
951 [[\\/]]* | ?:[[\\/]]* ) ;;
952 * ) as_dir=`(cd "$as_dir" && pwd) 2>/dev/null` ;;
954 case $PATH_SEPARATOR$at_new_path$PATH_SEPARATOR in
955 *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR*) ;;
956 $PATH_SEPARATOR$PATH_SEPARATOR) at_new_path=$as_dir ;;
957 *) AS_VAR_APPEND([at_new_path], ["$PATH_SEPARATOR$as_dir"]) ;;
962 # Setting up the FDs.
963 [#] AS_MESSAGE_LOG_FD is the log file. Not to be overwritten if '-d'.
965 at_suite_log=/dev/null
969 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
972 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
974 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
977 AS_ECHO(["$as_me: command line was:"])
978 AS_ECHO([" \$ $[0] $at_cli_args"])
981 # If ChangeLog exists, list a few lines in case it might help determining
983 if test -n "$at_top_srcdir" && test -f "$at_top_srcdir/ChangeLog"; then
986 sed 's/^/| /;10q' "$at_top_srcdir/ChangeLog"
993 # Contents of the config files.
994 for at_file in atconfig atlocal
996 test -r $at_file || continue
997 AS_ECHO(["$as_me: $at_file:"])
998 sed 's/^/| /' $at_file
1001 } >&AS_MESSAGE_LOG_FD
1003 m4_divert_pop([TESTS_BEGIN])dnl
1004 m4_divert_push([TESTS])dnl
1006 AS_BOX([Running the tests.])
1007 } >&AS_MESSAGE_LOG_FD
1009 at_start_date=`date`
1010 at_start_time=`date +%s 2>/dev/null`
1011 AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
1013 # Create the master directory if it doesn't already exist.
1014 AS_MKDIR_P(["$at_suite_dir"]) ||
1015 AS_ERROR([cannot create '$at_suite_dir'])
1017 # Can we diff with '/dev/null'? DU 5.0 refuses.
1018 if diff /dev/null /dev/null >/dev/null 2>&1; then
1019 at_devnull=/dev/null
1021 at_devnull=$at_suite_dir/devnull
1025 # Use 'diff -u' when possible.
1026 if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
1033 # Get the last needed group.
1034 for at_group in : $at_groups; do :; done
1036 # Extract the start and end lines of each test group at the tail
1044 test = substr ($ 0, 10)
1045 print "at_sed" test "=\"1," start "d;" (NR-1) "q\""
1046 if (test == "'"$at_group"'") exit
1047 }' "$at_myself" > "$at_suite_dir/at-source-lines" &&
1048 . "$at_suite_dir/at-source-lines" ||
1049 AS_ERROR([cannot create test line number cache])
1050 rm -f "$at_suite_dir/at-source-lines"
1052 # Set number of jobs for '-j'; avoid more jobs than test groups.
1053 set X $at_groups; shift; at_max_jobs=$[@%:@]
1054 if test $at_max_jobs -eq 0; then
1057 if test $at_jobs -ne 1 &&
1058 { test $at_jobs -eq 0 || test $at_jobs -gt $at_max_jobs; }; then
1059 at_jobs=$at_max_jobs
1062 # If parallel mode, don't output banners, don't split summary lines.
1063 if test $at_jobs -ne 1; then
1064 at_print_banners=false
1068 # Set up helper dirs.
1069 rm -rf "$at_helper_dir" &&
1070 mkdir "$at_helper_dir" &&
1071 cd "$at_helper_dir" &&
1072 { test -z "$at_groups" || mkdir $at_groups; } ||
1073 AS_ERROR([testsuite directory setup failed])
1075 # Functions for running a test group. We leave the actual
1076 # test group execution outside of a shell function in order
1077 # to avoid hitting zsh 4.x exit status bugs.
1079 AS_FUNCTION_DESCRIBE([at_fn_group_prepare], [],
1080 [Prepare for running a test group.])
1081 at_fn_group_prepare ()
1083 # The directory for additional per-group helper files.
1084 at_job_dir=$at_helper_dir/$at_group
1085 # The file containing the location of the last AT_CHECK.
1086 at_check_line_file=$at_job_dir/check-line
1087 # The file containing the exit status of the last command.
1088 at_status_file=$at_job_dir/status
1089 # The files containing the output of the tested commands.
1090 at_stdout=$at_job_dir/stdout
1091 at_stder1=$at_job_dir/stder1
1092 at_stderr=$at_job_dir/stderr
1093 # The file containing the code for a test group.
1094 at_test_source=$at_job_dir/test-source
1095 # The file containing dates.
1096 at_times_file=$at_job_dir/times
1098 # Be sure to come back to the top test directory.
1101 # Clearly separate the test groups when verbose.
1102 $at_first || $at_verbose echo
1104 at_group_normalized=$at_group
1105 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1107 # Create a fresh directory for the next test group, and enter.
1108 # If one already exists, the user may have invoked ./run from
1109 # within that directory; we remove the contents, but not the
1110 # directory itself, so that we aren't pulling the rug out from
1111 # under the shell's notion of the current directory.
1112 at_group_dir=$at_suite_dir/$at_group_normalized
1113 at_group_log=$at_group_dir/$as_me.log
1114 _AS_CLEAN_DIR("$at_group_dir") ||
1115 AS_WARN([test directory for $at_group_normalized could not be cleaned])
1116 # Be tolerant if the above 'rm' was not able to remove the directory.
1117 AS_MKDIR_P(["$at_group_dir"])
1119 echo 0 > "$at_status_file"
1121 # In verbose mode, append to the log file *and* show on
1122 # the standard output; in quiet mode only write to the log.
1123 if test -z "$at_verbose"; then
1124 at_tee_pipe='tee -a "$at_group_log"'
1126 at_tee_pipe='cat >> "$at_group_log"'
1130 AS_FUNCTION_DESCRIBE([at_fn_group_banner], [[ORDINAL LINE DESC PAD [BANNER]]],
1131 [Declare the test group ORDINAL, located at LINE with group description
1132 DESC, and residing under BANNER. Use PAD to align the status column.])
1133 at_fn_group_banner ()
1135 at_setup_line="$[2]"
1136 test -n "$[5]" && at_fn_banner $[5]
1139 [[0-9]]) at_desc_line=" $[1]: ";;
1140 [[0-9][0-9]]) at_desc_line=" $[1]: " ;;
1141 [*]) at_desc_line="$[1]: " ;;
1143 AS_VAR_APPEND([at_desc_line], ["$[3]$[4]"])
1144 $at_quiet AS_ECHO_N(["$at_desc_line"])
1145 echo "# -*- compilation -*-" >> "$at_group_log"
1148 AS_FUNCTION_DESCRIBE([at_fn_group_postprocess], [],
1149 [Perform cleanup after running a test group.])
1150 at_fn_group_postprocess ()
1152 # Be sure to come back to the suite directory, in particular
1153 # since below we might 'rm' the group directory we are in currently.
1156 if test ! -f "$at_check_line_file"; then
1157 sed "s/^ */$as_me: WARNING: /" <<_ATEOF
1158 A failure happened in a test group before any test could be
1159 run. This means that test suite is improperly designed. Please
1160 report this failure to <AT_PACKAGE_BUGREPORT>.
1162 AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
1165 $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
1166 AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
1167 case $at_xfail:$at_status in
1169 at_msg="UNEXPECTED PASS"
1171 at_errexit=$at_errexit_p
1181 at_msg='skipped ('`cat "$at_check_line_file"`')'
1187 at_msg='FAILED ('`cat "$at_check_line_file"`')'
1189 at_errexit=$at_errexit_p
1193 at_msg='expected failure ('`cat "$at_check_line_file"`')'
1199 echo "$at_res" > "$at_job_dir/$at_res"
1200 # In parallel mode, output the summary line only afterwards.
1201 if test $at_jobs -ne 1 && test -n "$at_verbose"; then
1202 AS_ECHO(["$at_desc_line $at_color$at_msg$at_std"])
1204 # Make sure there is a separator even with long titles.
1205 AS_ECHO([" $at_color$at_msg$at_std"])
1207 at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
1210 # $at_times_file is only available if the group succeeded.
1211 # We're not including the group log, so the success message
1212 # is written in the global log separately. But we also
1213 # write to the group log in case they're using -d.
1214 if test -f "$at_times_file"; then
1215 at_log_msg="$at_log_msg ("`sed 1d "$at_times_file"`')'
1216 rm -f "$at_times_file"
1218 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
1219 AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
1221 # Cleanup the group directory, unless the user wants the files
1222 # or the success was unexpected.
1223 if $at_debug_p || test $at_res = xpass; then
1224 at_fn_create_debugging_script
1225 if test $at_res = xpass && $at_errexit; then
1226 echo stop > "$at_stop_file"
1229 if test -d "$at_group_dir"; then
1230 find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
1231 rm -fr "$at_group_dir"
1233 rm -f "$at_test_source"
1237 # Upon failure, include the log into the testsuite's global
1238 # log. The failure message is written in the group log. It
1239 # is later included in the global log.
1240 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
1242 # Upon failure, keep the group directory for autopsy, and create
1243 # the debugging script. With -e, do not start any further tests.
1244 at_fn_create_debugging_script
1245 if $at_errexit; then
1246 echo stop > "$at_stop_file"
1253 m4_text_box([Driver loop.])
1255 dnl Catching signals correctly:
1257 dnl The first idea was: trap the signal, send it to all spawned jobs,
1258 dnl then reset the handler and reraise the signal for ourselves.
1259 dnl However, before exiting, ksh will then send the signal to all
1260 dnl process group members, potentially killing the outer testsuite
1261 dnl and/or the 'make' process driving us.
1262 dnl So now the strategy is: trap the signal, send it to all spawned jobs,
1263 dnl then exit the script with the right status.
1265 dnl In order to let the jobs know about the signal, we cannot just send it
1266 dnl to the current process group (kill $SIG 0), for the same reason as above.
1267 dnl Also, it does not reliably stop the suite to send the signal to the
1268 dnl spawned processes, because they might not transport it further
1269 dnl (maybe this can be fixed?).
1271 dnl So what we do is enable shell job control if available, which causes the
1272 dnl shell to start each parallel task as its own shell job, thus as a new
1273 dnl process group leader. We then send the signal to all new process groups.
1275 dnl Do we have job control?
1276 if (set -m && set +m && set +b) >/dev/null 2>&1; then
1278 at_job_control_on='set -m' at_job_control_off='set +m' at_job_group=-
1280 at_job_control_on=: at_job_control_off=: at_job_group=
1283 for at_signal in 1 2 15; do
1284 dnl This signal handler is not suitable for PIPE: it causes writes.
1285 dnl The code that was interrupted may have the errexit, monitor, or xtrace
1286 dnl flags enabled, so sanitize.
1287 trap 'set +x; set +e
1289 at_signal='"$at_signal"'
1290 dnl Safety belt: even with runaway processes, prevent starting new jobs.
1291 echo stop > "$at_stop_file"
1292 dnl Do not enter this area multiple times, do not kill self prematurely.
1294 dnl Gather process group IDs of currently running jobs.
1296 for at_pgid in `jobs -p 2>/dev/null`; do
1297 at_pgids="$at_pgids $at_job_group$at_pgid"
1299 dnl Ignore 'kill' errors, as some jobs may have finished in the meantime.
1300 test -z "$at_pgids" || kill -$at_signal $at_pgids 2>/dev/null
1301 dnl wait until all jobs have exited.
1303 dnl Status output. Do this after waiting for the jobs, for ordered output.
1304 dnl Avoid scribbling onto the end of a possibly incomplete line.
1305 if test "$at_jobs" -eq 1 || test -z "$at_verbose"; then
1308 at_signame=`kill -l $at_signal 2>&1 || echo $at_signal`
1310 test $# -gt 2 && at_signame=$at_signal
1311 AS_WARN([caught signal $at_signame, bailing out])
1312 dnl Do not reinstall the default handler here and reraise the signal to
1313 dnl let the default handler do its job, see the note about ksh above.
1314 dnl trap - $at_signal
1315 dnl kill -$at_signal $$
1316 dnl Instead, exit with appropriate status.
1317 AS_VAR_ARITH([exit_status], [128 + $at_signal])
1318 AS_EXIT([$exit_status])' $at_signal
1321 rm -f "$at_stop_file"
1324 if test $at_jobs -ne 1 &&
1325 rm -f "$at_job_fifo" &&
1326 test -n "$at_job_group" &&
1327 ( mkfifo "$at_job_fifo" && trap 'exit 1' PIPE STOP TSTP ) 2>/dev/null
1329 # FIFO job dispatcher.
1331 dnl Since we use job control, we need to propagate TSTP.
1332 dnl This handler need not be used for serial execution.
1333 dnl Again, we should stop all processes in the job groups, otherwise
1334 dnl the stopping will not be effective while one test group is running.
1335 dnl Apparently ksh does not honor the TSTP trap.
1336 dnl As a safety measure, not use the same variable names as in the
1337 dnl termination handlers above, one might get called during execution
1340 for at_pid in `jobs -p`; do
1341 at_pids="$at_pids $at_job_group$at_pid"
1343 dnl Send it to all spawned jobs, ignoring those finished meanwhile.
1344 if test -n "$at_pids"; then
1345 dnl Unfortunately, ksh93 fork-bombs when we send TSTP, so send STOP
1346 dnl if this might be ksh (STOP prevents possible TSTP handlers inside
1347 dnl AT_CHECKs from running). Then stop ourselves.
1349 test ${TMOUT+y} && at_sig=STOP
1350 kill -$at_sig $at_pids 2>/dev/null
1353 dnl We got a CONT, so let's go again. Passing this to all processes
1354 dnl in the groups is necessary (because we stopped them), but it may
1355 dnl cause changed test semantics; e.g., a sleep will be interrupted.
1356 test -z "$at_pids" || kill -CONT $at_pids 2>/dev/null' TSTP
1359 # Turn jobs into a list of numbers, starting from 1.
1360 at_joblist=`AS_ECHO(["$at_groups"]) | sed -n 1,${at_jobs}p`
1364 for at_group in $at_groups; do
1365 dnl Enable job control only for spawning the test group:
1366 dnl Let the jobs to run in separate process groups, but
1367 dnl avoid all the status output by the shell.
1368 $at_job_control_on 2>/dev/null
1370 # Start one test group.
1372 dnl First child must open the fifo to avoid blocking parent; all other
1373 dnl children inherit it already opened from the parent.
1375 exec AT_JOB_FIFO_OUT_FD>"$at_job_fifo"
1377 dnl Children do not need parent's copy of fifo.
1378 exec AT_JOB_FIFO_IN_FD<&-
1380 dnl When a child receives PIPE, be sure to write back the token,
1381 dnl so the master does not hang waiting for it.
1382 dnl errexit and xtrace should not be set in this shell instance,
1383 dnl except as debug measures. However, shells such as dash may
1384 dnl optimize away the _AT_CHECK subshell, so normalize here.
1385 trap 'set +x; set +e
1386 dnl Ignore PIPE signals that stem from writing back the token.
1388 echo stop > "$at_stop_file"
1389 echo >&AT_JOB_FIFO_OUT_FD
1390 dnl Do not reraise the default PIPE handler.
1391 dnl It wreaks havoc with ksh, see above.
1394 AS_EXIT([141])' PIPE
1396 if cd "$at_group_dir" &&
1397 at_fn_test $at_group &&
1400 AS_WARN([unable to parse test group: $at_group])
1403 at_fn_group_postprocess
1404 echo >&AT_JOB_FIFO_OUT_FD
1409 exec AT_JOB_FIFO_IN_FD<"$at_job_fifo" AT_JOB_FIFO_OUT_FD>"$at_job_fifo"
1411 shift # Consume one token.
1412 if test $[@%:@] -gt 0; then :; else
1413 read at_token <&AT_JOB_FIFO_IN_FD || break
1416 test -f "$at_stop_file" && break
1418 exec AT_JOB_FIFO_OUT_FD>&-
1419 # Read back the remaining ($at_jobs - 1) tokens.
1422 if test $[@%:@] -gt 0; then
1427 done <&AT_JOB_FIFO_IN_FD
1429 exec AT_JOB_FIFO_IN_FD<&-
1432 # Run serially, avoid forks and other potential surprises.
1433 for at_group in $at_groups; do
1435 if cd "$at_group_dir" &&
1436 at_fn_test $at_group &&
1437 . "$at_test_source"; then :; else
1438 AS_WARN([unable to parse test group: $at_group])
1441 at_fn_group_postprocess
1442 test -f "$at_stop_file" && break
1447 # Wrap up the test suite with summary statistics.
1450 # Use ?..???? when the list must remain sorted, the faster * otherwise.
1451 at_pass_list=`for f in */pass; do echo $f; done | sed '/\*/d; s,/pass,,'`
1452 at_skip_list=`for f in */skip; do echo $f; done | sed '/\*/d; s,/skip,,'`
1453 at_xfail_list=`for f in */xfail; do echo $f; done | sed '/\*/d; s,/xfail,,'`
1454 at_xpass_list=`for f in ?/xpass ??/xpass ???/xpass ????/xpass; do
1455 echo $f; done | sed '/?/d; s,/xpass,,'`
1456 at_fail_list=`for f in ?/fail ??/fail ???/fail ????/fail; do
1457 echo $f; done | sed '/?/d; s,/fail,,'`
1459 set X $at_pass_list $at_xpass_list $at_xfail_list $at_fail_list $at_skip_list
1460 shift; at_group_count=$[@%:@]
1461 set X $at_xpass_list; shift; at_xpass_count=$[@%:@]; at_xpass_list=$[*]
1462 set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
1463 set X $at_fail_list; shift; at_fail_count=$[@%:@]; at_fail_list=$[*]
1464 set X $at_skip_list; shift; at_skip_count=$[@%:@]
1466 AS_VAR_ARITH([at_run_count], [$at_group_count - $at_skip_count])
1467 AS_VAR_ARITH([at_unexpected_count], [$at_xpass_count + $at_fail_count])
1468 AS_VAR_ARITH([at_total_fail_count], [$at_xfail_count + $at_fail_count])
1470 # Back to the top directory.
1472 rm -rf "$at_helper_dir"
1474 # Compute the duration of the suite.
1476 at_stop_time=`date +%s 2>/dev/null`
1477 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
1478 case $at_start_time,$at_stop_time in
1480 AS_VAR_ARITH([at_duration_s], [$at_stop_time - $at_start_time])
1481 AS_VAR_ARITH([at_duration_m], [$at_duration_s / 60])
1482 AS_VAR_ARITH([at_duration_h], [$at_duration_m / 60])
1483 AS_VAR_ARITH([at_duration_s], [$at_duration_s % 60])
1484 AS_VAR_ARITH([at_duration_m], [$at_duration_m % 60])
1485 at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
1486 AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
1491 AS_BOX([Test results.])
1495 AS_BOX([Test results.])
1497 } >&AS_MESSAGE_LOG_FD
1500 dnl FIXME: this code is as far from i18n-cleanness as man
1501 dnl could imagine...
1503 if test $at_run_count = 1; then
1507 at_result="$at_run_count tests"
1510 if $at_errexit_p && test $at_unexpected_count != 0; then
1511 if test $at_xpass_count = 1; then
1512 at_result="$at_result $at_were run, one passed"
1514 at_result="$at_result $at_were run, one failed"
1516 at_result="$at_result unexpectedly and inhibited subsequent tests."
1519 # Don't you just love exponential explosion of the number of cases?
1521 case $at_xpass_count:$at_fail_count:$at_xfail_count in
1523 0:0:0) at_result="$at_result $at_were successful." at_color=$at_grn ;;
1524 0:0:*) at_result="$at_result behaved as expected." at_color=$at_lgn ;;
1526 # Some unexpected failures
1527 0:*:0) at_result="$at_result $at_were run,
1528 $at_fail_count failed unexpectedly." ;;
1530 # Some failures, both expected and unexpected
1531 0:*:1) at_result="$at_result $at_were run,
1532 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1533 0:*:*) at_result="$at_result $at_were run,
1534 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1536 # No unexpected failures, but some xpasses
1537 *:0:*) at_result="$at_result $at_were run,
1538 $at_xpass_count passed unexpectedly." ;;
1540 # No expected failures, but failures and xpasses
1541 *:1:0) at_result="$at_result $at_were run,
1542 $at_unexpected_count did not behave as expected dnl
1543 ($at_fail_count unexpected failure)." ;;
1544 *:*:0) at_result="$at_result $at_were run,
1545 $at_unexpected_count did not behave as expected dnl
1546 ($at_fail_count unexpected failures)." ;;
1549 *:*:1) at_result="$at_result $at_were run,
1550 $at_xpass_count passed unexpectedly,
1551 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1552 *:*:*) at_result="$at_result $at_were run,
1553 $at_xpass_count passed unexpectedly,
1554 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1557 if test $at_skip_count = 0 && test $at_run_count -gt 1; then
1558 at_result="All $at_result"
1562 # Now put skips in the mix.
1563 case $at_skip_count in
1565 1) at_result="$at_result
1566 1 test was skipped." ;;
1567 *) at_result="$at_result
1568 $at_skip_count tests were skipped." ;;
1571 if test $at_unexpected_count = 0; then
1572 echo "$at_color$at_result$at_std"
1573 echo "$at_result" >&AS_MESSAGE_LOG_FD
1575 echo "${at_color}ERROR: $at_result$at_std" >&2
1576 echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
1579 AS_BOX([Summary of the failures.])
1581 # Summary of failed and skipped tests.
1582 if test $at_fail_count != 0; then
1583 echo "Failed tests:"
1584 $SHELL "$at_myself" $at_fail_list --list
1587 if test $at_skip_count != 0; then
1588 echo "Skipped tests:"
1589 $SHELL "$at_myself" $at_skip_list --list
1592 if test $at_xpass_count != 0; then
1593 echo "Unexpected passes:"
1594 $SHELL "$at_myself" $at_xpass_list --list
1597 if test $at_fail_count != 0; then
1598 AS_BOX([Detailed failed tests.])
1600 for at_group in $at_fail_list
1602 at_group_normalized=$at_group
1603 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1604 cat "$at_suite_dir/$at_group_normalized/$as_me.log"
1609 if test -n "$at_top_srcdir"; then
1610 AS_BOX([${at_top_build_prefix}config.log])
1611 sed 's/^/| /' ${at_top_build_prefix}config.log
1614 } >&AS_MESSAGE_LOG_FD
1616 AS_BOX([$as_me.log was created.])
1619 if $at_debug_p; then
1620 at_msg='per-test log files'
1622 at_msg="'${at_testdir+${at_testdir}/}$as_me.log'"
1624 at_msg1a=${at_xpass_list:+', '}
1625 at_msg1=$at_fail_list${at_fail_list:+" failed$at_msg1a"}
1626 at_msg2=$at_xpass_list${at_xpass_list:+" passed unexpectedly"}
1628 AS_ECHO(["Please send $at_msg and all information you think might help:
1630 To: <AT_PACKAGE_BUGREPORT>
1631 Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me: dnl
1634 You may investigate any problem if you feel able to do so, in which
1635 case the test suite provides a good starting point. Its output may
1636 be found below '${at_testdir+${at_testdir}/}$as_me.dir'.
1643 m4_text_box([Actual tests.])
1644 m4_divert_pop([TESTS])dnl
1645 dnl End of AT_INIT: divert to KILL, only test groups are to be
1646 dnl output, the rest is ignored. Current diversion is BODY, inherited
1652 # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
1653 # [ACTION-IF-NOT-GIVEN])
1654 # ----------------------------------------------------------
1655 # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
1656 m4_defun([_AT_ARG_OPTION],
1657 [m4_divert_once([HELP_OTHER],
1658 [cat <<_ATEOF || at_write_fail=1
1662 ])dnl m4_divert_once HELP_OTHER
1663 m4_divert_text([HELP_OTHER],
1664 [cat <<_ATEOF || at_write_fail=1
1667 dnl Turn our options into our desired strings
1668 m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
1669 m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
1670 m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
1671 m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
1672 m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
1673 [m4_define_default([AT_first_option],AT_option)dnl
1674 m4_define_default([AT_first_option_tr],
1675 [m4_bpatsubst(m4_defn([AT_first_option]), -, [_])])dnl
1676 m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
1677 m4_append([AT_case_no],[--no-]AT_option, [ | ])dnl
1678 m4_append([AT_case_arg],
1679 m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
1680 ])dnl m4_foreach AT_option
1681 dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
1682 m4_divert_once([PARSE_ARGS_BEGIN],
1685 ## Set up package specific options.
1688 m4_divert_text([PARSE_ARGS_BEGIN],
1689 [dnl Provide a default value for options without arguments.
1690 m4_ifvaln([$3],,[at_arg_[]AT_first_option_tr=false])dnl
1691 at_arg_given_[]AT_first_option_tr=false
1692 ])dnl m4_divert_text DEFAULTS
1693 m4_divert_text([PARSE_ARGS],
1694 [dnl Parse the options and args when necessary.
1697 at_prev=--AT_first_option_tr
1700 at_arg_[]AT_first_option_tr=$at_optarg
1701 at_arg_given_[]AT_first_option_tr=:
1706 at_arg_[]AT_first_option_tr=:
1707 at_arg_given_[]AT_first_option_tr=:
1708 m4_ifval([$4],[$4])[]dnl
1712 at_arg_[]AT_first_option_tr=false
1713 at_arg_given_[]AT_first_option_tr=:
1714 m4_ifval([$4],[$4])[]dnl
1715 ;;])dnl m4_ifvaln $3
1716 ])dnl m4_divert_text PARSE_ARGS
1718 [m4_divert_once([PARSE_ARGS_END],
1721 ## Process package specific options when _not_ supplied.
1722 ##])dnl m4_divert_once PARSE_ARGS_END
1723 m4_divert_text([PARSE_ARGS_END],
1725 AS_IF([$at_arg_given_[]AT_first_option_tr],,[$5])dnl
1726 ])dnl m4_divert_text PARSE_ARGS_END
1728 ])dnl _AT_ARG_OPTION
1731 # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1732 # ------------------------------------------------------------------------
1733 # Accept a list of space-separated OPTIONS, all aliases of the first one.
1734 # Add HELP-TEXT to the HELP_OTHER diversion.
1736 # Leading dashes should not be passed in OPTIONS. Users will be required
1737 # to pass '--' before long options and '-' before single character options.
1739 # $at_arg_OPTION will be set to ':' if this option is received, 'false' if
1740 # if --no-OPTION is received, and 'false' by default.
1742 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered; here,
1743 # $at_optarg will be set to ':' or 'false' as appropriate. $at_optarg is
1744 # actually just a copy of $at_arg_OPTION.
1746 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete and
1747 # if no option from OPTIONS was used.
1748 m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
1751 # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1752 # ----------------------------------------------------------------------------
1753 # Accept a set of space-separated OPTIONS with arguments, all aliases of the
1754 # first one. Add HELP-TEXT to the HELP_OTHER diversion.
1756 # Leading dashes should not be passed in OPTIONS. Users will be required
1757 # to pass '--' before long options and '-' before single character options.
1759 # By default, any argument to these options will be assigned to the shell
1760 # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
1761 # any '-' characters replaced with '_'.
1763 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered; here,
1764 # $at_optarg will be set to the option argument. $at_optarg is actually just
1765 # a copy of $at_arg_OPTION.
1767 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1768 # and if no option from OPTIONS was used.
1769 m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
1772 # AT_TESTED(PROGRAMS)
1773 # -------------------
1774 # Specify the list of programs exercised by the test suite. Their
1775 # versions are logged, and in the case of embedded test suite, they
1776 # must correspond to the version of the package. PATH should be
1777 # already preset so the proper executable will be selected.
1778 m4_defun([AT_TESTED],
1779 [m4_require([_AT_TESTED])]dnl
1780 [m4_foreach_w([AT_test], [$1],
1781 [m4_append_uniq([AT_tested], "m4_defn([AT_test])", [ ])])])
1783 m4_defun([_AT_TESTED],
1784 [m4_wrap([m4_divert_text([DEFAULTS],
1785 [# List of the tested programs.
1786 at_tested='m4_translit(m4_dquote(m4_defn([AT_tested])), [ ], m4_newline)'
1788 [m4_divert_text([PREPARE_TESTS],
1790 AS_BOX([Tested programs.])
1792 } >&AS_MESSAGE_LOG_FD
1794 # Report what programs are being tested.
1795 for at_program in : `eval echo $at_tested`
1797 AS_CASE([$at_program],
1799 [[[\\/]* | ?:[\\/]*]], [at_program_=$at_program],
1800 [_AS_PATH_WALK([$PATH], [test -f "$as_dir$at_program" && break])
1801 at_program_=$as_dir$at_program])
1803 if test -f "$at_program_"; then
1805 AS_ECHO(["$at_srcdir/AT_LINE: $at_program_ --version"])
1806 "$at_program_" --version </dev/null
1808 } >&AS_MESSAGE_LOG_FD 2>&1
1810 AS_ERROR([cannot find $at_program])
1816 # AT_PREPARE_TESTS(SHELL-CODE)
1817 # ----------------------------
1818 # Execute @var{shell-code} in the main testsuite process,
1819 # after initializing the test suite and processing command-line options,
1820 # but before running any tests.
1821 m4_define([AT_PREPARE_TESTS],
1822 [m4_divert_once([PREPARE_TESTS],
1823 [m4_text_box([Prepare for this testsuite.])
1825 [m4_divert_text([PREPARE_TESTS], [$1])])
1828 # AT_PREPARE_EACH_TEST([SHELL-CODE])
1829 # ----------------------------------
1830 # Execute @var{shell-code} in each test group's subshell,
1831 # at the point of the AT_SETUP that starts each test group.
1832 m4_define([AT_PREPARE_EACH_TEST],
1833 [m4_append([AT_prepare_each_test], [$1], [
1837 # AT_TEST_HELPER_FN(NAME, ARGS, DESCRIPTION, CODE)
1838 # ------------------------------------------------
1839 # Define a shell function that will be available to the code for each test
1840 # group. Its name will be ath_fn_NAME, and its body will be CODE.
1842 # Implementation note: you might think this would use AT_PREPARE_EACH_TEST,
1843 # but shell functions defined in AT_PREPARE_TESTS *are* (currently) available
1844 # to test group subshells, and this way the code is only emitted once, not
1845 # once for each test group.
1846 m4_define([AT_TEST_HELPER_FN],
1847 [AS_LITERAL_WORD_IF([$1], [],
1848 [m4_fatal([invalid shell function name "$1"])])]dnl
1849 [m4_ifdef([ATH_fn_$1_defined],
1850 [m4_fatal([helper function "$1" defined twice])])]dnl
1851 [m4_define([ATH_fn_$1_defined])]dnl
1853 AS_FUNCTION_DESCRIBE([ath_fn_$1], [$2], [$3])
1861 # AT_COPYRIGHT(TEXT, [FILTER = m4_newline])
1862 # -----------------------------------------
1863 # Emit TEXT, a copyright notice, in the top of the test suite and in
1864 # --version output. Macros in TEXT are evaluated once. Process
1865 # the --version output through FILTER (m4_newline, m4_do, and
1866 # m4_copyright_condense are common filters).
1867 m4_define([AT_COPYRIGHT],
1868 [AS_COPYRIGHT([$1])[]]dnl
1869 [m4_divert_text([VERSION_NOTICES],
1870 [m4_default([$2], [m4_newline])([$1])])])# AT_COPYRIGHT
1875 # Enable colored test results if standard error is connected to a terminal.
1876 m4_define([AT_COLOR_TESTS],
1877 [m4_define([AT_color], [auto])])
1879 # AT_SETUP(DESCRIPTION)
1880 # ---------------------
1881 # Start a group of related tests, all to be executed in the same subshell.
1882 # The group is testing what DESCRIPTION says.
1883 _AT_DEFINE_INIT([AT_SETUP],
1884 [m4_ifdef([AT_ingroup], [m4_fatal([$0: nested AT_SETUP detected])],
1885 [m4_define([AT_ingroup], [AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
1887 m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
1888 m4_define([AT_capture_files], [])
1889 m4_define([AT_line], AT_LINE)
1890 m4_define([AT_xfail], [at_xfail=no])
1891 m4_define([AT_description], m4_expand([$1]))
1892 m4_define([AT_ordinal], m4_incr(AT_ordinal))
1893 m4_divert_push([TEST_GROUPS])dnl
1894 [#AT_START_]AT_ordinal
1895 at_fn_group_banner AT_ordinal 'm4_defn([AT_line])' \
1896 "AS_ESCAPE(m4_dquote(m4_defn([AT_description])))" m4_format(["%*s"],
1897 m4_max(0, m4_eval(47 - m4_qlen(m4_defn([AT_description])))), [])m4_if(
1898 AT_banner_ordinal, [0], [], [ AT_banner_ordinal])
1899 m4_ifset([AT_prepare_each_test], [AT_prepare_each_test
1901 m4_divert_push([TEST_SCRIPT])dnl
1905 # AT_FAIL_IF(SHELL-EXPRESSION)
1906 # ----------------------------
1907 # Make the test die with hard failure if SHELL-EXPRESSION evaluates to
1908 # true (exitcode = 0).
1909 _AT_DEFINE_SETUP([AT_FAIL_IF],
1911 dnl Try to limit the amount of conditionals that we emit.
1915 [:], [_AT_CHECK_EXIT([], [99])],
1916 [true], [_AT_CHECK_EXIT([], [99])],
1917 [_AT_CHECK_EXIT([$1], [99])])])
1920 # AT_SKIP_IF(SHELL-EXPRESSION)
1921 # ----------------------------
1922 # Skip the rest of the group if SHELL-EXPRESSION evaluates to true
1924 _AT_DEFINE_SETUP([AT_SKIP_IF],
1926 dnl Try to limit the amount of conditionals that we emit.
1930 [:], [_AT_CHECK_EXIT([], [77])],
1931 [true], [_AT_CHECK_EXIT([], [77])],
1932 [_AT_CHECK_EXIT([$1], [77])])])
1935 # AT_XFAIL_IF(SHELL-EXPRESSION)
1936 # -----------------------------
1937 # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
1938 # true (exitcode = 0).
1939 _AT_DEFINE_SETUP([AT_XFAIL_IF],
1941 dnl Try to limit the amount of conditionals that we emit.
1945 [:], [m4_define([AT_xfail], [at_xfail=yes])],
1946 [true], [m4_define([AT_xfail], [at_xfail=yes])],
1947 [m4_append([AT_xfail], [
1948 $1 && at_xfail=yes])])])
1951 # AT_KEYWORDS(KEYWORDS)
1952 # ---------------------
1953 # Declare a list of keywords associated to the current test group.
1954 # Since the -k option is case-insensitive, the list is stored in lower case
1955 # to avoid duplicates that differ only by case.
1956 _AT_DEFINE_SETUP([AT_KEYWORDS],
1957 [m4_append_uniq_w([AT_keywords], m4_tolower(_m4_expand([$1
1961 # AT_CAPTURE_FILE(FILE)
1962 # ---------------------
1963 # If the current test group does not behave as expected, save the contents of
1964 # FILE in the test suite log.
1965 _AT_DEFINE_SETUP([AT_CAPTURE_FILE],
1966 [m4_append_uniq([AT_capture_files], ["$1"], [ \
1972 # Complete a group of related tests.
1973 _AT_DEFINE_INIT([AT_CLEANUP],
1974 [m4_ifdef([AT_ingroup], [AT_ingroup[]_m4_undefine([AT_ingroup])],
1975 [m4_fatal([$0: missing AT_SETUP detected])])dnl
1976 m4_append([AT_help_all],
1977 m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);dnl
1978 m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
1980 m4_divert_pop([TEST_SCRIPT])dnl Back to TEST_GROUPS
1983 AS_ECHO(["AT_ordinal. $at_setup_line: testing $at_desc ..."])
1985 m4_undivert([TEST_SCRIPT])dnl Insert the code here
1987 $at_times_p && times >"$at_times_file"
1988 ) AS_MESSAGE_LOG_FD>&1 2>&1 AT_JOB_FIFO_OUT_FD>&- | eval $at_tee_pipe
1989 read at_status <"$at_status_file"
1990 [#AT_STOP_]AT_ordinal
1991 m4_divert_pop([TEST_GROUPS])dnl Back to KILL.
1997 # Start a category of related test groups. If multiple groups are executed,
1998 # output TEXT as a banner without any shell expansion, prior to any test
1999 # from the category. If TEXT is empty, no banner is printed.
2000 _AT_DEFINE_INIT([AT_BANNER],
2001 [m4_ifdef([AT_ingroup], [m4_fatal([$0: nested AT_SETUP detected])])dnl
2002 m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
2003 m4_divert_text([BANNERS],
2004 [@%:@ Banner AT_banner_ordinal. AT_LINE
2005 @%:@ Category starts at test group m4_incr(AT_ordinal).
2006 at_banner_text_[]AT_banner_ordinal="AS_ESCAPE([$1])"])dnl
2010 # AT_DATA_UNQUOTED(FILE, CONTENTS)
2011 # -----------------------
2012 # Initialize an input data FILE with given CONTENTS, which should be
2013 # empty or end with a newline.
2014 # This macro is not robust to active symbols in CONTENTS *on purpose*.
2015 # If you don't want CONTENTS to be evaluated, quote it twice.
2016 # In addition, it does not quote shell variables. For example, it
2017 # can be used to generate data files containing a carriage return.
2018 _AT_DEFINE_SETUP([AT_DATA_UNQUOTED],
2019 [m4_if([$2], [], [: >$1],
2020 [$2], [[]], [: >$1],
2026 # AT_DATA(FILE, CONTENTS)
2027 # -----------------------
2028 # Initialize an input data FILE with given CONTENTS, which should be
2029 # empty or end with a newline.
2030 # This macro is not robust to active symbols in CONTENTS *on purpose*.
2031 # If you don't want CONTENTS to be evaluated, quote it twice.
2032 _AT_DEFINE_SETUP([AT_DATA],
2033 [m4_if([$2], [], [: >$1],
2034 [$2], [[]], [: >$1],
2040 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2041 # [RUN-IF-FAIL], [RUN-IF-PASS])
2042 # ------------------------------------------------
2043 # Execute a test by performing given shell COMMANDS. These commands
2044 # should normally exit with STATUS, while producing expected STDOUT and
2045 # STDERR contents. Shell metacharacters in STDOUT and STDERR are
2046 # _not_ processed by the shell, but are treated as string literals.
2048 # STATUS, STDOUT, and STDERR are not checked if equal to 'ignore'.
2050 # If STDOUT is 'expout', then stdout is compared to the content of the file
2051 # 'expout'. Likewise for STDERR and 'experr'.
2053 # If STDOUT is 'stdout', then the stdout is left in the file 'stdout',
2054 # likewise for STDERR and 'stderr'. Don't do this:
2056 # AT_CHECK([command >out])
2057 # # Some checks on 'out'
2061 # AT_CHECK([command], [], [stdout])
2062 # # Some checks on 'stdout'
2064 # You might wonder why you can't just use 'ignore', then directly use stdout
2065 # and stderr left by the test suite:
2067 # AT_CHECK([command], [], [ignore])
2068 # AT_CHECK([check stdout])
2070 # If the test suite always captured data in the file 'stdout', then the
2071 # second command would be trying to read and write from the same file, with
2072 # undefined behavior. Therefore, the test suite actually captures data in
2073 # an internal file of a different name, and only creates 'stdout' when
2074 # explicitly requested.
2076 # Any line of stderr starting with leading blanks and a '+' are filtered
2077 # out, since most shells when tracing include subshell traces in stderr.
2078 # This may cause spurious failures when the test suite is run with '-x'.
2080 _AT_DEFINE_SETUP([AT_CHECK],
2081 [_AT_CHECK(m4_expand([$1]), [$2], AS_ESCAPE(m4_dquote(m4_expand([$3]))),
2082 AS_ESCAPE(m4_dquote(m4_expand([$4]))), [$5], [$6])])
2084 # AT_CHECK_UNQUOTED(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2085 # [RUN-IF-FAIL], [RUN-IF-PASS])
2086 # ---------------------------------------------------------
2087 # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
2088 # and STDERR arguments before running the comparison.
2089 _AT_DEFINE_SETUP([AT_CHECK_UNQUOTED],
2090 [_AT_CHECK(m4_expand([$1]), [$2], AS_ESCAPE(m4_dquote(m4_expand([$3])), [""]),
2091 AS_ESCAPE(m4_dquote(m4_expand([$4])), [""]), [$5], [$6])])
2093 # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2094 # [RUN-IF-FAIL], [RUN-IF-PASS])
2095 # ---------------------------------------------------------
2096 # Obsolete spelling of AT_CHECK_UNQUOTED.
2097 m4_define([AT_CHECK_NOESCAPE],
2098 [m4_warn([obsolete], [consider using AT_CHECK_UNQUOTED instead of $0])]dnl
2099 [_AT_CHECK(m4_expand([$1]), [$2], m4_expand([$3]),
2100 m4_expand([$4]), [$5], [$6])])
2103 # _AT_DECIDE_TRACEABLE(COMMANDS)
2104 # ------------------------------
2105 # Worker for _AT_CHECK that expands to shell code. If COMMANDS are safe to
2106 # trace with 'set -x', the shell code will evaluate to true. Otherwise,
2107 # the shell code will print a message stating an aspect of COMMANDS that makes
2108 # tracing them unsafe, and evaluate to false.
2110 # Tracing COMMANDS is not safe if they contain a command that spans multiple
2111 # lines. When the test suite user passes '-x' or '--trace', the test suite
2112 # precedes every command with a 'set -x'. Since most tests expect a specific
2113 # stderr, if only to confirm that it is empty, the test suite filters ^+ from
2114 # the captured stderr before comparing with the expected stderr. If a command
2115 # spans multiple lines, so will its trace, but a '+' only prefixes the first
2116 # line of that trace:
2127 # In a subset of cases, one could filter such extended shell traces from
2128 # stderr. Since test commands spanning several lines are rare, I chose
2129 # instead to simply not trace COMMANDS that could yield multiple trace lines.
2130 # Distinguishing such COMMANDS became the task at hand.
2132 # These features may cause a shell command to span multiple lines:
2134 # (a) A quoted literal newline.
2138 # M4 is a hostile language for the job of parsing COMMANDS to determine whether
2139 # each literal newline is quoted, so we simply disable tracing for all COMMANDS
2140 # that bear literal newlines.
2142 # (b) A command substitution not subject to word splitting.
2144 # var=$(printf 'foo\nbar')
2146 # echo "`printf 'foo\\nbar`"
2147 # One cannot know in general the number of lines a command substitution will
2148 # yield without executing the substituted command. As such, we disable tracing
2149 # for all COMMANDS containing these constructs.
2151 # (c) A parameter expansion not subject to word splitting.
2156 # Parameter expansions appear in COMMANDS with much greater frequency than do
2157 # newlines and command substitutions, so disabling tracing for all such
2158 # COMMANDS would much more substantially devalue 'testsuite -x'. To determine
2159 # which parameter expansions yield multiple lines, we escape all '`', '"',
2160 # and '\' in a copy of COMMANDS and expand that string within double quotes
2161 # at runtime. If the result of that expansion contains multiple lines, the
2162 # test suite disables tracing for the command in question.
2164 # This method leads the test suite to expand some parameters that the shell
2165 # itself will never expand due to single-quotes or backslash escapes. This is
2166 # not a problem for '$foo' expansions, which will simply yield the empty string
2167 # or some unrelated value. A '${...}' expansion could actually form invalid
2168 # shell code, however; consider '${=foo}'. Therefore, we disable tracing for
2169 # all COMMANDS containing '${...}'. This affects few COMMANDS.
2171 # This macro falls in a very hot path; the Autoconf test suite expands it 1640
2172 # times as of this writing. To give a sense of the impact of the heuristics I
2173 # just described, the test suite preemptively disables tracing for 31 of those,
2174 # and 268 contain parameter expansions that require runtime evaluation. The
2175 # balance are always safe to trace.
2176 m4_define([_AT_DECIDE_TRACEABLE],
2179 dnl Examine COMMANDS for a reason to never trace COMMANDS.
2180 [m4_pushdef([at_reason],
2181 m4_cond([m4_eval(m4_index([$1], [`]) >= 0)], [1],
2182 [[a `...` command substitution]],
2183 [m4_eval(m4_index([$1], [$(]) >= 0)], [1],
2184 [[a $(...) command substitution]],
2185 [m4_eval(m4_index([$1], [${]) >= 0)], [1],
2186 [[a ${...} parameter expansion]],
2187 [m4_eval(m4_index([$1], m4_newline) >= 0)], [1],
2188 [[an embedded newline]],
2189 [m4_eval(m4_bregexp([$1], [[^|]|[^|]]) >= 0)], [1],
2190 [[a shell pipeline]],
2192 [m4_if(m4_index(_m4_defn([at_reason]), [a]), [0],]dnl
2193 dnl We know at build time that tracing COMMANDS is never safe.
2194 [[at_fn_check_prepare_notrace '_m4_defn([at_reason])'],
2195 m4_index([$1], [$]), [-1],]dnl
2196 dnl We know at build time that tracing COMMANDS is always safe.
2197 [[at_fn_check_prepare_trace],]dnl
2198 dnl COMMANDS may contain parameter expansions; expand them at runtime.
2199 [[at_fn_check_prepare_dynamic "AS_ESCAPE([[$1]], [`\"])"])[]]dnl
2200 [_m4_popdef([at_reason])])
2203 # AT_DIFF_STDERR/AT_DIFF_STDOUT
2204 # -----------------------------
2205 # These are subroutines of AT_CHECK. Using indirect dispatch is a tad
2206 # faster than using m4_case, and these are called very frequently.
2207 m4_define([AT_DIFF_STDERR(stderr)],
2208 [echo stderr:; tee stderr <"$at_stderr"])
2209 m4_define([AT_DIFF_STDERR(stderr-nolog)],
2210 [echo stderr captured; cp "$at_stderr" stderr])
2211 m4_define([AT_DIFF_STDERR(ignore)],
2212 [echo stderr:; cat "$at_stderr"])
2213 m4_define([AT_DIFF_STDERR(ignore-nolog)])
2214 m4_define([AT_DIFF_STDERR(experr)],
2215 [$at_diff experr "$at_stderr" || at_failed=:])
2216 m4_define([AT_DIFF_STDERR()],
2217 [at_fn_diff_devnull "$at_stderr" || at_failed=:])
2219 m4_define([AT_DIFF_STDOUT(stdout)],
2220 [echo stdout:; tee stdout <"$at_stdout"])
2221 m4_define([AT_DIFF_STDOUT(stdout-nolog)],
2222 [echo stdout captured; cp "$at_stdout" stdout])
2223 m4_define([AT_DIFF_STDOUT(ignore)],
2224 [echo stdout:; cat "$at_stdout"])
2225 m4_define([AT_DIFF_STDOUT(ignore-nolog)])
2226 m4_define([AT_DIFF_STDOUT(expout)],
2227 [$at_diff expout "$at_stdout" || at_failed=:])
2228 m4_define([AT_DIFF_STDOUT()],
2229 [at_fn_diff_devnull "$at_stdout" || at_failed=:])
2231 # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2232 # [RUN-IF-FAIL], [RUN-IF-PASS])
2233 # -------------------------------------------------
2234 # Worker for AT_CHECK and AT_CHECK_UNQUOTED, with COMMANDS, STDOUT, and
2235 # STDERR pre-expanded.
2237 # Implementation Details
2238 # ----------------------
2239 # Ideally, we would like to run
2241 # ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
2243 # but we must group COMMANDS as it is not limited to a single command, and
2244 # then the shells will save the traces in at-stderr. So we have to filter
2245 # them out when checking stderr, and we must send them into the test suite's
2246 # stderr to honor -x properly. Since only the first line of the trace of a
2247 # multiline command starts with a '+', and I know of no straightforward way to
2248 # filter out the unadorned trace lines, we disable shell tracing entirely for
2249 # commands that could span multiple lines.
2251 # Limiting COMMANDS to a single command is not good either, since then
2252 # the user herself would use {} or (), and then we face the same problem.
2254 # But then, there is no point in running
2256 # ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
2258 # instead of the simpler
2260 # ( $at_traceon; $1 ) >at-stdout 2>at-stder1
2262 # Note that we truncate and append to the output files, to avoid losing
2263 # output from multiple concurrent processes, e.g., an inner testsuite
2264 # with parallel jobs.
2265 m4_define([_AT_CHECK],
2266 [m4_define([AT_ingroup])]dnl
2268 AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([[$1]])"])
2269 _AT_DECIDE_TRACEABLE([$1]) _AT_LINE_ESCAPED
2270 ( $at_check_trace; [$1]
2271 ) >>"$at_stdout" 2>>"$at_stderr" AS_MESSAGE_LOG_FD>&-
2272 at_status=$? at_failed=false
2274 m4_ifdef([AT_DIFF_STDERR($4)], [m4_indir([AT_DIFF_STDERR($4)])],
2275 [echo >>"$at_stderr"; AS_ECHO([["$4"]]) | \
2276 $at_diff - "$at_stderr" || at_failed=:])
2277 m4_ifdef([AT_DIFF_STDOUT($3)], [m4_indir([AT_DIFF_STDOUT($3)])],
2278 [echo >>"$at_stdout"; AS_ECHO([["$3"]]) | \
2279 $at_diff - "$at_stdout" || at_failed=:])
2280 m4_if([$2], [ignore], [at_fn_check_skip],
2281 [at_fn_check_status m4_default([$2], [0])]) $at_status "$at_srcdir/AT_LINE"
2282 m4_ifvaln([$5$6], [AS_IF($at_failed, [$5], [$6])])]dnl
2283 [$at_failed && at_fn_log_failure AT_capture_files
2287 # _AT_CHECK_EXIT(COMMANDS, [EXIT-STATUS-IF-PASS])
2288 # -----------------------------------------------
2289 # Minimal version of _AT_CHECK for AT_SKIP_IF and AT_FAIL_IF.
2290 m4_define([_AT_CHECK_EXIT],
2291 [m4_define([AT_ingroup])]dnl
2292 [AS_ECHO(_AT_LINE_ESCAPED) >"$at_check_line_file"
2293 m4_ifval([$1], [($1) \
2294 && ])at_fn_check_skip $2 "$at_srcdir/AT_LINE"])# _AT_CHECK_EXIT