Debian Codegraph @

lib/autotest/general.m4

raw
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-2026 Free Software Foundation, Inc.
5 ])
6
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.
12 #
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.
17 #
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.
21 #
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/> and
26 # <https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=blob_plain;f=COPYING.EXCEPTION>.
27
28
29 # _m4_divert(DIVERSION-NAME)
30 # --------------------------
31 # Convert a diversion name into its number. Otherwise, return
32 # DIVERSION-NAME which is supposed to be an actual diversion number.
33 # Of course it would be nicer to use m4_case here, instead of zillions
34 # of little macros, but it then takes twice longer to run 'autoconf'!
35 #
36 # From M4sugar:
37 # -1. KILL
38 # 10000. GROW
39 #
40 # From M4sh:
41 # 0. BINSH
42 # 1. HEADER-REVISION
43 # 2. HEADER-COMMENT
44 # 3. HEADER-COPYRIGHT
45 # 4. M4SH-SANITIZE
46 # 5. M4SH-INIT
47 # 1000. BODY
48 #
49 # Defined below:
50 # - DEFAULTS
51 # Overall initialization, value of $at_groups_all.
52 # - PARSE_ARGS_BEGIN
53 # Setup defaults required for option processing.
54 # - PARSE_ARGS
55 # Option processing. After AT_INIT, user options can be entered here as
56 # cases of a case statement.
57 # - PARSE_ARGS_END
58 # Finish up the option processing.
59 #
60 # - HELP
61 # Start printing the help message.
62 # - HELP_MODES
63 # Modes help text. Additional modes can be appended as self-contained
64 # cat'd here-docs as generated by AS_HELP_STRING.
65 # - HELP_TUNING_BEGIN
66 # Tuning help text. This is for Autotest-provided text.
67 # - HELP_TUNING
68 # Additional tuning options' help text can be appended here as
69 # self-contained cat'd here-docs as generated by AS_HELP_STRING.
70 # - HELP_OTHER
71 # User help can be appended to this as self-contained cat'd here-docs.
72 # - HELP_END
73 # Finish up the help texts.
74 #
75 # - VERSION
76 # Head of the handling of --version.
77 # - VERSION_NOTICES
78 # Copyright notices for --version.
79 # - VERSION_END
80 # Tail of the handling of --version.
81 #
82 # - BANNERS
83 # Output shell initialization for the associative array of banner text.
84 # - TESTS_BEGIN
85 # Like DEFAULTS but run after argument processing for purposes of
86 # optimization. Do anything else that needs to be done to prepare for
87 # tests. Sets up verbose and log file descriptors. Sets and logs PATH.
88 # - PREPARE_TESTS
89 # Declares functions shared among the tests. Perform any user
90 # initialization to be shared among all tests.
91 # - TESTS
92 # The core of the test suite.
93 #
94 # - TEST_SCRIPT
95 # The collector for code for each test, the "normal" diversion, but
96 # undiverted into other locations before final output.
97 #
98 # - TEST_GROUPS
99 # Contents of each test group. The tests deliberately occur after the
100 # end of the shell script, so that the shell need not spend time parsing
101 # commands it will not execute.
102
103 m4_define([_m4_divert(DEFAULTS)], 100)
104 m4_define([_m4_divert(PARSE_ARGS_BEGIN)], 200)
105 m4_define([_m4_divert(PARSE_ARGS)], 201)
106 m4_define([_m4_divert(PARSE_ARGS_END)], 202)
107 m4_define([_m4_divert(HELP)], 300)
108 m4_define([_m4_divert(HELP_MODES)], 301)
109 m4_define([_m4_divert(HELP_TUNING_BEGIN)], 302)
110 m4_define([_m4_divert(HELP_TUNING)], 303)
111 m4_define([_m4_divert(HELP_OTHER)], 304)
112 m4_define([_m4_divert(HELP_END)], 305)
113 m4_define([_m4_divert(VERSION)], 350)
114 m4_define([_m4_divert(VERSION_NOTICES)], 351)
115 m4_define([_m4_divert(VERSION_END)], 352)
116 m4_define([_m4_divert(BANNERS)], 400)
117 m4_define([_m4_divert(TESTS_BEGIN)], 401)
118 m4_define([_m4_divert(PREPARE_TESTS)], 402)
119 m4_define([_m4_divert(TESTS)], 403)
120 m4_define([_m4_divert(TEST_SCRIPT)], 450)
121 m4_define([_m4_divert(TEST_GROUPS)], 500)
122
123
124 # AT_LINE
125 # -------
126 # Return the current file sans directory, a colon, and the current
127 # line. Be sure to return a _quoted_ file name, so if, for instance,
128 # the user is lunatic enough to have a file named 'dnl' (and I, for
129 # one, love to be brainless and stubborn sometimes), then we return a
130 # quoted name.
131 #
132 # Gee, we can't use simply
133 #
134 # m4_bpatsubst(__file__, [^.*/\(.*\)], [[\1]])
135 #
136 # since then, since 'dnl' doesn't match the pattern, it is returned
137 # with once quotation level less, so you lose! And since GNU M4
138 # is one of the biggest junk in the whole universe wrt regexp, don't
139 # even think about using '?' or '\?'. Bah, '*' will do.
140 # Pleeeeeeeease, Gary, provide us with dirname and ERE!
141 #
142 # M4 recompiles the regular expression for every m4_bpatsubst, but __file__
143 # rarely changes. Be fast - only compute the dirname when necessary; for
144 # autoconf alone, this shaves off several seconds in building testsuite.
145 m4_define([_AT_LINE_file])
146 m4_define([_AT_LINE_base])
147 m4_define([AT_LINE],
148 [m4_if(m4_defn([_AT_LINE_file]), __file__, [],
149 [m4_do([m4_define([_AT_LINE_file], __file__)],
150 [m4_define([_AT_LINE_base],
151 m4_bregexp(/__file__, [/\([^/]*\)$], [[\1]]))])])dnl
152 m4_defn([_AT_LINE_base]):__line__])
153
154 # _AT_LINE_ESCAPED
155 # ----------------
156 # Same as AT_LINE, but already escaped for the shell.
157 m4_define([_AT_LINE_ESCAPED], ["AS_ESCAPE(m4_dquote(AT_LINE))"])
158
159
160 # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR)
161 # ------------------------------------------
162 # Normalize SHELL-VAR so that its value has the same number of digits as
163 # all the other test group numbers.
164 m4_define([_AT_NORMALIZE_TEST_GROUP_NUMBER],
165 [
166 eval 'while :; do
167 case $$1 in #(
168 '"$at_format"'*) break;;
169 esac
170 $1=0$$1
171 done'
172 ])
173
174 # _AT_DEFINE_INIT(NAME, [DEFINITION])
175 # -----------------------------------
176 # Define macro NAME to die if invoked prior to AT_INIT, and to DEFINITION
177 # after AT_INIT.
178 m4_define([_AT_DEFINE_INIT],
179 [m4_define($@)m4_pushdef([$1], [m4_fatal([$1: missing AT_INIT detected])])dnl
180 m4_append([_AT_DEFINE_INIT_LIST], [[$1]], [,])])
181
182 # _AT_DEFINE_SETUP(NAME, [DEFINITION])
183 # ------------------------------------
184 # Define macro NAME to die if invoked outside AT_SETUP/AT_CLEANUP, and
185 # to DEFINITION otherwise.
186 m4_define([_AT_DEFINE_SETUP],
187 [m4_define([$1], [m4_ifndef([AT_ingroup],
188 [m4_fatal([$1: missing AT_SETUP detected])])$2])])
189
190 # AS_MESSAGE_LOG_FD
191 # -----------------
192 # File descriptor open on the log file. This needs to be defined
193 # unconditionally, so that AT_TESTS_PREPARE code can use it. Usage
194 # prior to the point where the log file is opened will crash the
195 # testsuite.
196 m4_define([AS_MESSAGE_LOG_FD], [5])
197
198 # AT_JOB_FIFO_{IN,OUT}_FD
199 # -----------------
200 # Used by the parallel test driver.
201 # The parent needs two fds to the same fifo, otherwise, there is a race
202 # where the parent can read the fifo before a child opens it for writing
203 _AT_DEFINE_INIT([AT_JOB_FIFO_IN_FD], [6])
204 _AT_DEFINE_INIT([AT_JOB_FIFO_OUT_FD], [7])
205
206 # AT_INIT([TESTSUITE-NAME])
207 # -------------------------
208 # Begin test suite.
209 m4_define([AT_INIT],
210 [m4_pushdef([AT_INIT], [m4_fatal([$0: invoked multiple times])])]
211 [m4_pattern_forbid([^_?AT_])]
212 [m4_pattern_allow([^_ATEOF$])]
213 [m4_ifndef([AT_PACKAGE_BUGREPORT], [m4_fatal(
214 [$1: AT_PACKAGE_BUGREPORT is missing, consider writing package.m4])])]
215 [m4_define([AT_TESTSUITE_NAME],
216 m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1],
217 [m4_expand([: $1])]))]
218 [m4_define([AT_ordinal], 0)]
219 [m4_define([AT_banner_ordinal], 0)]
220 [m4_define([AT_help_all], [])]
221 [m4_map_args([_m4_popdef], _AT_DEFINE_INIT_LIST)]
222 [m4_wrap([_AT_FINISH])]
223 [AS_INIT[]]dnl
224 dnl We don't use m4sh's BODY diversion, but AS_INIT sticks a banner there.
225 dnl This trick removes that banner, since it adds nothing to autotest.
226 [m4_cleardivert([BODY])]dnl
227 [AS_ME_PREPARE[]]dnl
228 [m4_divert_push([DEFAULTS])]dnl
229 [AT_COPYRIGHT(m4_defn([_AT_COPYRIGHT_YEARS]), [
230 m4_copyright_condense])]
231 [AT_COPYRIGHT(
232 [This test suite is free software; the Free Software Foundation gives
233 unlimited permission to copy, distribute and modify it.], [m4_echo])]
234 [AS_PREPARE
235
236 SHELL=${CONFIG_SHELL-/bin/sh}
237
238 # How were we run?
239 at_cli_args="$[@]"
240
241 m4_divert_push([BANNERS])dnl
242
243 # Should we print banners? Yes if more than one test is run.
244 case $at_groups in #(
245 *$as_nl* )
246 at_print_banners=: ;; #(
247 * ) at_print_banners=false ;;
248 esac
249 # Text for banner N, set to a single space once printed.
250 m4_divert_pop([BANNERS])dnl back to DEFAULTS
251 m4_divert_push([PREPARE_TESTS])dnl
252
253 m4_text_box([Autotest shell functions.])
254
255 AS_FUNCTION_DESCRIBE([at_fn_banner], [NUMBER],
256 [Output banner NUMBER, provided the testsuite is running multiple groups
257 and this particular banner has not yet been printed.])
258 at_fn_banner ()
259 {
260 $at_print_banners || return 0
261 eval at_banner_text=\$at_banner_text_$[1]
262 test "x$at_banner_text" = "x " && return 0
263 eval "at_banner_text_$[1]=\" \""
264 if test -z "$at_banner_text"; then
265 $at_first || echo
266 else
267 AS_ECHO(["$as_nl$at_banner_text$as_nl"])
268 fi
269 } # at_fn_banner
270
271 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_notrace], [REASON LINE],
272 [Perform AT_CHECK preparations for the command at LINE for an
273 untraceable command; REASON is the reason for disabling tracing.])
274 at_fn_check_prepare_notrace ()
275 {
276 $at_trace_echo "Not enabling shell tracing (command contains $[1])"
277 AS_ECHO(["$[2]"]) >"$at_check_line_file"
278 at_check_trace=: at_check_filter=:
279 : >"$at_stdout"; : >"$at_stderr"
280 }
281
282 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_trace], [LINE],
283 [Perform AT_CHECK preparations for the command at LINE for a traceable
284 command.])
285 at_fn_check_prepare_trace ()
286 {
287 AS_ECHO(["$[1]"]) >"$at_check_line_file"
288 at_check_trace=$at_traceon at_check_filter=$at_check_filter_trace
289 : >"$at_stdout"; : >"$at_stderr"
290 }
291
292 AS_FUNCTION_DESCRIBE([at_fn_check_prepare_dynamic], [COMMAND LINE],
293 [Decide if COMMAND at LINE is traceable at runtime, and call the
294 appropriate preparation function.])
295 at_fn_check_prepare_dynamic ()
296 {
297 case $[1] in
298 *$as_nl*)
299 at_fn_check_prepare_notrace 'an embedded newline' "$[2]" ;;
300 *)
301 at_fn_check_prepare_trace "$[2]" ;;
302 esac
303 }
304
305 AS_FUNCTION_DESCRIBE([at_fn_filter_trace], [],
306 [Remove the lines in the file "$at_stderr" generated by "set -x" and print
307 them to stderr.])
308 at_fn_filter_trace ()
309 {
310 mv "$at_stderr" "$at_stder1"
311 grep '^ *+' "$at_stder1" >&2
312 grep -v '^ *+' "$at_stder1" >"$at_stderr"
313 }
314
315 AS_FUNCTION_DESCRIBE([at_fn_log_failure], [FILE-LIST],
316 [Copy the files in the list on stdout with a "> " prefix, and exit the shell
317 with a failure exit code.])
318 at_fn_log_failure ()
319 {
320 for file
321 do AS_ECHO(["$file:"]); sed 's/^/> /' "$file"; done
322 echo 1 > "$at_status_file"
323 exit 1
324 }
325
326 AS_FUNCTION_DESCRIBE([at_fn_check_skip], [EXIT-CODE LINE],
327 [Check whether EXIT-CODE is a special exit code (77 or 99), and if so exit
328 the test group subshell with that same exit code. Use LINE in any report
329 about test failure.])
330 at_fn_check_skip ()
331 {
332 case $[1] in
333 99) echo 99 > "$at_status_file"; at_failed=:
334 AS_ECHO(["$[2]: hard failure"]); exit 99;;
335 77) echo 77 > "$at_status_file"; exit 77;;
336 esac
337 }
338
339 AS_FUNCTION_DESCRIBE([at_fn_check_status], [EXPECTED EXIT-CODE LINE],
340 [Check whether EXIT-CODE is the EXPECTED exit code, and if so do nothing.
341 Otherwise, if it is 77 or 99, exit the test group subshell with that same
342 exit code; if it is anything else print an error message referring to LINE,
343 and fail the test.])
344 at_fn_check_status ()
345 {
346 dnl This order ensures that we don't 'skip' if we are precisely checking
347 dnl $? = 77 or $? = 99.
348 case $[2] in
349 $[1] ) ;;
350 77) echo 77 > "$at_status_file"; exit 77;;
351 99) echo 99 > "$at_status_file"; at_failed=:
352 AS_ECHO(["$[3]: hard failure"]); exit 99;;
353 *) AS_ECHO(["$[3]: exit code was $[2], expected $[1]"])
354 at_failed=:;;
355 esac
356 }
357
358 AS_FUNCTION_DESCRIBE([at_fn_diff_devnull], [FILE],
359 [Emit a diff between /dev/null and FILE. Uses "test -s" to avoid useless
360 diff invocations.])
361 at_fn_diff_devnull ()
362 {
363 test -s "$[1]" || return 0
364 $at_diff "$at_devnull" "$[1]"
365 }
366
367 AS_FUNCTION_DESCRIBE([at_fn_test], [NUMBER],
368 [Parse out test NUMBER from the tail of this file.])
369 at_fn_test ()
370 {
371 eval at_sed=\$at_sed$[1]
372 sed "$at_sed" "$at_myself" > "$at_test_source"
373 }
374
375 AS_FUNCTION_DESCRIBE([at_fn_create_debugging_script], [],
376 [Create the debugging script $at_group_dir/run which will reproduce the
377 current test group.])
378 at_fn_create_debugging_script ()
379 {
380 {
381 echo "#! /bin/sh" &&
382 AS_ECHO(["cd '$at_dir'"]) &&
383 AS_ECHO(['case $[#] in']) &&
384 AS_ECHO([" 0) exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
385 [$at_debug_args $at_group ;;"]) &&
386 AS_ECHO([" *) exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
387 [$at_debug_args $at_group \"\$[@]\" ;;"]) &&
388 AS_ECHO([esac]) &&
389 echo 'exit 1'
390 } >"$at_group_dir/run" &&
391 chmod +x "$at_group_dir/run"
392 }
393
394 m4_text_box([End of autotest shell functions.])
395 m4_divert_pop([PREPARE_TESTS])dnl back to DEFAULTS
396
397 # Not all shells have the 'times' builtin; the subshell is needed to make
398 # sure we discard the 'times: not found' message from the shell.
399 at_times_p=false
400 (times) >/dev/null 2>&1 && at_times_p=:
401
402 # CLI Arguments to pass to the debugging scripts.
403 at_debug_args=
404 # -e sets to true
405 at_errexit_p=false
406 # Shall we be verbose? ':' means no, empty means yes.
407 at_verbose=:
408 at_quiet=
409 # Running several jobs in parallel, 0 means as many as test groups.
410 at_jobs=1
411 at_traceon=:
412 at_trace_echo=:
413 at_check_filter_trace=:
414
415 # Shall we keep the debug scripts? Must be ':' when the suite is
416 # run by a debug script, so that the script doesn't remove itself.
417 at_debug_p=false
418 # Display help message?
419 at_help_p=false
420 # Display the version message?
421 at_version_p=false
422 # List test groups?
423 at_list_p=false
424 # --clean
425 at_clean=false
426 # Test groups to run
427 at_groups=
428 # Whether to rerun failed tests.
429 at_recheck=
430 # Whether a write failure occurred
431 at_write_fail=0
432
433 # The directory we run the suite in. Default to . if no -C option.
434 at_dir=`pwd`
435 # An absolute reference to this testsuite script.
436 dnl m4-double quote, to preserve []
437 [case $as_myself in
438 [\\/]* | ?:[\\/]* ) at_myself=$as_myself ;;
439 * ) at_myself=$at_dir/$as_myself ;;
440 esac]
441 # Whether -C is in effect.
442 at_change_dir=false
443 m4_divert_pop([DEFAULTS])dnl
444 m4_define([_AT_FINISH],
445 [m4_ifdef([AT_ingroup], [m4_fatal([missing AT_CLEANUP detected])])dnl
446 m4_divert_text([DEFAULTS],
447 [
448 # Whether to enable colored test results.
449 at_color=m4_ifdef([AT_color], [AT_color], [no])
450 # As many question marks as there are digits in the last test group number.
451 # Used to normalize the test group numbers so that 'ls' lists them in
452 # numerical order.
453 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
454 # Description of all the test groups.
455 at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"
456 # List of the all the test groups.
457 at_groups_all=`AS_ECHO(["$at_help_all"]) | sed 's/;.*//'`
458
459 AS_FUNCTION_DESCRIBE([at_fn_validate_ranges], [NAME...],
460 [Validate and normalize the test group number contained in each
461 variable NAME. Leading zeroes are treated as decimal.])
462 at_fn_validate_ranges ()
463 {
464 for at_grp
465 do
466 eval at_value=\$$at_grp
467 if test $at_value -lt 1 || test $at_value -gt AT_ordinal; then
468 AS_ECHO(["invalid test group: $at_value"]) >&2
469 exit 1
470 fi
471 case $at_value in
472 0*) # We want to treat leading 0 as decimal, like expr and test, but
473 # AS_VAR_ARITH treats it as octal if it uses $(( )).
474 # With XSI shells, ${at_value#${at_value%%[1-9]*}} avoids the
475 # expr fork, but it is not worth the effort to determine if the
476 # shell supports XSI when the user can just avoid leading 0.
477 eval $at_grp='`expr $at_value + 0`' ;;
478 esac
479 done
480 }])])dnl
481 m4_divert_push([PARSE_ARGS])dnl
482
483 at_prev=
484 for at_option
485 do
486 # If the previous option needs an argument, assign it.
487 if test -n "$at_prev"; then
488 at_option=$at_prev=$at_option
489 at_prev=
490 fi
491
492 case $at_option in
493 *=?*) at_optarg=`expr "X$at_option" : '[[^=]]*=\(.*\)'` ;;
494 *) at_optarg= ;;
495 esac
496
497 case $at_option in
498 --help | -h )
499 at_help_p=:
500 ;;
501
502 --list | -l )
503 at_list_p=:
504 ;;
505
506 --version | -V )
507 at_version_p=:
508 ;;
509
510 --clean | -c )
511 at_clean=:
512 ;;
513
514 --color )
515 at_color=always
516 ;;
517 --color=* )
518 case $at_optarg in
519 no | never | none) at_color=never ;;
520 auto | tty | if-tty) at_color=auto ;;
521 always | yes | force) at_color=always ;;
522 *) at_optname=`AS_ECHO([" $at_option"]) | sed 's/^ //; s/=.*//'`
523 AS_ERROR([unrecognized argument to $at_optname: $at_optarg]) ;;
524 esac
525 ;;
526
527 --debug | -d )
528 at_debug_p=:
529 ;;
530
531 --errexit | -e )
532 at_debug_p=:
533 at_errexit_p=:
534 ;;
535
536 --verbose | -v )
537 at_verbose=; at_quiet=:
538 ;;
539
540 --trace | -x )
541 at_traceon='set -x'
542 at_trace_echo=echo
543 at_check_filter_trace=at_fn_filter_trace
544 ;;
545
546 [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
547 at_fn_validate_ranges at_option
548 AS_VAR_APPEND([at_groups], ["$at_option$as_nl"])
549 ;;
550
551 # Ranges
552 [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
553 at_range_start=`echo $at_option |tr -d X-`
554 at_fn_validate_ranges at_range_start
555 at_range=`AS_ECHO(["$at_groups_all"]) | \
556 sed -ne '/^'$at_range_start'$/,$p'`
557 AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
558 ;;
559
560 [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
561 at_range_end=`echo $at_option |tr -d X-`
562 at_fn_validate_ranges at_range_end
563 at_range=`AS_ECHO(["$at_groups_all"]) | \
564 sed -ne '1,/^'$at_range_end'$/p'`
565 AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
566 ;;
567
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]] | \
570 [[0-9][0-9]-[0-9][0-9][0-9] | [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]] | \
572 [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
573 [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
574 at_range_start=`expr $at_option : '\(.*\)-'`
575 at_range_end=`expr $at_option : '.*-\(.*\)'`
576 if test $at_range_start -gt $at_range_end; then
577 at_tmp=$at_range_end
578 at_range_end=$at_range_start
579 at_range_start=$at_tmp
580 fi
581 at_fn_validate_ranges at_range_start at_range_end
582 at_range=`AS_ECHO(["$at_groups_all"]) | \
583 sed -ne '/^'$at_range_start'$/,/^'$at_range_end'$/p'`
584 AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
585 ;;
586
587 # Directory selection.
588 --directory | -C )
589 at_prev=--directory
590 ;;
591 --directory=* )
592 at_change_dir=:
593 at_dir=$at_optarg
594 if test x- = "x$at_dir" ; then
595 at_dir=./-
596 fi
597 ;;
598
599 # Parallel execution.
600 --jobs | -j )
601 at_jobs=0
602 ;;
603 --jobs=* | -j[[0-9]]* )
604 if test -n "$at_optarg"; then
605 at_jobs=$at_optarg
606 else
607 at_jobs=`expr X$at_option : 'X-j\(.*\)'`
608 fi
609 case $at_jobs in *[[!0-9]]*)
610 at_optname=`AS_ECHO([" $at_option"]) | sed 's/^ //; s/[[0-9=]].*//'`
611 AS_ERROR([non-numeric argument to $at_optname: $at_jobs]) ;;
612 esac
613 ;;
614
615 # Keywords.
616 --keywords | -k )
617 at_prev=--keywords
618 ;;
619 --keywords=* )
620 at_groups_selected=$at_help_all
621 at_save_IFS=$IFS
622 IFS=,
623 set X $at_optarg
624 shift
625 IFS=$at_save_IFS
626 for at_keyword
627 do
628 at_invert=
629 case $at_keyword in
630 '!'*)
631 at_invert="-v"
632 at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
633 ;;
634 esac
635 # It is on purpose that we match the test group titles too.
636 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
637 grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
638 done
639 # Smash the keywords.
640 at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//'`
641 AS_VAR_APPEND([at_groups], ["$at_groups_selected$as_nl"])
642 ;;
643 --recheck)
644 at_recheck=:
645 ;;
646 m4_divert_pop([PARSE_ARGS])dnl
647 dnl Process *=* last to allow for user specified --option=* type arguments.
648 m4_divert_push([PARSE_ARGS_END])dnl
649
650 *=*)
651 at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
652 # Reject names that are not valid shell variable names.
653 case $at_envvar in
654 '' | [[0-9]]* | *[[!_$as_cr_alnum]]* )
655 AS_ERROR([invalid variable name: '$at_envvar']) ;;
656 esac
657 at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
658 # Export now, but save eval for later and for debug scripts.
659 export $at_envvar
660 AS_VAR_APPEND([at_debug_args], [" $at_envvar='$at_value'"])
661 ;;
662
663 *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
664 AS_ECHO(["Try '$[0] --help' for more information."]) >&2
665 exit 1
666 ;;
667 esac
668 done
669
670 # Verify our last option didn't require an argument
671 AS_IF([test -n "$at_prev"], [AS_ERROR(['$at_prev' requires an argument])])
672
673 # The file containing the suite.
674 at_suite_log=$at_dir/$as_me.log
675
676 # Selected test groups.
677 if test -z "$at_groups$at_recheck"; then
678 at_groups=$at_groups_all
679 else
680 if test -n "$at_recheck" && test -r "$at_suite_log"; then
681 at_oldfails=`sed -n ['
682 /^Failed tests:$/,/^Skipped tests:$/{
683 s/^[ ]*\([1-9][0-9]*\):.*/\1/p
684 }
685 /^Unexpected passes:$/,/^## Detailed failed tests/{
686 s/^[ ]*\([1-9][0-9]*\):.*/\1/p
687 }
688 /^## Detailed failed tests/q
689 '] "$at_suite_log"`
690 AS_VAR_APPEND([at_groups], ["$at_oldfails$as_nl"])
691 fi
692 # Sort the tests, removing duplicates.
693 at_groups=`AS_ECHO(["$at_groups"]) | sort -nu | sed '/^$/d'`
694 fi
695
696 if test x"$at_color" = xalways \
697 || { test x"$at_color" = xauto && test -t 1; }; then
698 at_red=`printf '\033@<:@0;31m'`
699 at_grn=`printf '\033@<:@0;32m'`
700 at_lgn=`printf '\033@<:@1;32m'`
701 at_blu=`printf '\033@<:@1;34m'`
702 at_std=`printf '\033@<:@m'`
703 else
704 at_red= at_grn= at_lgn= at_blu= at_std=
705 fi
706 m4_divert_pop([PARSE_ARGS_END])dnl
707 m4_divert_push([HELP])dnl
708
709 # Help message.
710 if $at_help_p; then
711 cat <<_ATEOF || at_write_fail=1
712 Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
713
714 Run all the tests, or the selected TESTS, given by numeric ranges, and
715 save a detailed log file. Upon failure, create debugging scripts.
716
717 Do not change environment variables directly. Instead, set them via
718 command line arguments. Set 'AUTOTEST_PATH' to select the executables
719 to exercise. Each relative directory is expanded as build and source
720 directories relative to the top level of this distribution.
721 E.g., from within the build directory /tmp/foo-1.0, invoking this:
722
723 $ $[0] AUTOTEST_PATH=bin
724
725 is equivalent to the following, assuming the source directory is /src/foo-1.0:
726
727 PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH $[0]
728 _ATEOF
729 m4_divert_pop([HELP])dnl
730 m4_divert_push([HELP_MODES])dnl
731 cat <<_ATEOF || at_write_fail=1
732
733 Operation modes:
734 -h, --help print the help message, then exit
735 -V, --version print version number, then exit
736 -c, --clean remove all the files this test suite might create and exit
737 -l, --list describes all the tests, or the selected TESTS
738 _ATEOF
739 m4_divert_pop([HELP_MODES])dnl
740 m4_wrap([m4_divert_push([HELP_TUNING_BEGIN])dnl
741 cat <<_ATEOF || at_write_fail=1
742
743 dnl extra quoting prevents emacs whitespace mode from putting tabs in output
744 Execution tuning:
745 -C, --directory=DIR
746 [ change to directory DIR before starting]
747 --color[[=never|auto|always]]
748 [ ]m4_ifdef([AT_color],
749 [disable colored test results, or enable even without terminal],
750 [enable colored test results on terminal, or always])
751 -j, --jobs[[=N]]
752 [ Allow N jobs at once; infinite jobs with no arg (default 1)]
753 -k, --keywords=KEYWORDS
754 [ select the tests matching all the comma-separated KEYWORDS]
755 [ multiple '-k' accumulate; prefixed '!' negates a KEYWORD]
756 --recheck select all tests that failed or passed unexpectedly last time
757 -e, --errexit abort as soon as a test fails; implies --debug
758 -v, --verbose force more detailed output
759 [ default for debugging scripts]
760 -d, --debug inhibit clean up and top-level logging
761 [ default for debugging scripts]
762 -x, --trace enable tests shell tracing
763 _ATEOF
764 m4_divert_pop([HELP_TUNING_BEGIN])])dnl
765 m4_divert_push([HELP_END])dnl
766 cat <<_ATEOF || at_write_fail=1
767
768 Report bugs to <AT_PACKAGE_BUGREPORT>.dnl
769 m4_ifdef([AT_PACKAGE_NAME],
770 [m4_ifset([AT_PACKAGE_URL], [
771 m4_defn([AT_PACKAGE_NAME]) home page: <AT_PACKAGE_URL>.])dnl
772 m4_if(m4_index(m4_defn([AT_PACKAGE_NAME]), [GNU ]), [0], [
773 General help using GNU software: <https://www.gnu.org/gethelp/>.])])
774 _ATEOF
775 exit $at_write_fail
776 fi
777
778 # List of tests.
779 if $at_list_p; then
780 cat <<_ATEOF || at_write_fail=1
781 AT_TESTSUITE_NAME test groups:
782
783 NUM: FILE-NAME:LINE TEST-GROUP-NAME
784 KEYWORDS
785
786 _ATEOF
787 # Pass an empty line as separator between selected groups and help.
788 AS_ECHO(["$at_groups$as_nl$as_nl$at_help_all"]) |
789 awk 'NF == 1 && FS != ";" {
790 selected[[$ 1]] = 1
791 next
792 }
793 /^$/ { FS = ";" }
794 NF > 0 {
795 if (selected[[$ 1]]) {
796 printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
797 if ($ 4) {
798 lmax = 79
799 indent = " "
800 line = indent
801 len = length (line)
802 n = split ($ 4, a, " ")
803 for (i = 1; i <= n; i++) {
804 l = length (a[[i]]) + 1
805 if (i > 1 && len + l > lmax) {
806 print line
807 line = indent " " a[[i]]
808 len = length (line)
809 } else {
810 line = line " " a[[i]]
811 len += l
812 }
813 }
814 if (n)
815 print line
816 }
817 }
818 }' || at_write_fail=1
819 exit $at_write_fail
820 fi
821 m4_divert_pop([HELP_END])dnl
822 m4_divert_push([VERSION])dnl
823 if $at_version_p; then
824 AS_ECHO(["$as_me (AT_PACKAGE_STRING)"]) &&
825 cat <<\_ATEOF || at_write_fail=1
826 m4_divert_pop([VERSION])dnl
827 m4_divert_push([VERSION_END])dnl
828 _ATEOF
829 exit $at_write_fail
830 fi
831 m4_divert_pop([VERSION_END])dnl
832 m4_divert_push([TESTS_BEGIN])dnl
833
834 # Take any -C into account.
835 if $at_change_dir ; then
836 test x != "x$at_dir" && cd "$at_dir" \
837 || AS_ERROR([unable to change directory])
838 at_dir=`pwd`
839 fi
840
841 # Load the config files for any default variable assignments.
842 for at_file in atconfig atlocal
843 do
844 test -r $at_file || continue
845 . ./$at_file || AS_ERROR([invalid content: $at_file])
846 done
847
848 # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
849 : "${at_top_build_prefix=$at_top_builddir}"
850
851 # Perform any assignments requested during argument parsing.
852 eval "$at_debug_args"
853
854 # atconfig delivers names relative to the directory the test suite is
855 # in, but the groups themselves are run in testsuite-dir/group-dir.
856 if test -n "$at_top_srcdir"; then
857 builddir=../..
858 for at_dir_var in srcdir top_srcdir top_build_prefix
859 do
860 AS_VAR_COPY([at_val], [at_$at_dir_var])
861 case $at_val in
862 [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
863 *) at_prefix=../../ ;;
864 esac
865 AS_VAR_SET([$at_dir_var], [$at_prefix$at_val])
866 done
867 fi
868
869 m4_text_box([Directory structure.])
870
871 # This is the set of directories and files used by this script
872 # (non-literals are capitalized):
873 #
874 # TESTSUITE - the testsuite
875 # TESTSUITE.log - summarizes the complete testsuite run
876 # TESTSUITE.dir/ - created during a run, remains after -d or failed test
877 # + at-groups/ - during a run: status of all groups in run
878 # | + NNN/ - during a run: meta-data about test group NNN
879 # | | + check-line - location (source file and line) of current AT_CHECK
880 # | | + status - exit status of current AT_CHECK
881 # | | + stdout - stdout of current AT_CHECK
882 # | | + stder1 - stderr, including trace
883 # | | + stderr - stderr, with trace filtered out
884 # | | + test-source - portion of testsuite that defines group
885 # | | + times - timestamps for computing duration
886 # | | + pass - created if group passed
887 # | | + xpass - created if group xpassed
888 # | | + fail - created if group failed
889 # | | + xfail - created if group xfailed
890 # | | + skip - created if group skipped
891 # + at-stop - during a run: end the run if this file exists
892 # + at-source-lines - during a run: cache of TESTSUITE line numbers for extraction
893 # + 0..NNN/ - created for each group NNN, remains after -d or failed test
894 # | + TESTSUITE.log - summarizes the group results
895 # | + ... - files created during the group
896
897 # The directory the whole suite works in.
898 # Should be absolute to let the user 'cd' at will.
899 at_suite_dir=$at_dir/$as_me.dir
900 # The file containing the suite ($at_dir might have changed since earlier).
901 at_suite_log=$at_dir/$as_me.log
902 # The directory containing helper files per test group.
903 at_helper_dir=$at_suite_dir/at-groups
904 # Stop file: if it exists, do not start new jobs.
905 at_stop_file=$at_suite_dir/at-stop
906 # The fifo used for the job dispatcher.
907 at_job_fifo=$at_suite_dir/at-job-fifo
908
909 if $at_clean; then
910 test -d "$at_suite_dir" &&
911 find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
912 rm -f -r "$at_suite_dir" "$at_suite_log"
913 exit $?
914 fi
915
916 # Don't take risks: use only absolute directories in PATH.
917 #
918 # For stand-alone test suites (ie. atconfig was not found),
919 # AUTOTEST_PATH is relative to '.'.
920 #
921 # For embedded test suites, AUTOTEST_PATH is relative to the top level
922 # of the package. Then expand it into build/src parts, since users
923 # may create executables in both places.
924 AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s|:|$PATH_SEPARATOR|g"`
925 at_path=
926 _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
927 [test -n "$at_path" && AS_VAR_APPEND([at_path], [$PATH_SEPARATOR])
928 case $as_dir in
929 [[\\/]]* | ?:[[\\/]]* )
930 AS_VAR_APPEND([at_path], ["$as_dir"])
931 ;;
932 * )
933 if test -z "$at_top_build_prefix"; then
934 # Stand-alone test suite.
935 AS_VAR_APPEND([at_path], ["$as_dir"])
936 else
937 # Embedded test suite.
938 AS_VAR_APPEND([at_path], ["$at_top_build_prefix$as_dir$PATH_SEPARATOR"])
939 AS_VAR_APPEND([at_path], ["$at_top_srcdir/$as_dir"])
940 fi
941 ;;
942 esac])
943
944 # Now build and simplify PATH.
945 #
946 # There might be directories that don't exist, but don't redirect
947 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
948 at_new_path=
949 _AS_PATH_WALK([$at_path],
950 [test -d "$as_dir" || continue
951 case $as_dir in
952 [[\\/]]* | ?:[[\\/]]* ) ;;
953 * ) as_dir=`(cd "$as_dir" && pwd) 2>/dev/null` ;;
954 esac
955 case $PATH_SEPARATOR$at_new_path$PATH_SEPARATOR in
956 *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR*) ;;
957 $PATH_SEPARATOR$PATH_SEPARATOR) at_new_path=$as_dir ;;
958 *) AS_VAR_APPEND([at_new_path], ["$PATH_SEPARATOR$as_dir"]) ;;
959 esac])
960 PATH=$at_new_path
961 export PATH
962
963 # Setting up the FDs.
964 [#] AS_MESSAGE_LOG_FD is the log file. Not to be overwritten if '-d'.
965 if $at_debug_p; then
966 at_suite_log=/dev/null
967 else
968 : >"$at_suite_log"
969 fi
970 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
971
972 # Banners and logs.
973 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
974 {
975 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
976 echo
977
978 AS_ECHO(["$as_me: command line was:"])
979 AS_ECHO([" \$ $[0] $at_cli_args"])
980 echo
981
982 # If ChangeLog exists, list a few lines in case it might help determining
983 # the exact version.
984 if test -n "$at_top_srcdir" && test -f "$at_top_srcdir/ChangeLog"; then
985 AS_BOX([ChangeLog.])
986 echo
987 sed 's/^/| /;10q' "$at_top_srcdir/ChangeLog"
988 echo
989 fi
990
991 AS_UNAME
992 echo
993
994 # Contents of the config files.
995 for at_file in atconfig atlocal
996 do
997 test -r $at_file || continue
998 AS_ECHO(["$as_me: $at_file:"])
999 sed 's/^/| /' $at_file
1000 echo
1001 done
1002 } >&AS_MESSAGE_LOG_FD
1003
1004 m4_divert_pop([TESTS_BEGIN])dnl
1005 m4_divert_push([TESTS])dnl
1006 {
1007 AS_BOX([Running the tests.])
1008 } >&AS_MESSAGE_LOG_FD
1009
1010 at_start_date=`date`
1011 at_start_time=`date +%s 2>/dev/null`
1012 AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
1013
1014 # Create the master directory if it doesn't already exist.
1015 AS_MKDIR_P(["$at_suite_dir"]) ||
1016 AS_ERROR([cannot create '$at_suite_dir'])
1017
1018 # Can we diff with '/dev/null'? DU 5.0 refuses.
1019 if diff /dev/null /dev/null >/dev/null 2>&1; then
1020 at_devnull=/dev/null
1021 else
1022 at_devnull=$at_suite_dir/devnull
1023 >"$at_devnull"
1024 fi
1025
1026 # Use 'diff -u' when possible.
1027 if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
1028 then
1029 at_diff='diff -u'
1030 else
1031 at_diff=diff
1032 fi
1033
1034 # Get the last needed group.
1035 for at_group in : $at_groups; do :; done
1036
1037 # Extract the start and end lines of each test group at the tail
1038 # of this file
1039 awk '
1040 BEGIN { FS="" }
1041 /^@%:@AT_START_/ {
1042 start = NR
1043 }
1044 /^@%:@AT_STOP_/ {
1045 test = substr ($ 0, 10)
1046 print "at_sed" test "=\"1," start "d;" (NR-1) "q\""
1047 if (test == "'"$at_group"'") exit
1048 }' "$at_myself" > "$at_suite_dir/at-source-lines" &&
1049 . "$at_suite_dir/at-source-lines" ||
1050 AS_ERROR([cannot create test line number cache])
1051 rm -f "$at_suite_dir/at-source-lines"
1052
1053 # Set number of jobs for '-j'; avoid more jobs than test groups.
1054 set X $at_groups; shift; at_max_jobs=$[@%:@]
1055 if test $at_max_jobs -eq 0; then
1056 at_jobs=1
1057 fi
1058 if test $at_jobs -ne 1 &&
1059 { test $at_jobs -eq 0 || test $at_jobs -gt $at_max_jobs; }; then
1060 at_jobs=$at_max_jobs
1061 fi
1062
1063 # If parallel mode, don't output banners, don't split summary lines.
1064 if test $at_jobs -ne 1; then
1065 at_print_banners=false
1066 at_quiet=:
1067 fi
1068
1069 # Set up helper dirs.
1070 rm -rf "$at_helper_dir" &&
1071 mkdir "$at_helper_dir" &&
1072 cd "$at_helper_dir" &&
1073 { test -z "$at_groups" || mkdir $at_groups; } ||
1074 AS_ERROR([testsuite directory setup failed])
1075
1076 # Functions for running a test group. We leave the actual
1077 # test group execution outside of a shell function in order
1078 # to avoid hitting zsh 4.x exit status bugs.
1079
1080 AS_FUNCTION_DESCRIBE([at_fn_group_prepare], [],
1081 [Prepare for running a test group.])
1082 at_fn_group_prepare ()
1083 {
1084 # The directory for additional per-group helper files.
1085 at_job_dir=$at_helper_dir/$at_group
1086 # The file containing the location of the last AT_CHECK.
1087 at_check_line_file=$at_job_dir/check-line
1088 # The file containing the exit status of the last command.
1089 at_status_file=$at_job_dir/status
1090 # The files containing the output of the tested commands.
1091 at_stdout=$at_job_dir/stdout
1092 at_stder1=$at_job_dir/stder1
1093 at_stderr=$at_job_dir/stderr
1094 # The file containing the code for a test group.
1095 at_test_source=$at_job_dir/test-source
1096 # The file containing dates.
1097 at_times_file=$at_job_dir/times
1098
1099 # Be sure to come back to the top test directory.
1100 cd "$at_suite_dir"
1101
1102 # Clearly separate the test groups when verbose.
1103 $at_first || $at_verbose echo
1104
1105 at_group_normalized=$at_group
1106 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1107
1108 # Create a fresh directory for the next test group, and enter.
1109 # If one already exists, the user may have invoked ./run from
1110 # within that directory; we remove the contents, but not the
1111 # directory itself, so that we aren't pulling the rug out from
1112 # under the shell's notion of the current directory.
1113 at_group_dir=$at_suite_dir/$at_group_normalized
1114 at_group_log=$at_group_dir/$as_me.log
1115 _AS_CLEAN_DIR("$at_group_dir") ||
1116 AS_WARN([test directory for $at_group_normalized could not be cleaned])
1117 # Be tolerant if the above 'rm' was not able to remove the directory.
1118 AS_MKDIR_P(["$at_group_dir"])
1119
1120 echo 0 > "$at_status_file"
1121
1122 # In verbose mode, append to the log file *and* show on
1123 # the standard output; in quiet mode only write to the log.
1124 if test -z "$at_verbose"; then
1125 at_tee_pipe='tee -a "$at_group_log"'
1126 else
1127 at_tee_pipe='cat >> "$at_group_log"'
1128 fi
1129 }
1130
1131 AS_FUNCTION_DESCRIBE([at_fn_group_banner], [[ORDINAL LINE DESC PAD [BANNER]]],
1132 [Declare the test group ORDINAL, located at LINE with group description
1133 DESC, and residing under BANNER. Use PAD to align the status column.])
1134 at_fn_group_banner ()
1135 {
1136 at_setup_line="$[2]"
1137 test -n "$[5]" && at_fn_banner $[5]
1138 at_desc="$[3]"
1139 case $[1] in
1140 [[0-9]]) at_desc_line=" $[1]: ";;
1141 [[0-9][0-9]]) at_desc_line=" $[1]: " ;;
1142 [*]) at_desc_line="$[1]: " ;;
1143 esac
1144 AS_VAR_APPEND([at_desc_line], ["$[3]$[4]"])
1145 $at_quiet AS_ECHO_N(["$at_desc_line"])
1146 echo "# -*- compilation -*-" >> "$at_group_log"
1147 }
1148
1149 AS_FUNCTION_DESCRIBE([at_fn_group_postprocess], [],
1150 [Perform cleanup after running a test group.])
1151 at_fn_group_postprocess ()
1152 {
1153 # Be sure to come back to the suite directory, in particular
1154 # since below we might 'rm' the group directory we are in currently.
1155 cd "$at_suite_dir"
1156
1157 if test ! -f "$at_check_line_file"; then
1158 sed "s/^ */$as_me: WARNING: /" <<_ATEOF
1159 A failure happened in a test group before any test could be
1160 run. This means that test suite is improperly designed. Please
1161 report this failure to <AT_PACKAGE_BUGREPORT>.
1162 _ATEOF
1163 AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
1164 at_status=99
1165 fi
1166 $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
1167 AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
1168 case $at_xfail:$at_status in
1169 yes:0)
1170 at_msg="UNEXPECTED PASS"
1171 at_res=xpass
1172 at_errexit=$at_errexit_p
1173 at_color=$at_red
1174 ;;
1175 no:0)
1176 at_msg="ok"
1177 at_res=pass
1178 at_errexit=false
1179 at_color=$at_grn
1180 ;;
1181 *:77)
1182 at_msg='skipped ('`cat "$at_check_line_file"`')'
1183 at_res=skip
1184 at_errexit=false
1185 at_color=$at_blu
1186 ;;
1187 no:* | *:99)
1188 at_msg='FAILED ('`cat "$at_check_line_file"`')'
1189 at_res=fail
1190 at_errexit=$at_errexit_p
1191 at_color=$at_red
1192 ;;
1193 yes:*)
1194 at_msg='expected failure ('`cat "$at_check_line_file"`')'
1195 at_res=xfail
1196 at_errexit=false
1197 at_color=$at_lgn
1198 ;;
1199 esac
1200 echo "$at_res" > "$at_job_dir/$at_res"
1201 # In parallel mode, output the summary line only afterwards.
1202 if test $at_jobs -ne 1 && test -n "$at_verbose"; then
1203 AS_ECHO(["$at_desc_line $at_color$at_msg$at_std"])
1204 else
1205 # Make sure there is a separator even with long titles.
1206 AS_ECHO([" $at_color$at_msg$at_std"])
1207 fi
1208 at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
1209 case $at_status in
1210 0|77)
1211 # $at_times_file is only available if the group succeeded.
1212 # We're not including the group log, so the success message
1213 # is written in the global log separately. But we also
1214 # write to the group log in case they're using -d.
1215 if test -f "$at_times_file"; then
1216 at_log_msg="$at_log_msg ("`sed 1d "$at_times_file"`')'
1217 rm -f "$at_times_file"
1218 fi
1219 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
1220 AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
1221
1222 # Cleanup the group directory, unless the user wants the files
1223 # or the success was unexpected.
1224 if $at_debug_p || test $at_res = xpass; then
1225 at_fn_create_debugging_script
1226 if test $at_res = xpass && $at_errexit; then
1227 echo stop > "$at_stop_file"
1228 fi
1229 else
1230 if test -d "$at_group_dir"; then
1231 find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
1232 rm -fr "$at_group_dir"
1233 fi
1234 rm -f "$at_test_source"
1235 fi
1236 ;;
1237 *)
1238 # Upon failure, include the log into the testsuite's global
1239 # log. The failure message is written in the group log. It
1240 # is later included in the global log.
1241 AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
1242
1243 # Upon failure, keep the group directory for autopsy, and create
1244 # the debugging script. With -e, do not start any further tests.
1245 at_fn_create_debugging_script
1246 if $at_errexit; then
1247 echo stop > "$at_stop_file"
1248 fi
1249 ;;
1250 esac
1251 }
1252
1253
1254 m4_text_box([Driver loop.])
1255
1256 dnl Catching signals correctly:
1257 dnl
1258 dnl The first idea was: trap the signal, send it to all spawned jobs,
1259 dnl then reset the handler and reraise the signal for ourselves.
1260 dnl However, before exiting, ksh will then send the signal to all
1261 dnl process group members, potentially killing the outer testsuite
1262 dnl and/or the 'make' process driving us.
1263 dnl So now the strategy is: trap the signal, send it to all spawned jobs,
1264 dnl then exit the script with the right status.
1265 dnl
1266 dnl In order to let the jobs know about the signal, we cannot just send it
1267 dnl to the current process group (kill $SIG 0), for the same reason as above.
1268 dnl Also, it does not reliably stop the suite to send the signal to the
1269 dnl spawned processes, because they might not transport it further
1270 dnl (maybe this can be fixed?).
1271 dnl
1272 dnl So what we do is enable shell job control if available, which causes the
1273 dnl shell to start each parallel task as its own shell job, thus as a new
1274 dnl process group leader. We then send the signal to all new process groups.
1275
1276 dnl Do we have job control?
1277 if (set -m && set +m && set +b) >/dev/null 2>&1; then
1278 set +b
1279 at_job_control_on='set -m' at_job_control_off='set +m' at_job_group=-
1280 else
1281 at_job_control_on=: at_job_control_off=: at_job_group=
1282 fi
1283
1284 for at_signal in 1 2 15; do
1285 dnl This signal handler is not suitable for PIPE: it causes writes.
1286 dnl The code that was interrupted may have the errexit, monitor, or xtrace
1287 dnl flags enabled, so sanitize.
1288 trap 'set +x; set +e
1289 $at_job_control_off
1290 at_signal='"$at_signal"'
1291 dnl Safety belt: even with runaway processes, prevent starting new jobs.
1292 echo stop > "$at_stop_file"
1293 dnl Do not enter this area multiple times, do not kill self prematurely.
1294 trap "" $at_signal
1295 dnl Gather process group IDs of currently running jobs.
1296 at_pgids=
1297 for at_pgid in `jobs -p 2>/dev/null`; do
1298 at_pgids="$at_pgids $at_job_group$at_pgid"
1299 done
1300 dnl Ignore 'kill' errors, as some jobs may have finished in the meantime.
1301 test -z "$at_pgids" || kill -$at_signal $at_pgids 2>/dev/null
1302 dnl wait until all jobs have exited.
1303 wait
1304 dnl Status output. Do this after waiting for the jobs, for ordered output.
1305 dnl Avoid scribbling onto the end of a possibly incomplete line.
1306 if test "$at_jobs" -eq 1 || test -z "$at_verbose"; then
1307 echo >&2
1308 fi
1309 at_signame=`kill -l $at_signal 2>&1 || echo $at_signal`
1310 set x $at_signame
1311 test $# -gt 2 && at_signame=$at_signal
1312 AS_WARN([caught signal $at_signame, bailing out])
1313 dnl Do not reinstall the default handler here and reraise the signal to
1314 dnl let the default handler do its job, see the note about ksh above.
1315 dnl trap - $at_signal
1316 dnl kill -$at_signal $$
1317 dnl Instead, exit with appropriate status.
1318 AS_VAR_ARITH([exit_status], [128 + $at_signal])
1319 AS_EXIT([$exit_status])' $at_signal
1320 done
1321
1322 rm -f "$at_stop_file"
1323 at_first=:
1324
1325 if test $at_jobs -ne 1 &&
1326 rm -f "$at_job_fifo" &&
1327 test -n "$at_job_group" &&
1328 ( mkfifo "$at_job_fifo" && trap 'exit 1' PIPE STOP TSTP ) 2>/dev/null
1329 then
1330 # FIFO job dispatcher.
1331
1332 dnl Since we use job control, we need to propagate TSTP.
1333 dnl This handler need not be used for serial execution.
1334 dnl Again, we should stop all processes in the job groups, otherwise
1335 dnl the stopping will not be effective while one test group is running.
1336 dnl Apparently ksh does not honor the TSTP trap.
1337 dnl As a safety measure, not use the same variable names as in the
1338 dnl termination handlers above, one might get called during execution
1339 dnl of the other.
1340 trap 'at_pids=
1341 for at_pid in `jobs -p`; do
1342 at_pids="$at_pids $at_job_group$at_pid"
1343 done
1344 dnl Send it to all spawned jobs, ignoring those finished meanwhile.
1345 if test -n "$at_pids"; then
1346 dnl Unfortunately, ksh93 fork-bombs when we send TSTP, so send STOP
1347 dnl if this might be ksh (STOP prevents possible TSTP handlers inside
1348 dnl AT_CHECKs from running). Then stop ourselves.
1349 at_sig=TSTP
1350 test ${TMOUT+y} && at_sig=STOP
1351 kill -$at_sig $at_pids 2>/dev/null
1352 fi
1353 kill -STOP $$
1354 dnl We got a CONT, so let's go again. Passing this to all processes
1355 dnl in the groups is necessary (because we stopped them), but it may
1356 dnl cause changed test semantics; e.g., a sleep will be interrupted.
1357 test -z "$at_pids" || kill -CONT $at_pids 2>/dev/null' TSTP
1358
1359 echo
1360 # Turn jobs into a list of numbers, starting from 1.
1361 at_joblist=`AS_ECHO(["$at_groups"]) | sed -n 1,${at_jobs}p`
1362
1363 set X $at_joblist
1364 shift
1365 for at_group in $at_groups; do
1366 dnl Enable job control only for spawning the test group:
1367 dnl Let the jobs to run in separate process groups, but
1368 dnl avoid all the status output by the shell.
1369 $at_job_control_on 2>/dev/null
1370 (
1371 # Start one test group.
1372 $at_job_control_off
1373 dnl First child must open the fifo to avoid blocking parent; all other
1374 dnl children inherit it already opened from the parent.
1375 if $at_first; then
1376 exec AT_JOB_FIFO_OUT_FD>"$at_job_fifo"
1377 else
1378 dnl Children do not need parent's copy of fifo.
1379 exec AT_JOB_FIFO_IN_FD<&-
1380 fi
1381 dnl When a child receives PIPE, be sure to write back the token,
1382 dnl so the master does not hang waiting for it.
1383 dnl errexit and xtrace should not be set in this shell instance,
1384 dnl except as debug measures. However, shells such as dash may
1385 dnl optimize away the _AT_CHECK subshell, so normalize here.
1386 trap 'set +x; set +e
1387 dnl Ignore PIPE signals that stem from writing back the token.
1388 trap "" PIPE
1389 echo stop > "$at_stop_file"
1390 echo >&AT_JOB_FIFO_OUT_FD
1391 dnl Do not reraise the default PIPE handler.
1392 dnl It wreaks havoc with ksh, see above.
1393 dnl trap - 13
1394 dnl kill -13 $$
1395 AS_EXIT([141])' PIPE
1396 at_fn_group_prepare
1397 if cd "$at_group_dir" &&
1398 at_fn_test $at_group &&
1399 . "$at_test_source"
1400 then :; else
1401 AS_WARN([unable to parse test group: $at_group])
1402 at_failed=:
1403 fi
1404 at_fn_group_postprocess
1405 echo >&AT_JOB_FIFO_OUT_FD
1406 ) &
1407 $at_job_control_off
1408 if $at_first; then
1409 at_first=false
1410 exec AT_JOB_FIFO_IN_FD<"$at_job_fifo" AT_JOB_FIFO_OUT_FD>"$at_job_fifo"
1411 fi
1412 shift # Consume one token.
1413 if test $[@%:@] -gt 0; then :; else
1414 read at_token <&AT_JOB_FIFO_IN_FD || break
1415 set x $[*]
1416 fi
1417 test -f "$at_stop_file" && break
1418 done
1419 exec AT_JOB_FIFO_OUT_FD>&-
1420 # Read back the remaining ($at_jobs - 1) tokens.
1421 set X $at_joblist
1422 shift
1423 if test $[@%:@] -gt 0; then
1424 shift
1425 for at_job
1426 do
1427 read at_token
1428 done <&AT_JOB_FIFO_IN_FD
1429 fi
1430 exec AT_JOB_FIFO_IN_FD<&-
1431 wait
1432 else
1433 # Run serially, avoid forks and other potential surprises.
1434 for at_group in $at_groups; do
1435 at_fn_group_prepare
1436 if cd "$at_group_dir" &&
1437 at_fn_test $at_group &&
1438 . "$at_test_source"; then :; else
1439 AS_WARN([unable to parse test group: $at_group])
1440 at_failed=:
1441 fi
1442 at_fn_group_postprocess
1443 test -f "$at_stop_file" && break
1444 at_first=false
1445 done
1446 fi
1447
1448 # Wrap up the test suite with summary statistics.
1449 cd "$at_helper_dir"
1450
1451 # Use ?..???? when the list must remain sorted, the faster * otherwise.
1452 at_pass_list=`for f in */pass; do echo $f; done | sed '/\*/d; s,/pass,,'`
1453 at_skip_list=`for f in */skip; do echo $f; done | sed '/\*/d; s,/skip,,'`
1454 at_xfail_list=`for f in */xfail; do echo $f; done | sed '/\*/d; s,/xfail,,'`
1455 at_xpass_list=`for f in ?/xpass ??/xpass ???/xpass ????/xpass; do
1456 echo $f; done | sed '/?/d; s,/xpass,,'`
1457 at_fail_list=`for f in ?/fail ??/fail ???/fail ????/fail; do
1458 echo $f; done | sed '/?/d; s,/fail,,'`
1459
1460 set X $at_pass_list $at_xpass_list $at_xfail_list $at_fail_list $at_skip_list
1461 shift; at_group_count=$[@%:@]
1462 set X $at_xpass_list; shift; at_xpass_count=$[@%:@]; at_xpass_list=$[*]
1463 set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
1464 set X $at_fail_list; shift; at_fail_count=$[@%:@]; at_fail_list=$[*]
1465 set X $at_skip_list; shift; at_skip_count=$[@%:@]
1466
1467 AS_VAR_ARITH([at_run_count], [$at_group_count - $at_skip_count])
1468 AS_VAR_ARITH([at_unexpected_count], [$at_xpass_count + $at_fail_count])
1469 AS_VAR_ARITH([at_total_fail_count], [$at_xfail_count + $at_fail_count])
1470
1471 # Back to the top directory.
1472 cd "$at_dir"
1473 rm -rf "$at_helper_dir"
1474
1475 # Compute the duration of the suite.
1476 at_stop_date=`date`
1477 at_stop_time=`date +%s 2>/dev/null`
1478 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
1479 case $at_start_time,$at_stop_time in
1480 [[0-9]*,[0-9]*])
1481 AS_VAR_ARITH([at_duration_s], [$at_stop_time - $at_start_time])
1482 AS_VAR_ARITH([at_duration_m], [$at_duration_s / 60])
1483 AS_VAR_ARITH([at_duration_h], [$at_duration_m / 60])
1484 AS_VAR_ARITH([at_duration_s], [$at_duration_s % 60])
1485 AS_VAR_ARITH([at_duration_m], [$at_duration_m % 60])
1486 at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
1487 AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
1488 ;;
1489 esac
1490
1491 echo
1492 AS_BOX([Test results.])
1493 echo
1494 {
1495 echo
1496 AS_BOX([Test results.])
1497 echo
1498 } >&AS_MESSAGE_LOG_FD
1499
1500 dnl
1501 dnl FIXME: this code is as far from i18n-cleanness as man
1502 dnl could imagine...
1503 dnl
1504 if test $at_run_count = 1; then
1505 at_result="1 test"
1506 at_were=was
1507 else
1508 at_result="$at_run_count tests"
1509 at_were=were
1510 fi
1511 if $at_errexit_p && test $at_unexpected_count != 0; then
1512 if test $at_xpass_count = 1; then
1513 at_result="$at_result $at_were run, one passed"
1514 else
1515 at_result="$at_result $at_were run, one failed"
1516 fi
1517 at_result="$at_result unexpectedly and inhibited subsequent tests."
1518 at_color=$at_red
1519 else
1520 # Don't you just love exponential explosion of the number of cases?
1521 at_color=$at_red
1522 case $at_xpass_count:$at_fail_count:$at_xfail_count in
1523 # So far, so good.
1524 0:0:0) at_result="$at_result $at_were successful." at_color=$at_grn ;;
1525 0:0:*) at_result="$at_result behaved as expected." at_color=$at_lgn ;;
1526
1527 # Some unexpected failures
1528 0:*:0) at_result="$at_result $at_were run,
1529 $at_fail_count failed unexpectedly." ;;
1530
1531 # Some failures, both expected and unexpected
1532 0:*:1) at_result="$at_result $at_were run,
1533 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1534 0:*:*) at_result="$at_result $at_were run,
1535 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1536
1537 # No unexpected failures, but some xpasses
1538 *:0:*) at_result="$at_result $at_were run,
1539 $at_xpass_count passed unexpectedly." ;;
1540
1541 # No expected failures, but failures and xpasses
1542 *:1:0) at_result="$at_result $at_were run,
1543 $at_unexpected_count did not behave as expected dnl
1544 ($at_fail_count unexpected failure)." ;;
1545 *:*:0) at_result="$at_result $at_were run,
1546 $at_unexpected_count did not behave as expected dnl
1547 ($at_fail_count unexpected failures)." ;;
1548
1549 # All of them.
1550 *:*:1) at_result="$at_result $at_were run,
1551 $at_xpass_count passed unexpectedly,
1552 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1553 *:*:*) at_result="$at_result $at_were run,
1554 $at_xpass_count passed unexpectedly,
1555 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1556 esac
1557
1558 if test $at_skip_count = 0 && test $at_run_count -gt 1; then
1559 at_result="All $at_result"
1560 fi
1561 fi
1562
1563 # Now put skips in the mix.
1564 case $at_skip_count in
1565 0) ;;
1566 1) at_result="$at_result
1567 1 test was skipped." ;;
1568 *) at_result="$at_result
1569 $at_skip_count tests were skipped." ;;
1570 esac
1571
1572 if test $at_unexpected_count = 0; then
1573 echo "$at_color$at_result$at_std"
1574 echo "$at_result" >&AS_MESSAGE_LOG_FD
1575 else
1576 echo "${at_color}ERROR: $at_result$at_std" >&2
1577 echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
1578 {
1579 echo
1580 AS_BOX([Summary of the failures.])
1581
1582 # Summary of failed and skipped tests.
1583 if test $at_fail_count != 0; then
1584 echo "Failed tests:"
1585 $SHELL "$at_myself" $at_fail_list --list
1586 echo
1587 fi
1588 if test $at_skip_count != 0; then
1589 echo "Skipped tests:"
1590 $SHELL "$at_myself" $at_skip_list --list
1591 echo
1592 fi
1593 if test $at_xpass_count != 0; then
1594 echo "Unexpected passes:"
1595 $SHELL "$at_myself" $at_xpass_list --list
1596 echo
1597 fi
1598 if test $at_fail_count != 0; then
1599 AS_BOX([Detailed failed tests.])
1600 echo
1601 for at_group in $at_fail_list
1602 do
1603 at_group_normalized=$at_group
1604 _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1605 cat "$at_suite_dir/$at_group_normalized/$as_me.log"
1606 echo
1607 done
1608 echo
1609 fi
1610 if test -n "$at_top_srcdir"; then
1611 AS_BOX([${at_top_build_prefix}config.log])
1612 sed 's/^/| /' ${at_top_build_prefix}config.log
1613 echo
1614 fi
1615 } >&AS_MESSAGE_LOG_FD
1616
1617 AS_BOX([$as_me.log was created.])
1618
1619 echo
1620 if $at_debug_p; then
1621 at_msg='per-test log files'
1622 else
1623 at_msg="'${at_testdir+${at_testdir}/}$as_me.log'"
1624 fi
1625 at_msg1a=${at_xpass_list:+', '}
1626 at_msg1=$at_fail_list${at_fail_list:+" failed$at_msg1a"}
1627 at_msg2=$at_xpass_list${at_xpass_list:+" passed unexpectedly"}
1628
1629 AS_ECHO(["Please send $at_msg and all information you think might help:
1630
1631 To: <AT_PACKAGE_BUGREPORT>
1632 Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me: dnl
1633 $at_msg1$at_msg2
1634
1635 You may investigate any problem if you feel able to do so, in which
1636 case the test suite provides a good starting point. Its output may
1637 be found below '${at_testdir+${at_testdir}/}$as_me.dir'.
1638 "])
1639 exit 1
1640 fi
1641
1642 exit 0
1643
1644 m4_text_box([Actual tests.])
1645 m4_divert_pop([TESTS])dnl
1646 dnl End of AT_INIT: divert to KILL, only test groups are to be
1647 dnl output, the rest is ignored. Current diversion is BODY, inherited
1648 dnl from M4sh.
1649 m4_divert([KILL])
1650 ])# AT_INIT
1651
1652
1653 # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
1654 # [ACTION-IF-NOT-GIVEN])
1655 # ----------------------------------------------------------
1656 # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
1657 m4_defun([_AT_ARG_OPTION],
1658 [m4_divert_once([HELP_OTHER],
1659 [cat <<_ATEOF || at_write_fail=1
1660
1661 Other options:
1662 _ATEOF
1663 ])dnl m4_divert_once HELP_OTHER
1664 m4_divert_text([HELP_OTHER],
1665 [cat <<_ATEOF || at_write_fail=1
1666 $2
1667 _ATEOF])dnl
1668 dnl Turn our options into our desired strings
1669 m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
1670 m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
1671 m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
1672 m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
1673 m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
1674 [m4_define_default([AT_first_option],AT_option)dnl
1675 m4_define_default([AT_first_option_tr],
1676 [m4_bpatsubst(m4_defn([AT_first_option]), -, [_])])dnl
1677 m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
1678 m4_append([AT_case_no],[--no-]AT_option, [ | ])dnl
1679 m4_append([AT_case_arg],
1680 m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
1681 ])dnl m4_foreach AT_option
1682 dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
1683 m4_divert_once([PARSE_ARGS_BEGIN],
1684 [
1685 ##
1686 ## Set up package specific options.
1687 ##
1688 ])dnl
1689 m4_divert_text([PARSE_ARGS_BEGIN],
1690 [dnl Provide a default value for options without arguments.
1691 m4_ifvaln([$3],,[at_arg_[]AT_first_option_tr=false])dnl
1692 at_arg_given_[]AT_first_option_tr=false
1693 ])dnl m4_divert_text DEFAULTS
1694 m4_divert_text([PARSE_ARGS],
1695 [dnl Parse the options and args when necessary.
1696 m4_ifvaln([$3],
1697 [ AT_case )
1698 at_prev=--AT_first_option_tr
1699 ;;
1700 AT_case_arg )
1701 at_arg_[]AT_first_option_tr=$at_optarg
1702 at_arg_given_[]AT_first_option_tr=:
1703 $4
1704 ;;],
1705 [ AT_case )
1706 at_optarg=:
1707 at_arg_[]AT_first_option_tr=:
1708 at_arg_given_[]AT_first_option_tr=:
1709 m4_ifval([$4],[$4])[]dnl
1710 ;;
1711 AT_case_no )
1712 at_optarg=false
1713 at_arg_[]AT_first_option_tr=false
1714 at_arg_given_[]AT_first_option_tr=:
1715 m4_ifval([$4],[$4])[]dnl
1716 ;;])dnl m4_ifvaln $3
1717 ])dnl m4_divert_text PARSE_ARGS
1718 m4_ifvaln([$5],
1719 [m4_divert_once([PARSE_ARGS_END],
1720 [
1721 ##
1722 ## Process package specific options when _not_ supplied.
1723 ##])dnl m4_divert_once PARSE_ARGS_END
1724 m4_divert_text([PARSE_ARGS_END],
1725 [
1726 AS_IF([$at_arg_given_[]AT_first_option_tr],,[$5])dnl
1727 ])dnl m4_divert_text PARSE_ARGS_END
1728 ])dnl m4_ifvaln $5
1729 ])dnl _AT_ARG_OPTION
1730
1731
1732 # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1733 # ------------------------------------------------------------------------
1734 # Accept a list of space-separated OPTIONS, all aliases of the first one.
1735 # Add HELP-TEXT to the HELP_OTHER diversion.
1736 #
1737 # Leading dashes should not be passed in OPTIONS. Users will be required
1738 # to pass '--' before long options and '-' before single character options.
1739 #
1740 # $at_arg_OPTION will be set to ':' if this option is received, 'false' if
1741 # if --no-OPTION is received, and 'false' by default.
1742 #
1743 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered; here,
1744 # $at_optarg will be set to ':' or 'false' as appropriate. $at_optarg is
1745 # actually just a copy of $at_arg_OPTION.
1746 #
1747 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete and
1748 # if no option from OPTIONS was used.
1749 m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
1750
1751
1752 # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1753 # ----------------------------------------------------------------------------
1754 # Accept a set of space-separated OPTIONS with arguments, all aliases of the
1755 # first one. Add HELP-TEXT to the HELP_OTHER diversion.
1756 #
1757 # Leading dashes should not be passed in OPTIONS. Users will be required
1758 # to pass '--' before long options and '-' before single character options.
1759 #
1760 # By default, any argument to these options will be assigned to the shell
1761 # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
1762 # any '-' characters replaced with '_'.
1763 #
1764 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered; here,
1765 # $at_optarg will be set to the option argument. $at_optarg is actually just
1766 # a copy of $at_arg_OPTION.
1767 #
1768 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1769 # and if no option from OPTIONS was used.
1770 m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
1771
1772
1773 # AT_TESTED(PROGRAMS)
1774 # -------------------
1775 # Specify the list of programs exercised by the test suite. Their
1776 # versions are logged, and in the case of embedded test suite, they
1777 # must correspond to the version of the package. PATH should be
1778 # already preset so the proper executable will be selected.
1779 m4_defun([AT_TESTED],
1780 [m4_require([_AT_TESTED])]dnl
1781 [m4_foreach_w([AT_test], [$1],
1782 [m4_append_uniq([AT_tested], "m4_defn([AT_test])", [ ])])])
1783
1784 m4_defun([_AT_TESTED],
1785 [m4_wrap([m4_divert_text([DEFAULTS],
1786 [# List of the tested programs.
1787 at_tested='m4_translit(m4_dquote(m4_defn([AT_tested])), [ ], m4_newline)'
1788 ])]dnl
1789 [m4_divert_text([PREPARE_TESTS],
1790 [{
1791 AS_BOX([Tested programs.])
1792 echo
1793 } >&AS_MESSAGE_LOG_FD
1794
1795 # Report what programs are being tested.
1796 for at_program in : `eval echo $at_tested`
1797 do
1798 AS_CASE([$at_program],
1799 [:], [continue],
1800 [[[\\/]* | ?:[\\/]*]], [at_program_=$at_program],
1801 [_AS_PATH_WALK([$PATH], [test -f "$as_dir$at_program" && break])
1802 at_program_=$as_dir$at_program])
1803
1804 if test -f "$at_program_"; then
1805 {
1806 AS_ECHO(["$at_srcdir/AT_LINE: $at_program_ --version"])
1807 "$at_program_" --version </dev/null
1808 echo
1809 } >&AS_MESSAGE_LOG_FD 2>&1
1810 else
1811 AS_ERROR([cannot find $at_program])
1812 fi
1813 done
1814 ])])])
1815
1816
1817 # AT_PREPARE_TESTS(SHELL-CODE)
1818 # ----------------------------
1819 # Execute @var{shell-code} in the main testsuite process,
1820 # after initializing the test suite and processing command-line options,
1821 # but before running any tests.
1822 m4_define([AT_PREPARE_TESTS],
1823 [m4_divert_once([PREPARE_TESTS],
1824 [m4_text_box([Prepare for this testsuite.])
1825 ])]dnl
1826 [m4_divert_text([PREPARE_TESTS], [$1])])
1827
1828
1829 # AT_PREPARE_EACH_TEST([SHELL-CODE])
1830 # ----------------------------------
1831 # Execute @var{shell-code} in each test group's subshell,
1832 # at the point of the AT_SETUP that starts each test group.
1833 m4_define([AT_PREPARE_EACH_TEST],
1834 [m4_append([AT_prepare_each_test], [$1], [
1835 ])])
1836
1837
1838 # AT_TEST_HELPER_FN(NAME, ARGS, DESCRIPTION, CODE)
1839 # ------------------------------------------------
1840 # Define a shell function that will be available to the code for each test
1841 # group. Its name will be ath_fn_NAME, and its body will be CODE.
1842 #
1843 # Implementation note: you might think this would use AT_PREPARE_EACH_TEST,
1844 # but shell functions defined in AT_PREPARE_TESTS *are* (currently) available
1845 # to test group subshells, and this way the code is only emitted once, not
1846 # once for each test group.
1847 m4_define([AT_TEST_HELPER_FN],
1848 [AS_LITERAL_WORD_IF([$1], [],
1849 [m4_fatal([invalid shell function name "$1"])])]dnl
1850 [m4_ifdef([ATH_fn_$1_defined],
1851 [m4_fatal([helper function "$1" defined twice])])]dnl
1852 [m4_define([ATH_fn_$1_defined])]dnl
1853 [AT_PREPARE_TESTS([
1854 AS_FUNCTION_DESCRIBE([ath_fn_$1], [$2], [$3])
1855 ath_fn_$1 ()
1856 {
1857 $4
1858 }
1859 ])])
1860
1861
1862 # AT_COPYRIGHT(TEXT, [FILTER = m4_newline])
1863 # -----------------------------------------
1864 # Emit TEXT, a copyright notice, in the top of the test suite and in
1865 # --version output. Macros in TEXT are evaluated once. Process
1866 # the --version output through FILTER (m4_newline, m4_do, and
1867 # m4_copyright_condense are common filters).
1868 m4_define([AT_COPYRIGHT],
1869 [AS_COPYRIGHT([$1])[]]dnl
1870 [m4_divert_text([VERSION_NOTICES],
1871 [m4_default([$2], [m4_newline])([$1])])])# AT_COPYRIGHT
1872
1873
1874 # AT_COLOR_TESTS
1875 # --------------
1876 # Enable colored test results if standard error is connected to a terminal.
1877 m4_define([AT_COLOR_TESTS],
1878 [m4_define([AT_color], [auto])])
1879
1880 # AT_SETUP(DESCRIPTION)
1881 # ---------------------
1882 # Start a group of related tests, all to be executed in the same subshell.
1883 # The group is testing what DESCRIPTION says.
1884 _AT_DEFINE_INIT([AT_SETUP],
1885 [m4_ifdef([AT_ingroup], [m4_fatal([$0: nested AT_SETUP detected])],
1886 [m4_define([AT_ingroup], [AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
1887 ])])
1888 m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
1889 m4_define([AT_capture_files], [])
1890 m4_define([AT_line], AT_LINE)
1891 m4_define([AT_xfail], [at_xfail=no])
1892 m4_define([AT_description], m4_expand([$1]))
1893 m4_define([AT_ordinal], m4_incr(AT_ordinal))
1894 m4_divert_push([TEST_GROUPS])dnl
1895 [#AT_START_]AT_ordinal
1896 at_fn_group_banner AT_ordinal 'm4_defn([AT_line])' \
1897 "AS_ESCAPE(m4_dquote(m4_defn([AT_description])))" m4_format(["%*s"],
1898 m4_max(0, m4_eval(47 - m4_qlen(m4_defn([AT_description])))), [])m4_if(
1899 AT_banner_ordinal, [0], [], [ AT_banner_ordinal])
1900 m4_ifset([AT_prepare_each_test], [AT_prepare_each_test
1901 ])dnl
1902 m4_divert_push([TEST_SCRIPT])dnl
1903 ])
1904
1905
1906 # AT_FAIL_IF(SHELL-EXPRESSION)
1907 # ----------------------------
1908 # Make the test die with hard failure if SHELL-EXPRESSION evaluates to
1909 # true (exitcode = 0).
1910 _AT_DEFINE_SETUP([AT_FAIL_IF],
1911 [dnl
1912 dnl Try to limit the amount of conditionals that we emit.
1913 m4_case([$1],
1914 [], [],
1915 [false], [],
1916 [:], [_AT_CHECK_EXIT([], [99])],
1917 [true], [_AT_CHECK_EXIT([], [99])],
1918 [_AT_CHECK_EXIT([$1], [99])])])
1919
1920
1921 # AT_SKIP_IF(SHELL-EXPRESSION)
1922 # ----------------------------
1923 # Skip the rest of the group if SHELL-EXPRESSION evaluates to true
1924 # (exitcode = 0).
1925 _AT_DEFINE_SETUP([AT_SKIP_IF],
1926 [dnl
1927 dnl Try to limit the amount of conditionals that we emit.
1928 m4_case([$1],
1929 [], [],
1930 [false], [],
1931 [:], [_AT_CHECK_EXIT([], [77])],
1932 [true], [_AT_CHECK_EXIT([], [77])],
1933 [_AT_CHECK_EXIT([$1], [77])])])
1934
1935
1936 # AT_XFAIL_IF(SHELL-EXPRESSION)
1937 # -----------------------------
1938 # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
1939 # true (exitcode = 0).
1940 _AT_DEFINE_SETUP([AT_XFAIL_IF],
1941 [dnl
1942 dnl Try to limit the amount of conditionals that we emit.
1943 m4_case([$1],
1944 [], [],
1945 [false], [],
1946 [:], [m4_define([AT_xfail], [at_xfail=yes])],
1947 [true], [m4_define([AT_xfail], [at_xfail=yes])],
1948 [m4_append([AT_xfail], [
1949 $1 && at_xfail=yes])])])
1950
1951
1952 # AT_KEYWORDS(KEYWORDS)
1953 # ---------------------
1954 # Declare a list of keywords associated to the current test group.
1955 # Since the -k option is case-insensitive, the list is stored in lower case
1956 # to avoid duplicates that differ only by case.
1957 _AT_DEFINE_SETUP([AT_KEYWORDS],
1958 [m4_append_uniq_w([AT_keywords], m4_tolower(_m4_expand([$1
1959 ])))])
1960
1961
1962 # AT_CAPTURE_FILE(FILE)
1963 # ---------------------
1964 # If the current test group does not behave as expected, save the contents of
1965 # FILE in the test suite log.
1966 _AT_DEFINE_SETUP([AT_CAPTURE_FILE],
1967 [m4_append_uniq([AT_capture_files], ["$1"], [ \
1968 ])])
1969
1970
1971 # AT_CLEANUP
1972 # ----------
1973 # Complete a group of related tests.
1974 _AT_DEFINE_INIT([AT_CLEANUP],
1975 [m4_ifdef([AT_ingroup], [AT_ingroup[]_m4_undefine([AT_ingroup])],
1976 [m4_fatal([$0: missing AT_SETUP detected])])dnl
1977 m4_append([AT_help_all],
1978 m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);dnl
1979 m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
1980 )dnl
1981 m4_divert_pop([TEST_SCRIPT])dnl Back to TEST_GROUPS
1982 AT_xfail
1983 (
1984 AS_ECHO(["AT_ordinal. $at_setup_line: testing $at_desc ..."])
1985 $at_traceon
1986 m4_undivert([TEST_SCRIPT])dnl Insert the code here
1987 set +x
1988 $at_times_p && times >"$at_times_file"
1989 ) AS_MESSAGE_LOG_FD>&1 2>&1 AT_JOB_FIFO_OUT_FD>&- | eval $at_tee_pipe
1990 read at_status <"$at_status_file"
1991 [#AT_STOP_]AT_ordinal
1992 m4_divert_pop([TEST_GROUPS])dnl Back to KILL.
1993 ])# AT_CLEANUP
1994
1995
1996 # AT_BANNER([TEXT])
1997 # -----------------
1998 # Start a category of related test groups. If multiple groups are executed,
1999 # output TEXT as a banner without any shell expansion, prior to any test
2000 # from the category. If TEXT is empty, no banner is printed.
2001 _AT_DEFINE_INIT([AT_BANNER],
2002 [m4_ifdef([AT_ingroup], [m4_fatal([$0: nested AT_SETUP detected])])dnl
2003 m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
2004 m4_divert_text([BANNERS],
2005 [@%:@ Banner AT_banner_ordinal. AT_LINE
2006 @%:@ Category starts at test group m4_incr(AT_ordinal).
2007 at_banner_text_[]AT_banner_ordinal="AS_ESCAPE([$1])"])dnl
2008 ])# AT_BANNER
2009
2010
2011 # AT_DATA_UNQUOTED(FILE, CONTENTS)
2012 # -----------------------
2013 # Initialize an input data FILE with given CONTENTS, which should be
2014 # empty or end with a newline.
2015 # This macro is not robust to active symbols in CONTENTS *on purpose*.
2016 # If you don't want CONTENTS to be evaluated, quote it twice.
2017 # In addition, it does not quote shell variables. For example, it
2018 # can be used to generate data files containing a carriage return.
2019 _AT_DEFINE_SETUP([AT_DATA_UNQUOTED],
2020 [m4_if([$2], [], [: >$1],
2021 [$2], [[]], [: >$1],
2022 [cat >$1 <<_ATEOF
2023 $2[]_ATEOF
2024 ])])
2025
2026
2027 # AT_DATA(FILE, CONTENTS)
2028 # -----------------------
2029 # Initialize an input data FILE with given CONTENTS, which should be
2030 # empty or end with a newline.
2031 # This macro is not robust to active symbols in CONTENTS *on purpose*.
2032 # If you don't want CONTENTS to be evaluated, quote it twice.
2033 _AT_DEFINE_SETUP([AT_DATA],
2034 [m4_if([$2], [], [: >$1],
2035 [$2], [[]], [: >$1],
2036 [cat >$1 <<'_ATEOF'
2037 $2[]_ATEOF
2038 ])])
2039
2040
2041 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2042 # [RUN-IF-FAIL], [RUN-IF-PASS])
2043 # ------------------------------------------------
2044 # Execute a test by performing given shell COMMANDS. These commands
2045 # should normally exit with STATUS, while producing expected STDOUT and
2046 # STDERR contents. Shell metacharacters in STDOUT and STDERR are
2047 # _not_ processed by the shell, but are treated as string literals.
2048 #
2049 # STATUS, STDOUT, and STDERR are not checked if equal to 'ignore'.
2050 #
2051 # If STDOUT is 'expout', then stdout is compared to the content of the file
2052 # 'expout'. Likewise for STDERR and 'experr'.
2053 #
2054 # If STDOUT is 'stdout', then the stdout is left in the file 'stdout',
2055 # likewise for STDERR and 'stderr'. Don't do this:
2056 #
2057 # AT_CHECK([command >out])
2058 # # Some checks on 'out'
2059 #
2060 # do this instead:
2061 #
2062 # AT_CHECK([command], [], [stdout])
2063 # # Some checks on 'stdout'
2064 #
2065 # You might wonder why you can't just use 'ignore', then directly use stdout
2066 # and stderr left by the test suite:
2067 #
2068 # AT_CHECK([command], [], [ignore])
2069 # AT_CHECK([check stdout])
2070 #
2071 # If the test suite always captured data in the file 'stdout', then the
2072 # second command would be trying to read and write from the same file, with
2073 # undefined behavior. Therefore, the test suite actually captures data in
2074 # an internal file of a different name, and only creates 'stdout' when
2075 # explicitly requested.
2076 #
2077 # Any line of stderr starting with leading blanks and a '+' are filtered
2078 # out, since most shells when tracing include subshell traces in stderr.
2079 # This may cause spurious failures when the test suite is run with '-x'.
2080 #
2081 _AT_DEFINE_SETUP([AT_CHECK],
2082 [_AT_CHECK(m4_expand([$1]), [$2], AS_ESCAPE(m4_dquote(m4_expand([$3]))),
2083 AS_ESCAPE(m4_dquote(m4_expand([$4]))), [$5], [$6])])
2084
2085 # AT_CHECK_UNQUOTED(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2086 # [RUN-IF-FAIL], [RUN-IF-PASS])
2087 # ---------------------------------------------------------
2088 # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
2089 # and STDERR arguments before running the comparison.
2090 _AT_DEFINE_SETUP([AT_CHECK_UNQUOTED],
2091 [_AT_CHECK(m4_expand([$1]), [$2], AS_ESCAPE(m4_dquote(m4_expand([$3])), [""]),
2092 AS_ESCAPE(m4_dquote(m4_expand([$4])), [""]), [$5], [$6])])
2093
2094 # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2095 # [RUN-IF-FAIL], [RUN-IF-PASS])
2096 # ---------------------------------------------------------
2097 # Obsolete spelling of AT_CHECK_UNQUOTED.
2098 m4_define([AT_CHECK_NOESCAPE],
2099 [m4_warn([obsolete], [consider using AT_CHECK_UNQUOTED instead of $0])]dnl
2100 [_AT_CHECK(m4_expand([$1]), [$2], m4_expand([$3]),
2101 m4_expand([$4]), [$5], [$6])])
2102
2103
2104 # _AT_DECIDE_TRACEABLE(COMMANDS)
2105 # ------------------------------
2106 # Worker for _AT_CHECK that expands to shell code. If COMMANDS are safe to
2107 # trace with 'set -x', the shell code will evaluate to true. Otherwise,
2108 # the shell code will print a message stating an aspect of COMMANDS that makes
2109 # tracing them unsafe, and evaluate to false.
2110 #
2111 # Tracing COMMANDS is not safe if they contain a command that spans multiple
2112 # lines. When the test suite user passes '-x' or '--trace', the test suite
2113 # precedes every command with a 'set -x'. Since most tests expect a specific
2114 # stderr, if only to confirm that it is empty, the test suite filters ^+ from
2115 # the captured stderr before comparing with the expected stderr. If a command
2116 # spans multiple lines, so will its trace, but a '+' only prefixes the first
2117 # line of that trace:
2118 #
2119 # $ echo 'foo
2120 # bar'
2121 # => stdout
2122 # foo
2123 # bar
2124 # => stderr
2125 # + foo
2126 # bar
2127 #
2128 # In a subset of cases, one could filter such extended shell traces from
2129 # stderr. Since test commands spanning several lines are rare, I chose
2130 # instead to simply not trace COMMANDS that could yield multiple trace lines.
2131 # Distinguishing such COMMANDS became the task at hand.
2132 #
2133 # These features may cause a shell command to span multiple lines:
2134 #
2135 # (a) A quoted literal newline.
2136 # Example:
2137 # echo foo'
2138 # 'bar
2139 # M4 is a hostile language for the job of parsing COMMANDS to determine whether
2140 # each literal newline is quoted, so we simply disable tracing for all COMMANDS
2141 # that bear literal newlines.
2142 #
2143 # (b) A command substitution not subject to word splitting.
2144 # Example:
2145 # var=$(printf 'foo\nbar')
2146 # Example:
2147 # echo "`printf 'foo\\nbar`"
2148 # One cannot know in general the number of lines a command substitution will
2149 # yield without executing the substituted command. As such, we disable tracing
2150 # for all COMMANDS containing these constructs.
2151 #
2152 # (c) A parameter expansion not subject to word splitting.
2153 # Example:
2154 # var=foo'
2155 # 'bar
2156 # echo "$var"
2157 # Parameter expansions appear in COMMANDS with much greater frequency than do
2158 # newlines and command substitutions, so disabling tracing for all such
2159 # COMMANDS would much more substantially devalue 'testsuite -x'. To determine
2160 # which parameter expansions yield multiple lines, we escape all '`', '"',
2161 # and '\' in a copy of COMMANDS and expand that string within double quotes
2162 # at runtime. If the result of that expansion contains multiple lines, the
2163 # test suite disables tracing for the command in question.
2164 #
2165 # This method leads the test suite to expand some parameters that the shell
2166 # itself will never expand due to single-quotes or backslash escapes. This is
2167 # not a problem for '$foo' expansions, which will simply yield the empty string
2168 # or some unrelated value. A '${...}' expansion could actually form invalid
2169 # shell code, however; consider '${=foo}'. Therefore, we disable tracing for
2170 # all COMMANDS containing '${...}'. This affects few COMMANDS.
2171 #
2172 # This macro falls in a very hot path; the Autoconf test suite expands it 1640
2173 # times as of this writing. To give a sense of the impact of the heuristics I
2174 # just described, the test suite preemptively disables tracing for 31 of those,
2175 # and 268 contain parameter expansions that require runtime evaluation. The
2176 # balance are always safe to trace.
2177 m4_define([_AT_DECIDE_TRACEABLE],
2178 dnl Utility macro.
2179 dnl
2180 dnl Examine COMMANDS for a reason to never trace COMMANDS.
2181 [m4_pushdef([at_reason],
2182 m4_cond([m4_eval(m4_index([$1], [`]) >= 0)], [1],
2183 [[a `...` command substitution]],
2184 [m4_eval(m4_index([$1], [$(]) >= 0)], [1],
2185 [[a $(...) command substitution]],
2186 [m4_eval(m4_index([$1], [${]) >= 0)], [1],
2187 [[a ${...} parameter expansion]],
2188 [m4_eval(m4_index([$1], m4_newline) >= 0)], [1],
2189 [[an embedded newline]],
2190 [m4_eval(m4_bregexp([$1], [[^|]|[^|]]) >= 0)], [1],
2191 [[a shell pipeline]],
2192 []))]dnl No reason.
2193 [m4_if(m4_index(_m4_defn([at_reason]), [a]), [0],]dnl
2194 dnl We know at build time that tracing COMMANDS is never safe.
2195 [[at_fn_check_prepare_notrace '_m4_defn([at_reason])'],
2196 m4_index([$1], [$]), [-1],]dnl
2197 dnl We know at build time that tracing COMMANDS is always safe.
2198 [[at_fn_check_prepare_trace],]dnl
2199 dnl COMMANDS may contain parameter expansions; expand them at runtime.
2200 [[at_fn_check_prepare_dynamic "AS_ESCAPE([[$1]], [`\"])"])[]]dnl
2201 [_m4_popdef([at_reason])])
2202
2203
2204 # AT_DIFF_STDERR/AT_DIFF_STDOUT
2205 # -----------------------------
2206 # These are subroutines of AT_CHECK. Using indirect dispatch is a tad
2207 # faster than using m4_case, and these are called very frequently.
2208 m4_define([AT_DIFF_STDERR(stderr)],
2209 [echo stderr:; tee stderr <"$at_stderr"])
2210 m4_define([AT_DIFF_STDERR(stderr-nolog)],
2211 [echo stderr captured; cp "$at_stderr" stderr])
2212 m4_define([AT_DIFF_STDERR(ignore)],
2213 [echo stderr:; cat "$at_stderr"])
2214 m4_define([AT_DIFF_STDERR(ignore-nolog)])
2215 m4_define([AT_DIFF_STDERR(experr)],
2216 [$at_diff experr "$at_stderr" || at_failed=:])
2217 m4_define([AT_DIFF_STDERR()],
2218 [at_fn_diff_devnull "$at_stderr" || at_failed=:])
2219
2220 m4_define([AT_DIFF_STDOUT(stdout)],
2221 [echo stdout:; tee stdout <"$at_stdout"])
2222 m4_define([AT_DIFF_STDOUT(stdout-nolog)],
2223 [echo stdout captured; cp "$at_stdout" stdout])
2224 m4_define([AT_DIFF_STDOUT(ignore)],
2225 [echo stdout:; cat "$at_stdout"])
2226 m4_define([AT_DIFF_STDOUT(ignore-nolog)])
2227 m4_define([AT_DIFF_STDOUT(expout)],
2228 [$at_diff expout "$at_stdout" || at_failed=:])
2229 m4_define([AT_DIFF_STDOUT()],
2230 [at_fn_diff_devnull "$at_stdout" || at_failed=:])
2231
2232 # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
2233 # [RUN-IF-FAIL], [RUN-IF-PASS])
2234 # -------------------------------------------------
2235 # Worker for AT_CHECK and AT_CHECK_UNQUOTED, with COMMANDS, STDOUT, and
2236 # STDERR pre-expanded.
2237 #
2238 # Implementation Details
2239 # ----------------------
2240 # Ideally, we would like to run
2241 #
2242 # ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
2243 #
2244 # but we must group COMMANDS as it is not limited to a single command, and
2245 # then the shells will save the traces in at-stderr. So we have to filter
2246 # them out when checking stderr, and we must send them into the test suite's
2247 # stderr to honor -x properly. Since only the first line of the trace of a
2248 # multiline command starts with a '+', and I know of no straightforward way to
2249 # filter out the unadorned trace lines, we disable shell tracing entirely for
2250 # commands that could span multiple lines.
2251 #
2252 # Limiting COMMANDS to a single command is not good either, since then
2253 # the user herself would use {} or (), and then we face the same problem.
2254 #
2255 # But then, there is no point in running
2256 #
2257 # ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
2258 #
2259 # instead of the simpler
2260 #
2261 # ( $at_traceon; $1 ) >at-stdout 2>at-stder1
2262 #
2263 # Note that we truncate and append to the output files, to avoid losing
2264 # output from multiple concurrent processes, e.g., an inner testsuite
2265 # with parallel jobs.
2266 m4_define([_AT_CHECK],
2267 [m4_define([AT_ingroup])]dnl
2268 [{ set +x
2269 AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([[$1]])"])
2270 _AT_DECIDE_TRACEABLE([$1]) _AT_LINE_ESCAPED
2271 ( $at_check_trace; [$1]
2272 ) >>"$at_stdout" 2>>"$at_stderr" AS_MESSAGE_LOG_FD>&-
2273 at_status=$? at_failed=false
2274 $at_check_filter
2275 m4_ifdef([AT_DIFF_STDERR($4)], [m4_indir([AT_DIFF_STDERR($4)])],
2276 [echo >>"$at_stderr"; AS_ECHO([["$4"]]) | \
2277 $at_diff - "$at_stderr" || at_failed=:])
2278 m4_ifdef([AT_DIFF_STDOUT($3)], [m4_indir([AT_DIFF_STDOUT($3)])],
2279 [echo >>"$at_stdout"; AS_ECHO([["$3"]]) | \
2280 $at_diff - "$at_stdout" || at_failed=:])
2281 m4_if([$2], [ignore], [at_fn_check_skip],
2282 [at_fn_check_status m4_default([$2], [0])]) $at_status "$at_srcdir/AT_LINE"
2283 m4_ifvaln([$5$6], [AS_IF($at_failed, [$5], [$6])])]dnl
2284 [$at_failed && at_fn_log_failure AT_capture_files
2285 $at_traceon; }
2286 ])# _AT_CHECK
2287
2288 # _AT_CHECK_EXIT(COMMANDS, [EXIT-STATUS-IF-PASS])
2289 # -----------------------------------------------
2290 # Minimal version of _AT_CHECK for AT_SKIP_IF and AT_FAIL_IF.
2291 m4_define([_AT_CHECK_EXIT],
2292 [m4_define([AT_ingroup])]dnl
2293 [AS_ECHO(_AT_LINE_ESCAPED) >"$at_check_line_file"
2294 m4_ifval([$1], [($1) \
2295 && ])at_fn_check_skip $2 "$at_srcdir/AT_LINE"])# _AT_CHECK_EXIT