Reword the copyright notices to match what's suggested in GPLv3.
[autoconf/tsuna.git] / lib / autotest / general.m4
blobf562679fe3c6b337ad8c4eb4f426197724dd0a58
1 # This file is part of Autoconf.                          -*- Autoconf -*-
2 # M4 macros used in building test suites.
4 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free
5 # Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 # As a special exception, the Free Software Foundation gives unlimited
21 # permission to copy, distribute and modify the configure scripts that
22 # are the output of Autoconf.  You need not follow the terms of the GNU
23 # General Public License when using or distributing such scripts, even
24 # though portions of the text of Autoconf appear in them.  The GNU
25 # General Public License (GPL) does govern all other use of the material
26 # that constitutes the Autoconf program.
28 # Certain portions of the Autoconf source text are designed to be copied
29 # (in certain cases, depending on the input) into the output of
30 # Autoconf.  We call these the "data" portions.  The rest of the Autoconf
31 # source text consists of comments plus executable code that decides which
32 # of the data portions to output in any given case.  We call these
33 # comments and executable code the "non-data" portions.  Autoconf never
34 # copies any of the non-data portions into its output.
36 # This special exception to the GPL applies to versions of Autoconf
37 # released by the Free Software Foundation.  When you make and
38 # distribute a modified version of Autoconf, you may extend this special
39 # exception to the GPL to apply to your modified version as well, *unless*
40 # your modified version has the potential to copy into its output some
41 # of the text that was the non-data portion of the version that you started
42 # with.  (In other words, unless your change moves or copies text from
43 # the non-data portions to the data portions.)  If your modification has
44 # such potential, you must delete any notice of this special exception
45 # to the GPL from your modified version.
47 # _m4_divert(DIVERSION-NAME)
48 # --------------------------
49 # Convert a diversion name into its number.  Otherwise, return
50 # DIVERSION-NAME which is supposed to be an actual diversion number.
51 # Of course it would be nicer to use m4_case here, instead of zillions
52 # of little macros, but it then takes twice longer to run `autoconf'!
54 # From M4sugar:
55 #    -1. KILL
56 # 10000. GROW
58 # From M4sh:
59 #    0. BINSH
60 #    1. HEADER-REVISION
61 #    2. HEADER-COMMENT
62 #    3. HEADER-COPYRIGHT
63 #    4. M4SH-SANITIZE
64 #    5. M4SH-INIT
65 # 1000. BODY
67 # Defined below:
68 #  - DEFAULTS
69 #    Overall initialization, value of $at_groups_all.
70 #  - PARSE_ARGS_BEGIN
71 #    Setup defaults required for option processing.
72 #  - PARSE_ARGS
73 #    Option processing.  After AT_INIT, user options can be entered here as
74 #    cases of a case statement.
75 #  - PARSE_ARGS_END
76 #    Finish up the option processing.
78 #  - HELP
79 #    Start printing the help message.
80 #  - HELP_MODES
81 #    Modes help text.  Additional modes can be appended as self-contained
82 #    cat'd here-docs as generated by AS_HELP_STRING.
83 #  - HELP_TUNING
84 #    Tuning help text.  Additional tuning options can be appended as
85 #    self-contained cat'd here-docs as generated by AS_HELP_STRING.
86 #  - HELP_OTHER
87 #    User help can be appended to this as self-contained cat'd here-docs.
88 #  - HELP_END
89 #    Finish up the help texts.
91 #  - VERSION
92 #    Head of the handling of --version.
93 #  - VERSION_NOTICES
94 #    Copyright notices for --version.
95 #  - VERSION_END
96 #    Tail of the handling of --version.
98 #  - PREPARE_TESTS
99 #    Like DEFAULTS but run after argument processing for purposes of
100 #    optimization.  Do anything else that needs to be done to prepare for
101 #    tests.  Sets up verbose and log file descriptors.  Sets and logs PATH.
102 #  - TESTS
103 #    The core of the test suite.
104 #  - TESTS_END
105 #    tail of the core for;case, overall wrap up, generation of debugging
106 #    scripts and statistics.
107 #  - TEST_SCRIPT
108 #    The code for each test, the ``normal'' diversion
110 m4_define([_m4_divert(DEFAULTS)],           100)
111 m4_define([_m4_divert(PARSE_ARGS_BEGIN)],   200)
112 m4_define([_m4_divert(PARSE_ARGS)],         201)
113 m4_define([_m4_divert(PARSE_ARGS_END)],     202)
114 m4_define([_m4_divert(HELP)],               300)
115 m4_define([_m4_divert(HELP_MODES)],         301)
116 m4_define([_m4_divert(HELP_TUNING)],        302)
117 m4_define([_m4_divert(HELP_OTHER)],         303)
118 m4_define([_m4_divert(HELP_END)],           304)
119 m4_define([_m4_divert(VERSION)],            350)
120 m4_define([_m4_divert(VERSION_NOTICES)],    351)
121 m4_define([_m4_divert(VERSION_END)],        352)
122 m4_define([_m4_divert(PREPARE_TESTS)],      400)
123 m4_define([_m4_divert(TESTS)],              401)
124 m4_define([_m4_divert(TESTS_END)],          402)
125 m4_define([_m4_divert(TEST_SCRIPT)],        403)
128 # AT_LINE
129 # -------
130 # Return the current file sans directory, a colon, and the current
131 # line.  Be sure to return a _quoted_ file name, so if, for instance,
132 # the user is lunatic enough to have a file named `dnl' (and I, for
133 # one, love to be brainless and stubborn sometimes), then we return a
134 # quoted name.
136 # Gee, we can't use simply
138 #  m4_bpatsubst(__file__, [^.*/\(.*\)], [[\1]])
140 # since then, since `dnl' doesn't match the pattern, it is returned
141 # with once quotation level less, so you lose!  And since GNU M4
142 # is one of the biggest junk in the whole universe wrt regexp, don't
143 # even think about using `?' or `\?'.  Bah, `*' will do.
144 # Pleeeeeeeease, Gary, provide us with dirname and ERE!
145 m4_define([AT_LINE],
146 [m4_bpatsubst(__file__, [^\(.*/\)*\(.*\)], [[\2]]):__line__])
149 # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR)
150 # ------------------------------------------
151 # Normalize SHELL-VAR so that its value has the same number of digits as
152 # all the other test group numbers.
153 m4_define([_AT_NORMALIZE_TEST_GROUP_NUMBER],
155   eval 'while :; do
156     case $$1 in #(
157     '"$at_format"'*) break;;
158     esac
159     $1=0$$1
160   done'
163 # _AT_CREATE_DEBUGGING_SCRIPT
164 # ---------------------------
165 # Create the debugging script $at_group_dir/run which will reproduce the
166 # current test group.
167 m4_define([_AT_CREATE_DEBUGGING_SCRIPT],
168 [         {
169             echo "#! /bin/sh"
170             echo 'test "${ZSH_VERSION+set}" = set && alias -g '\''${1+"$[@]"}'\''='\''"$[@]"'\'''
171             AS_ECHO(["cd '$at_dir'"])
172             AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} $[0] -v -d $at_debug_args $at_group \${1+\"\$[@]\"}"])
173             echo 'exit 1'
174           } >$at_group_dir/run
175           chmod +x $at_group_dir/run
176 ])# _AT_CREATE_DEBUGGING_SCRIPT
179 # AT_INIT([TESTSUITE-NAME])
180 # -------------------------
181 # Begin test suite.
182 m4_define([AT_INIT],
183 [m4_pattern_forbid([^_?AT_])
184 m4_define([AT_TESTSUITE_NAME],
185           m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1], [: $1]))
186 m4_define([AT_ordinal], 0)
187 m4_define([AT_banner_ordinal], 0)
188 m4_define([AT_groups_all], [])
189 m4_define([AT_help_all], [])
190 AS_INIT
191 AT_COPYRIGHT(
192 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
193 Foundation, Inc.
194 This test suite is free software; the Free Software Foundation gives
195 unlimited permission to copy, distribute and modify it.])
196 AS_PREPARE
197 m4_divert_push([DEFAULTS])dnl
199 SHELL=${CONFIG_SHELL-/bin/sh}
201 # How were we run?
202 at_cli_args="$[@]"
204 # Load the config file.
205 for at_file in atconfig atlocal
207   test -r $at_file || continue
208   . ./$at_file || AS_ERROR([invalid content: $at_file])
209 done
211 # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
212 : ${at_top_build_prefix=$at_top_builddir}
214 # atconfig delivers names relative to the directory the test suite is
215 # in, but the groups themselves are run in testsuite-dir/group-dir.
216 if test -n "$at_top_srcdir"; then
217   builddir=../..
218   for at_dir in srcdir top_srcdir top_build_prefix
219   do
220     at_val=AS_VAR_GET([at_$at_dir])
221     case $at_val in
222       [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
223       *) at_prefix=../../ ;;
224     esac
225     AS_VAR_SET([$at_dir], [$at_prefix$at_val])
226   done
229 # Not all shells have the 'times' builtin; the subshell is needed to make
230 # sure we discard the 'times: not found' message from the shell.
231 at_times_p=false
232 (times) >/dev/null 2>&1 && at_times_p=:
234 # CLI Arguments to pass to the debugging scripts.
235 at_debug_args=
236 # -e sets to true
237 at_errexit_p=false
238 # Shall we be verbose?  ':' means no, empty means yes.
239 at_verbose=:
240 at_quiet=
242 # Shall we keep the debug scripts?  Must be `:' when the suite is
243 # run by a debug script, so that the script doesn't remove itself.
244 at_debug_p=false
245 # Display help message?
246 at_help_p=false
247 # Display the version message?
248 at_version_p=false
249 # List test groups?
250 at_list_p=false
251 # Test groups to run
252 at_groups=
254 # The directory we are in.
255 at_dir=`pwd`
256 # The directory the whole suite works in.
257 # Should be absolutely to let the user `cd' at will.
258 at_suite_dir=$at_dir/$as_me.dir
259 # The file containing the suite.
260 at_suite_log=$at_dir/$as_me.log
261 # The file containing the location of the last AT_CHECK.
262 at_check_line_file=$at_suite_dir/at-check-line
263 # The file containing the exit status of the last command.
264 at_status_file=$at_suite_dir/at-status
265 # The files containing the output of the tested commands.
266 at_stdout=$at_suite_dir/at-stdout
267 at_stder1=$at_suite_dir/at-stder1
268 at_stderr=$at_suite_dir/at-stderr
269 # The file containing dates.
270 at_times_file=$at_suite_dir/at-times
271 m4_divert_pop([DEFAULTS])dnl
272 m4_wrap([m4_divert_text([DEFAULTS],
274 # List of the tested programs.
275 at_tested='m4_ifdef([AT_tested], [AT_tested])'
276 # List of the all the test groups.
277 at_groups_all='AT_groups_all'
278 # As many question marks as there are digits in the last test group number.
279 # Used to normalize the test group numbers so that `ls' lists them in
280 # numerical order.
281 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
282 # Description of all the test groups.
283 at_help_all="AS_ESCAPE(m4_defn([AT_help_all]))"])])dnl
284 m4_divert_push([PARSE_ARGS])dnl
286 at_prev=
287 for at_option
289   # If the previous option needs an argument, assign it.
290   if test -n "$at_prev"; then
291     at_option=$at_prev=$at_option
292     at_prev=
293   fi
295   case $at_option in
296   *=*) at_optarg=`expr "x$at_option" : 'x[[^=]]*=\(.*\)'` ;;
297   *)   at_optarg= ;;
298   esac
300   # Accept the important Cygnus configure options, so we can diagnose typos.
302   case $at_option in
303     --help | -h )
304         at_help_p=:
305         ;;
307     --list | -l )
308         at_list_p=:
309         ;;
311     --version | -V )
312         at_version_p=:
313         ;;
315     --clean | -c )
316         test -d "$at_suite_dir" &&
317           find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
318         rm -f -r "$at_suite_dir" "$at_suite_log"
319         exit $?
320         ;;
322     --debug | -d )
323         at_debug_p=:
324         ;;
326     --errexit | -e )
327         at_debug_p=:
328         at_errexit_p=:
329         ;;
331     --verbose | -v )
332         at_verbose=; at_quiet=:
333         ;;
335     --trace | -x )
336         at_traceon='set -x'; at_traceoff='set +x'
337         ;;
339     [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
340         at_groups="$at_groups$at_option "
341         ;;
343     # Ranges
344     [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
345         at_range_start=`echo $at_option |tr -d X-`
346         at_range=`AS_ECHO([" $at_groups_all "]) | \
347           sed -e 's/^.* \('$at_range_start' \)/\1/'`
348         at_groups="$at_groups$at_range "
349         ;;
351     [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
352         at_range_end=`echo $at_option |tr -d X-`
353         at_range=`AS_ECHO([" $at_groups_all "]) | \
354           sed -e 's/\( '$at_range_end'\) .*$/\1/'`
355         at_groups="$at_groups$at_range "
356         ;;
358     [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
359     [[0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9]] | \
360     [[0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
361     [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
362     [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
363     [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
364         at_range_start=`expr $at_option : '\(.*\)-'`
365         at_range_end=`expr $at_option : '.*-\(.*\)'`
366         if test $at_range_start -gt $at_range_end; then
367           at_tmp=$at_range_end
368           at_range_end=$at_range_start
369           at_range_start=$at_tmp
370         fi
371         at_range=`AS_ECHO([" $at_groups_all "]) | \
372           sed -e 's/^.*\( '$at_range_start' \)/\1/' \
373               -e 's/\( '$at_range_end'\) .*$/\1/'`
374         at_groups="$at_groups$at_range "
375         ;;
377     # Keywords.
378     --keywords | -k )
379         at_prev=--keywords
380         ;;
381     --keywords=* )
382         at_groups_selected=$at_help_all
383         at_save_IFS=$IFS
384         IFS=,
385         set X $at_optarg
386         shift
387         IFS=$at_save_IFS
388         for at_keyword
389         do
390           at_invert=
391           case $at_keyword in
392           '!'*)
393             at_invert="-v"
394             at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
395             ;;
396           esac
397           # It is on purpose that we match the test group titles too.
398           at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
399               grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
400         done
401         # Smash the newlines.
402         at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//' |
403           tr "$as_nl" ' '
404         `
405         at_groups="$at_groups$at_groups_selected "
406         ;;
407 m4_divert_pop([PARSE_ARGS])dnl
408 dnl Process *=* last to allow for user specified --option=* type arguments.
409 m4_divert_push([PARSE_ARGS_END])dnl
411     *=*)
412         at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
413         # Reject names that are not valid shell variable names.
414         expr "x$at_envvar" : "[.*[^_$as_cr_alnum]]" >/dev/null &&
415           AS_ERROR([invalid variable name: $at_envvar])
416         at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
417         eval "$at_envvar='$at_value'"
418         export $at_envvar
419         # Propagate to debug scripts.
420         at_debug_args="$at_debug_args $at_envvar='$at_value'"
421         ;;
423      *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
424         AS_ECHO(["Try \`$[0] --help' for more information."]) >&2
425         exit 1
426         ;;
427   esac
428 done
430 # Selected test groups.
431 if test -z "$at_groups"; then
432   at_groups=$at_groups_all
433 else
434   # Sort the tests, removing duplicates:
435   at_groups=`AS_ECHO(["$at_groups"]) | tr ' ' "$as_nl" | sort -nu`
436   # and add banners.  (Passing at_groups_all is tricky--see the comment
437   # starting with "Passing at_groups is tricky.")
438   at_groups=`AS_ECHO(["$at_groups$as_nl $at_groups_all"]) |
439     awk ['BEGIN { FS = "@" } # Effectively switch off field splitting.
440         /^$/ { next }  # Ignore the empty line.
441         !/ / { groups++; selected[$ 0] = 1; next }
442         # The last line, containing at_groups_all.
443         {
444                 n = split($ 0, a, " ")
445                 # If there are several tests, select their banners:
446                 if (groups > 1) {
447                         for (i = 1; i <= n; i++) {
448                                 if (a[i] ~ /^banner-/)
449                                         banner = a[i]
450                                 else if (banner != "" && selected[a[i]] == 1)
451                                         selected[banner] = 1
452                         }
453                 }
454                 for (i = 1; i <= n; i++)
455                         if (selected[a[i]] == 1)
456                                 list = list " " a[i]
457                 print list
458         }']`
460 m4_divert_pop([PARSE_ARGS_END])dnl
461 m4_divert_push([HELP])dnl
463 # Help message.
464 if $at_help_p; then
465   cat <<_ATEOF
466 Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
468 Run all the tests, or the selected TESTS, given by numeric ranges, and
469 save a detailed log file.  Upon failure, create debugging scripts.
471 You should not change environment variables unless explicitly passed
472 as command line arguments.  Set \`AUTOTEST_PATH' to select the executables
473 to exercise.  Each relative directory is expanded as build and source
474 directories relatively to the top level of this distribution.  E.g.,
476   $ $[0] AUTOTEST_PATH=bin
478 possibly amounts into
480   PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH
481 _ATEOF
482 m4_divert_pop([HELP])dnl
483 m4_divert_push([HELP_MODES])dnl
484 cat <<_ATEOF
486 Operation modes:
487   -h, --help     print the help message, then exit
488   -V, --version  print version number, then exit
489   -c, --clean    remove all the files this test suite might create and exit
490   -l, --list     describes all the tests, or the selected TESTS
491 _ATEOF
492 m4_divert_pop([HELP_MODES])dnl
493 m4_divert_push([HELP_TUNING])dnl
494 cat <<_ATEOF
496 Execution tuning:
497   -k, --keywords=KEYWORDS
498                  select the tests matching all the comma-separated KEYWORDS
499                  multiple \`-k' accumulate; prefixed \`!' negates a KEYWORD
500   -e, --errexit  abort as soon as a test fails; implies --debug
501   -v, --verbose  force more detailed output
502                  default for debugging scripts
503   -d, --debug    inhibit clean up and top-level logging
504                  default for debugging scripts
505   -x, --trace    enable tests shell tracing
506 _ATEOF
507 m4_divert_pop([HELP_TUNING])dnl
508 m4_divert_push([HELP_END])dnl
509 cat <<_ATEOF
511 Report bugs to <AT_PACKAGE_BUGREPORT>.
512 _ATEOF
513   exit 0
516 # List of tests.
517 if $at_list_p; then
518   cat <<_ATEOF
519 AT_TESTSUITE_NAME test groups:
521  NUM: FILE-NAME:LINE     TEST-GROUP-NAME
522       KEYWORDS
524 _ATEOF
525   # Passing at_groups is tricky.  We cannot use it to form a literal string
526   # or regexp because of the limitation of AIX awk.  And Solaris' awk
527   # doesn't grok more than 99 fields in a record, so we have to use `split'.
528   AS_ECHO(["$at_groups$as_nl$at_help_all"]) |
529     awk 'BEGIN { FS = ";" }
530          NR == 1 {
531            for (n = split($ 0, a, " "); n; n--) selected[[a[n]]] = 1
532            next
533          }
534          {
535            if (selected[[$ 1]]) {
536              printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
537              if ($ 4) printf "      %s\n", $ 4
538            }
539          }'
540   exit 0
542 m4_divert_pop([HELP_END])dnl
543 m4_divert_push([VERSION])dnl
544 if $at_version_p; then
545   AS_ECHO(["$as_me (AT_PACKAGE_STRING)"])
546   cat <<\_ACEOF
547 m4_divert_pop([VERSION])dnl
548 m4_divert_push([VERSION_END])dnl
549 _ACEOF
550   exit 0
552 m4_divert_pop([VERSION_END])dnl
553 m4_divert_push([PREPARE_TESTS])dnl
555 # Don't take risks: use only absolute directories in PATH.
557 # For stand-alone test suites, AUTOTEST_PATH is relative to `.'.
559 # For embedded test suites, AUTOTEST_PATH is relative to the top level
560 # of the package.  Then expand it into build/src parts, since users
561 # may create executables in both places.
562 AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s&:&$PATH_SEPARATOR&g"`
563 at_path=
564 _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
565 [test -n "$at_path" && at_path=$at_path$PATH_SEPARATOR
566 case $as_dir in
567   [[\\/]]* | ?:[[\\/]]* )
568     at_path=$at_path$as_dir
569     ;;
570   * )
571     if test -z "$at_top_build_prefix"; then
572       # Stand-alone test suite.
573       at_path=$at_path$as_dir
574     else
575       # Embedded test suite.
576       at_path=$at_path$at_top_build_prefix$as_dir$PATH_SEPARATOR
577       at_path=$at_path$at_top_srcdir/$as_dir
578     fi
579     ;;
580 esac])
582 # Now build and simplify PATH.
584 # There might be directories that don't exist, but don't redirect
585 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
586 at_new_path=
587 _AS_PATH_WALK([$at_path],
588 [as_dir=`(cd "$as_dir" && pwd) 2>/dev/null`
589 test -d "$as_dir" || continue
590 case $at_new_path in
591                   $as_dir                 | \
592                   $as_dir$PATH_SEPARATOR* | \
593   *$PATH_SEPARATOR$as_dir                 | \
594   *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR* ) ;;
596   '') at_new_path=$as_dir ;;
597    *) at_new_path=$at_new_path$PATH_SEPARATOR$as_dir ;;
598 esac])
599 PATH=$at_new_path
600 export PATH
602 # Setting up the FDs.
603 # 5 is the log file.  Not to be overwritten if `-d'.
604 m4_define([AS_MESSAGE_LOG_FD], [5])
605 if $at_debug_p; then
606   at_suite_log=/dev/null
607 else
608   : >"$at_suite_log"
610 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
612 # Banners and logs.
613 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
615   AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
616   echo
618   AS_ECHO(["$as_me: command line was:"])
619   AS_ECHO(["  \$ $[0] $at_cli_args"])
620   echo
622   # Try to find a few ChangeLogs in case it might help determining the
623   # exact version.  Use the relative dir: if the top dir is a symlink,
624   # find will not follow it (and options to follow the links are not
625   # portable), which would result in no output here.
626   if test -n "$at_top_srcdir"; then
627     AS_BOX([ChangeLogs.])
628     echo
629     for at_file in `find "$at_top_srcdir" -name ChangeLog -print`
630     do
631       AS_ECHO(["$as_me: $at_file:"])
632       sed 's/^/| /;10q' $at_file
633       echo
634     done
636     AS_UNAME
637     echo
638   fi
640   # Contents of the config files.
641   for at_file in atconfig atlocal
642   do
643     test -r $at_file || continue
644     AS_ECHO(["$as_me: $at_file:"])
645     sed 's/^/| /' $at_file
646     echo
647   done
649   AS_BOX([Tested programs.])
650   echo
651 } >&AS_MESSAGE_LOG_FD
653 # Report what programs are being tested.
654 for at_program in : $at_tested
656   test "$at_program" = : && continue
657   _AS_PATH_WALK([$PATH], [test -f "$as_dir/$at_program" && break])
658   if test -f "$as_dir/$at_program"; then
659     {
660       AS_ECHO(["$at_srcdir/AT_LINE: $as_dir/$at_program --version"])
661       "$as_dir/$at_program" --version
662       echo
663     } >&AS_MESSAGE_LOG_FD 2>&1
664   else
665     AS_ERROR([cannot find $at_program])
666   fi
667 done
670   AS_BOX([Running the tests.])
671 } >&AS_MESSAGE_LOG_FD
673 at_start_date=`date`
674 at_start_time=`date +%s 2>/dev/null`
675 AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
676 at_xpass_list=
677 at_xfail_list=
678 at_pass_list=
679 at_fail_list=
680 at_skip_list=
681 at_group_count=0
682 m4_divert_pop([PREPARE_TESTS])dnl
683 m4_divert_push([TESTS])dnl
685 # Create the master directory if it doesn't already exist.
686 test -d "$at_suite_dir" ||
687   mkdir "$at_suite_dir" ||
688   AS_ERROR([cannot create '$at_suite_dir'])
690 # Can we diff with `/dev/null'?  DU 5.0 refuses.
691 if diff /dev/null /dev/null >/dev/null 2>&1; then
692   at_devnull=/dev/null
693 else
694   at_devnull=$at_suite_dir/devnull
695   >"$at_devnull"
698 # Use `diff -u' when possible.
699 if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
700 then
701   at_diff='diff -u'
702 else
703   at_diff=diff
707 for at_group in $at_groups
709   # Be sure to come back to the top test directory.
710   cd "$at_suite_dir"
712   # Clearly separate the test groups when verbose.
713   test $at_group_count != 0 && $at_verbose echo
715   case $at_group in
716     banner-*)
717       at_group_log=$at_suite_log
718       ;;
720     *)
721       at_group_normalized=$at_group
722       _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
724       # Create a fresh directory for the next test group, and enter.
725       at_group_dir=$at_suite_dir/$at_group_normalized
726       at_group_log=$at_group_dir/$as_me.log
727       if test -d "$at_group_dir"; then
728         find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
729         rm -fr "$at_group_dir" ||
730           AS_WARN([test directory could not be cleaned.])
731       fi
732       # Be tolerant if the above `rm' was not able to remove the directory.
733       AS_MKDIR_P([$at_group_dir])
734       cd $at_group_dir
735       ;;
736   esac
738   echo 0 > "$at_status_file"
740   # In verbose mode, append to the log file *and* show on
741   # the standard output; in quiet mode only write to the log
742   if test -z "$at_verbose"; then
743     at_tee_pipe='tee -a "$at_group_log"'
744   else
745     at_tee_pipe='cat >> "$at_group_log"'
746   fi
748   case $at_group in
749 dnl Test groups inserted here (TESTS).
750 m4_divert_pop([TESTS])[]dnl
751 m4_divert_push([TESTS_END])[]dnl
753   * )
754     AS_ECHO(["$as_me: no such test group: $at_group"]) >&2
755     continue
756     ;;
757   esac
759   # Be sure to come back to the suite directory, in particular
760   # since below we might `rm' the group directory we are in currently.
761   cd "$at_suite_dir"
763   case $at_group in
764     banner-*) ;;
765     *)
766       if test ! -f "$at_check_line_file"; then
767         sed "s/^ */$as_me: warning: /" <<_ATEOF
768         A failure happened in a test group before any test could be
769         run. This means that test suite is improperly designed.  Please
770         report this failure to <AT_PACKAGE_BUGREPORT>.
771 _ATEOF
772         AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
773       fi
774       at_group_count=`expr 1 + $at_group_count`
775       $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
776       AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
777       case $at_xfail:$at_status in
778         yes:0)
779             at_msg="UNEXPECTED PASS"
780             at_xpass_list="$at_xpass_list $at_group"
781             at_errexit=$at_errexit_p
782             ;;
783         no:0)
784             at_msg="ok"
785             at_pass_list="$at_pass_list $at_group"
786             at_errexit=false
787             ;;
788         *:77)
789             at_msg='skipped ('`cat "$at_check_line_file"`')'
790             at_skip_list="$at_skip_list $at_group"
791             at_errexit=false
792             ;;
793         yes:*)
794             at_msg='expected failure ('`cat "$at_check_line_file"`')'
795             at_xfail_list="$at_xfail_list $at_group"
796             at_errexit=false
797             ;;
798         no:*)
799             at_msg='FAILED ('`cat "$at_check_line_file"`')'
800             at_fail_list="$at_fail_list $at_group"
801             at_errexit=$at_errexit_p
802             ;;
803       esac
804       # Make sure there is a separator even with long titles.
805       AS_ECHO([" $at_msg"])
806       at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
807       case $at_status in
808         0|77)
809           # $at_times_file is only available if the group succeeded.
810           # We're not including the group log, so the success message
811           # is written in the global log separately.  But we also
812           # write to the group log in case they're using -d.
813           if test -f "$at_times_file"; then
814             at_log_msg="$at_log_msg     ("`sed 1d "$at_times_file"`')'
815             rm -f "$at_times_file"
816           fi
817           AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
818           AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
820           # Cleanup the group directory, unless the user wants the files.
821           if $at_debug_p ; then
822             _AT_CREATE_DEBUGGING_SCRIPT
823           elif test -d "$at_group_dir"; then
824             find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
825             rm -fr "$at_group_dir"
826           fi
827           ;;
828         *)
829           # Upon failure, include the log into the testsuite's global
830           # log.  The failure message is written in the group log.  It
831           # is later included in the global log.
832           AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
834           # Upon failure, keep the group directory for autopsy, and
835           # create the debugging script.
836           _AT_CREATE_DEBUGGING_SCRIPT
837           $at_errexit && break
838           ;;
839       esac
840       ;;
841   esac
842 done
844 # Back to the top directory.
845 cd "$at_dir"
847 # Compute the duration of the suite.
848 at_stop_date=`date`
849 at_stop_time=`date +%s 2>/dev/null`
850 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
851 case $at_start_time,$at_stop_time in
852   [[0-9]*,[0-9]*])
853     at_duration_s=`expr $at_stop_time - $at_start_time`
854     at_duration_m=`expr $at_duration_s / 60`
855     at_duration_h=`expr $at_duration_m / 60`
856     at_duration_s=`expr $at_duration_s % 60`
857     at_duration_m=`expr $at_duration_m % 60`
858     at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
859     AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
860     ;;
861 esac
863 # Wrap up the test suite with summary statistics.
864 set X $at_skip_list; shift; at_skip_count=$[@%:@]
865 set X $at_fail_list; shift; at_fail_count=$[@%:@]
866 set X $at_xpass_list; shift; at_xpass_count=$[@%:@]
867 set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
869 at_run_count=`expr $at_group_count - $at_skip_count`
870 at_unexpected_count=`expr $at_xpass_count + $at_fail_count`
871 at_total_fail_count=`expr $at_xfail_count + $at_fail_count`
873 echo
874 AS_BOX([Test results.])
875 echo
877   echo
878   AS_BOX([Test results.])
879   echo
880 } >&AS_MESSAGE_LOG_FD
883 dnl FIXME: this code is as far from i18n-cleanness as man
884 dnl could imagine...
886 if test $at_run_count = 1; then
887   at_result="1 test"
888   at_were=was
889 else
890   at_result="$at_run_count tests"
891   at_were=were
893 if $at_errexit_p && test $at_unexpected_count != 0; then
894   if test $at_xpass_count = 1; then
895     at_result="$at_result $at_were run, one passed"
896   else
897     at_result="$at_result $at_were run, one failed"
898   fi
899   at_result="$at_result unexpectedly and inhibited subsequent tests."
900 else
901   # Don't you just love exponential explosion of the number of cases?
902   case $at_xpass_count:$at_fail_count:$at_xfail_count in
903     # So far, so good.
904     0:0:0) at_result="$at_result $at_were successful." ;;
905     0:0:*) at_result="$at_result behaved as expected." ;;
907     # Some unexpected failures
908     0:*:0) at_result="$at_result $at_were run,
909 $at_fail_count failed unexpectedly." ;;
911     # Some failures, both expected and unexpected
912     0:*:1) at_result="$at_result $at_were run,
913 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
914     0:*:*) at_result="$at_result $at_were run,
915 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
917     # No unexpected failures, but some xpasses
918     *:0:*) at_result="$at_result $at_were run,
919 $at_xpass_count passed unexpectedly." ;;
921     # No expected failures, but failures and xpasses
922     *:1:0) at_result="$at_result $at_were run,
923 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failure)." ;;
924     *:*:0) at_result="$at_result $at_were run,
925 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failures)." ;;
927     # All of them.
928     *:*:1) at_result="$at_result $at_were run,
929 $at_xpass_count passed unexpectedly,
930 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
931     *:*:*) at_result="$at_result $at_were run,
932 $at_xpass_count passed unexpectedly,
933 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
934   esac
936   if test $at_skip_count = 0 && test $at_run_count -gt 1; then
937     at_result="All $at_result"
938   fi
941 # Now put skips in the mix.
942 case $at_skip_count in
943   0) ;;
944   1) at_result="$at_result
945 1 test was skipped." ;;
946   *) at_result="$at_result
947 $at_skip_count tests were skipped." ;;
948 esac
950 if test $at_unexpected_count = 0; then
951   echo "$at_result"
952   echo "$at_result" >&AS_MESSAGE_LOG_FD
953 else
954   echo "ERROR: $at_result" >&2
955   echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
956   {
957     echo
958     AS_BOX([Summary of the failures.])
960     # Summary of failed and skipped tests.
961     if test $at_fail_count != 0; then
962       echo "Failed tests:"
963       $SHELL "$[0]" $at_fail_list --list
964       echo
965     fi
966     if test $at_skip_count != 0; then
967       echo "Skipped tests:"
968       $SHELL "$[0]" $at_skip_list --list
969       echo
970     fi
971     if test $at_xpass_count != 0; then
972       echo "Unexpected passes:"
973       $SHELL "$[0]" $at_xpass_list --list
974       echo
975     fi
976     if test $at_fail_count != 0; then
977       AS_BOX([Detailed failed tests.])
978       echo
979       for at_group in $at_fail_list
980       do
981         at_group_normalized=$at_group
982         _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
983         cat "$at_suite_dir/$at_group_normalized/$as_me.log"
984         echo
985       done
986       echo
987     fi
988     if test -n "$at_top_srcdir"; then
989       AS_BOX([${at_top_build_prefix}config.log])
990       sed 's/^/| /' ${at_top_build_prefix}config.log
991       echo
992     fi
993   } >&AS_MESSAGE_LOG_FD
995   AS_BOX([$as_me.log was created.])
997   echo
998   AS_ECHO(["Please send \`${at_testdir+${at_testdir}/}$as_me.log' and all information you think might help:
1000    To: <AT_PACKAGE_BUGREPORT>
1001    Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me:dnl
1002 $at_fail_list${at_fail_list:+ failed${at_xpass_list:+,}}dnl
1003 $at_xpass_list${at_xpass_list:+ passed unexpectedly}
1005   if test $at_debug_p = false; then
1006     echo
1007     echo 'You may investigate any problem if you feel able to do so, in which'
1008     echo 'case the test suite provides a good starting point.  Its output may'
1009     AS_ECHO(["be found below \`${at_testdir+${at_testdir}/}$as_me.dir'."])
1010     echo
1011   fi
1012     exit 1
1015 exit 0
1016 m4_divert_pop([TESTS_END])dnl
1017 dnl End of AT_INIT: divert to KILL, only test groups are to be
1018 dnl output, the rest is ignored.  Current diversion is BODY, inherited
1019 dnl from M4sh.
1020 m4_divert_pop([BODY])
1021 m4_divert_push([KILL])
1022 ])# AT_INIT
1025 # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
1026 #                [ACTION-IF-NOT-GIVEN])
1027 # ---------------------------------------------------------------------------
1028 # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
1029 m4_defun([_AT_ARG_OPTION],
1030 [m4_divert_once([HELP_OTHER],
1031 [cat <<_ATEOF
1033 Other options:
1034 _ATEOF
1035 ])dnl m4_divert_once HELP_OTHER
1036 m4_divert_text([HELP_OTHER],
1037 [cat <<_ATEOF
1039 _ATEOF])dnl
1040 dnl Turn our options into our desired strings
1041 m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
1042 m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
1043 m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
1044 m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
1045 m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
1046 [m4_define_default([AT_first_option],AT_option)dnl
1047 m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
1048 m4_append([AT_case_no],[--no]AT_option, [ | ])dnl
1049 m4_append([AT_case_arg],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
1050 ])dnl m4_foreach AT_option
1051 dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
1052 m4_divert_once([PARSE_ARGS_BEGIN],
1055 ## Set up package specific options.
1057 ])dnl
1058 m4_divert_text([PARSE_ARGS_BEGIN],
1059 [dnl Provide a default value for options without arguments.
1060 m4_ifvaln([$3],,[at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false])dnl
1061 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=false
1062 ])dnl m4_divert_text DEFAULTS
1063 m4_ifval([$3],[m4_divert_once([PARSE_ARGS_END],
1066 ## Verify our last option didn't require an argument
1068 AS_IF([test -n "$at_prev"],[AS_ERROR([`$at_prev' requires an argument.])])])])
1069 m4_divert_text([PARSE_ARGS],
1070 [dnl Parse the options and args when necessary.
1071 m4_ifvaln([$3],
1072 [    AT_case )
1073         at_prev=--m4_bpatsubst([AT_first_option], -, _)
1074         ;;
1075     AT_case_arg )
1076         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=$at_optarg
1077         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1078         $4
1079         ;;],
1080 [    AT_case )
1081         at_optarg=:
1082         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=:
1083         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1084         m4_ifval([$4],[$4])dnl
1085         ;;
1086     AT_case_no )
1087         at_optarg=false
1088         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false
1089         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1090         m4_ifval([$4],[$4])dnl
1091         ;;])dnl m4_ifvaln $3
1092 ])dnl m4_divert_text PARSE_ARGS
1093 m4_ifvaln([$5],
1094 [m4_divert_once([PARSE_ARGS_END],
1097 ## Process package specific options when _not_ supplied.
1098 ##])dnl m4_divert_once PARSE_ARGS_END
1099 m4_divert_text([PARSE_ARGS_END],
1101 AS_IF([$at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)],,[$5])dnl
1102 ])dnl m4_divert_text PARSE_ARGS_END
1103 ])dnl m4_ifvaln $5
1104 ])dnl _AT_ARG_OPTION
1107 # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1108 # ------------------------------------------------------------------------
1109 # Accept a set of OPTIONS with arguments.  Add HELP-TEXT to the HELP_OTHER
1110 # diversion.
1112 # Preceding dashes should not be passed into OPTIONS.  Users will be required
1113 # to pass `--' before long options and `-' before single character options.
1115 # $at_arg_OPTION will be set to `:' if this option is received, `false' if
1116 # if --noOPTION is received, and `false' by default.
1118 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1119 # $at_optarg set to `:' or `false' as appropriate.  $at_optarg is actually
1120 # just a copy of $at_arg_OPTION.
1122 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1123 # if no option from OPTIONS was found.
1124 m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
1127 # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1128 # ---------------------------------------------------------------------------
1129 # Accept a set of OPTIONS with arguments, seperated by commas.  Add HELP-TEXT
1130 # to the HELP_OTHER diversion.
1132 # Preceding dashes should not be passed into OPTIONS.  Users will be required
1133 # to pass `--' before long options and `-' before single character options.
1135 # By default, any argument to these options will be assigned to the shell
1136 # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
1137 # any `-' characters replaced with `_'.
1139 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1140 # $at_optarg set.  $at_optarg is actually just a copy of $at_arg_OPTION.
1142 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1143 # if no option from OPTIONS was found.
1144 m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
1147 # AT_TESTED(PROGRAMS)
1148 # -------------------
1149 # Specify the list of programs exercised by the test suite.  Their
1150 # versions are logged, and in the case of embedded test suite, they
1151 # must correspond to the version of the package.  PATH should be
1152 # already preset so the proper executable will be selected.
1153 m4_define([AT_TESTED],
1154 [m4_append_uniq([AT_tested], [$1], [
1155 ])])
1158 # AT_COPYRIGHT(TEXT)
1159 # ------------------
1160 # Emit TEXT, a copyright notice, in the top of the test suite and in
1161 # --version output.  Macros in TEXT are evaluated once.
1162 m4_define([AT_COPYRIGHT],
1163 [AS_COPYRIGHT([$1])[]dnl
1164 m4_divert_text([VERSION_NOTICES],
1166 $1])])# AT_COPYRIGHT
1169 # AT_SETUP(DESCRIPTION)
1170 # ---------------------
1171 # Start a group of related tests, all to be executed in the same subshell.
1172 # The group is testing what DESCRIPTION says.
1173 m4_define([AT_SETUP],
1174 [m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
1175 m4_ifdef([AT_capture_files], [m4_undefine([AT_capture_files])])
1176 m4_define([AT_line], AT_LINE)
1177 m4_define([AT_xfail], [at_xfail=no])
1178 m4_define([AT_description], [$1])
1179 m4_define([AT_ordinal], m4_incr(AT_ordinal))
1180 m4_append([AT_groups_all], [ ]m4_defn([AT_ordinal]))
1181 m4_divert_push([TESTS])dnl
1182   AT_ordinal ) @%:@ AT_ordinal. m4_defn([AT_line]): $1
1183     at_setup_line='m4_defn([AT_line])'
1184     at_desc="AS_ESCAPE([$1])"
1185     $at_quiet AS_ECHO_N(["m4_format([%3d: %-]m4_eval(47 - m4_qdelta([$1]))[s],
1186                        AT_ordinal, AS_ESCAPE([[$1]]))[]"])
1187 m4_divert_push([TEST_SCRIPT])dnl
1191 # AT_XFAIL_IF(SHELL-EXPRESSION)
1192 # -----------------------------
1193 # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
1194 # true (exitcode = 0).
1195 m4_define([AT_XFAIL_IF],
1196 [dnl
1197 dnl Try to limit the amount of conditionals that we emit.
1198 m4_case([$1],
1199       [], [],
1200       [false], [],
1201       [:], [m4_define([AT_xfail], [at_xfail=yes])],
1202       [true], [m4_define([AT_xfail], [at_xfail=yes])],
1203       [m4_append([AT_xfail], [
1204       $1 && at_xfail=yes])])])
1207 # AT_KEYWORDS(KEYWORDS)
1208 # ---------------------
1209 # Declare a list of keywords associated to the current test group.
1210 m4_define([AT_KEYWORDS],
1211 [m4_append_uniq([AT_keywords], [$1], [ ])])
1214 # AT_CAPTURE_FILE(FILE)
1215 # ---------------------
1216 # If the current test group does not behave as expected, save the contents of
1217 # FILE in the test suite log.
1218 m4_define([AT_CAPTURE_FILE],
1219 [m4_append_uniq([AT_capture_files], ["$1"], [ \
1220 ])])
1223 # AT_CLEANUP
1224 # ----------
1225 # Complete a group of related tests.
1226 m4_define([AT_CLEANUP],
1227 [m4_append([AT_help_all],
1228 m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
1229 )dnl
1230 m4_divert_pop([TEST_SCRIPT])dnl Back to TESTS
1231     AT_xfail
1232     echo "#                             -*- compilation -*-" >> "$at_group_log"
1233     (
1234       AS_ECHO(["AT_ordinal. m4_defn([AT_line]): testing $1..."])
1235       $at_traceon
1236 m4_undivert([TEST_SCRIPT])dnl Insert the code here
1237       $at_traceoff
1238       $at_times_p && times >"$at_times_file"
1239     ) AS_MESSAGE_LOG_FD>&1 2>&1 | eval $at_tee_pipe
1240     at_status=`cat "$at_status_file"`
1241     ;;
1243 m4_divert_pop([TESTS])dnl Back to KILL.
1244 ])# AT_CLEANUP
1247 # AT_BANNER(TEXT)
1248 # ---------------
1249 # Output TEXT without any shell expansion.
1250 m4_define([AT_BANNER],
1251 [m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
1252 m4_append([AT_groups_all], [ banner-]m4_defn([AT_banner_ordinal]))
1253 m4_divert_text([TESTS],
1255   banner-AT_banner_ordinal ) @%:@ Banner AT_banner_ordinal. AT_LINE
1256     cat <<\_ATEOF
1260 _ATEOF
1261     ;;
1262 ])dnl
1263 ])# AT_BANNER
1266 # AT_DATA(FILE, CONTENTS)
1267 # -----------------------
1268 # Initialize an input data FILE with given CONTENTS, which should end with
1269 # an end of line.
1270 # This macro is not robust to active symbols in CONTENTS *on purpose*.
1271 # If you don't want CONTENTS to be evaluated, quote it twice.
1272 m4_define([AT_DATA],
1273 [cat >$1 <<'_ATEOF'
1274 $2[]_ATEOF
1278 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1279 #          [RUN-IF-FAIL], [RUN-IF-PASS])
1280 # ------------------------------------------------
1281 # Execute a test by performing given shell COMMANDS.  These commands
1282 # should normally exit with STATUS, while producing expected STDOUT and
1283 # STDERR contents.  Shell metacharacters in STDOUT and STDERR are
1284 # _not_ processed by the shell, but are treated as string literals.
1286 # STATUS, STDOUT, and STDERR are not checked if equal to `ignore'.
1288 # If STDOUT is `expout', then stdout is compared to the content of the file
1289 # `expout'.  Likewise for STDERR and `experr'.
1291 # If STDOUT is `stdout', then the stdout is left in the file `stdout',
1292 # likewise for STDERR and `stderr'.  Don't do this:
1294 #    AT_CHECK([command >out])
1295 #    # Some checks on `out'
1297 # do this instead:
1299 #    AT_CHECK([command], [], [stdout])
1300 #    # Some checks on `stdout'
1302 # This is an unfortunate limitation inherited from Ultrix which will not
1303 # let you redirect several times the same FD (see the Autoconf documentation).
1304 # If you use the `AT_CHECK([command >out])' be sure to get a test suite
1305 # that will show spurious failures.
1307 # You might wonder why not just use `ignore' and directly use stdout and
1308 # stderr left by the test suite.  Firstly because the names of these files
1309 # is an internal detail, and secondly, because
1311 #    AT_CHECK([command], [], [ignore])
1312 #    AT_CHECK([check stdout])
1314 # will use `stdout' both in input and output: undefined behavior would
1315 # certainly result.  That's why the test suite will save them in `at-stdout'
1316 # and `at-stderr', and will provide you with `stdout' and `stderr'.
1318 # Any line of stderr starting with leading blanks and a `+' are filtered
1319 # out, since most shells when tracing include subshell traces in stderr.
1320 # This may cause spurious failures when the test suite is run with `-x'.
1322 m4_define([AT_CHECK],
1323 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6],1)])
1325 # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1326 #                   [RUN-IF-FAIL], [RUN-IF-PASS])
1327 # ---------------------------------------------------------
1328 # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
1329 # and STDERR arguments before running the comparison.
1330 m4_define([AT_CHECK_NOESCAPE],
1331 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6])])
1334 # _AT_DECIDE_TRACEABLE(COMMANDS)
1335 # ------------------------------
1336 # Worker for for _AT_CHECK that expands to shell code.  If COMMANDS are safe to
1337 # trace with `set -x', the shell code will set `at_trace_this=yes'.  Otherwise,
1338 # the shell code will print a message stating an aspect of COMMANDS that makes
1339 # tracing them unsafe.
1341 # Tracing COMMANDS is not safe if they contain a command that spans multiple
1342 # lines.  When the test suite user passes `-x' or `--trace', the test suite
1343 # precedes every command with a `set -x'.  Since most tests expect a specific
1344 # stderr, if only to confirm that it is empty, the test suite filters ^+ from
1345 # the captured stderr before comparing with the expected stderr.  If a command
1346 # spans multiple lines, so will its trace, but a `+' only prefixes the first
1347 # line of that trace:
1349 # $ echo 'foo
1350 # bar'
1351 # => stdout
1352 # foo
1353 # bar
1354 # => stderr
1355 # + foo
1356 # bar
1358 # In a subset of cases, one could filter such extended shell traces from stderr.
1359 # Since test commands spanning several lines are rare, I chose instead to simply
1360 # not trace COMMANDS that could yield multiple trace lines.  Distinguishing such
1361 # COMMANDS became the task at hand.
1363 # These features may cause a shell command to span multiple lines:
1365 # (a) A quoted literal newline.
1366 # Example:
1367 #   echo foo'
1368 #   'bar
1369 # M4 is a hostile language for the job of parsing COMMANDS to determine whether
1370 # each literal newline is quoted, so we simply disable tracing for all COMMANDS
1371 # that bear literal newlines.
1373 # (b) A command substitution not subject to word splitting.
1374 # Example:
1375 #   var=$(printf 'foo\nbar')
1376 # Example:
1377 #   echo "`printf 'foo\\nbar`"
1378 # One cannot know in general the number of lines a command substitution will
1379 # yield without executing the substituted command.  As such, we disable tracing
1380 # for all COMMANDS containing these constructs.
1382 # (c) A parameter expansion not subject to word splitting.
1383 # Example:
1384 #   var=foo'
1385 #   'bar
1386 #   echo "$var"
1387 # Parameter expansions appear in COMMANDS with much greater frequency than do
1388 # newlines and command substitutions, so disabling tracing for all such COMMANDS
1389 # would much more substantially devalue `testsuite -x'.  To determine which
1390 # parameter expansions yield multiple lines, we escape all ``', `"', and `\' in
1391 # a copy of COMMANDS and expand that string within double quotes at runtime.  If
1392 # the result of that expansion contains multiple lines, the test suite disables
1393 # tracing for the command in question.
1395 # This method leads the test suite to expand some parameters that the shell
1396 # itself will never expand due to single-quotes or backslash escapes.  This is
1397 # not a problem for `$foo' expansions, which will simply yield the empty string
1398 # or some unrelated value.  A `${...}' expansion could actually form invalid
1399 # shell code, however; consider `${=foo}'.  Therefore, we disable tracing for
1400 # all COMMANDS containing `${...}'.  This affects few COMMANDS.
1402 # This macro falls in a very hot path; the Autoconf test suite expands it 1640
1403 # times as of this writing.  To give a sense of the impact of the heuristics I
1404 # just described, the test suite preemptively disables tracing for 31 of those,
1405 # and 268 contain parameter expansions that require runtime evaluation.  The
1406 # balance are always safe to trace.
1408 # _AT_CHECK expands COMMANDS, but the Autoconf language does not provide a way
1409 # to safely expand arbitrary COMMANDS in an argument list, so the below tests
1410 # examine COMMANDS unexpanded.
1411 m4_define([_AT_DECIDE_TRACEABLE],
1412 [dnl Utility macros.
1413 m4_pushdef([at_lf], [
1414 ])[]dnl
1416 dnl Examine COMMANDS for a reason to never trace COMMANDS.
1417 m4_pushdef([at_reason],
1418            m4_bmatch([$1],
1419                      [`.*`], [[a `...` command substitution]],
1420                      [\$(],  [[a $(...) command substitution]],
1421                      [\${],  [[a ${...} parameter expansion]],
1422                      at_lf,  [[an embedded newline]],
1423                      [[]]dnl No reason.
1424 ))dnl
1426 m4_ifval(m4_defn([at_reason]),
1427 [echo 'Not enabling shell tracing (command contains ]m4_defn([at_reason])[)'],
1428 [m4_bmatch([$1], [\$],
1429 dnl COMMANDS may contain parameter expansions; expand them at runtime.
1430 [case "AS_ESCAPE([$1], [`\"])" in
1431         *'
1432 '*) echo 'Not enabling shell tracing (command contains an embedded newline)' ;;
1433  *) at_trace_this=yes ;;
1434     esac],
1435 dnl We know at build time that tracing COMMANDS is always safe.
1436 [at_trace_this=yes])])[]dnl
1437 m4_popdef([at_lf])[]dnl
1438 m4_popdef([at_reason])])
1441 # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1442 #           [RUN-IF-FAIL], [RUN-IF-PASS], SHELL_ESCAPE_IO)
1443 # ---------------------------------------------------------
1444 # Worker for AT_CHECK & AT_CHECK_NOESCAPE.  The final SHELL-ESCAPE-IO
1445 # argument determines whether the STDOUT & STDERR arguments will be escaped or
1446 # not.
1449 # Implementation Details
1450 # ----------------------
1451 # Ideally, we would like to run
1453 #    ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
1455 # but we must group COMMANDS as it is not limited to a single command, and
1456 # then the shells will save the traces in at-stderr. So we have to filter
1457 # them out when checking stderr, and we must send them into the test suite's
1458 # stderr to honor -x properly. Since only the first line of the trace of a
1459 # multiline command starts with a `+', and I know of no straightforward way to
1460 # filter out the unadorned trace lines, we disable shell tracing entirely for
1461 # commands that could span multiple lines.
1463 # Limiting COMMANDS to a single command is not good either, since them
1464 # the user herself would use {} or (), and then we face the same problem.
1466 # But then, there is no point in running
1468 #   ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
1470 # instead of the simpler
1472 #  ( $at_traceon; $1 ) >at-stdout 2>at-stder1
1474 m4_define([_AT_CHECK],
1475 [$at_traceoff
1476 AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([$1])"])
1477 echo AT_LINE >"$at_check_line_file"
1479 at_trace_this=
1480 if test -n "$at_traceon"; then
1481     _AT_DECIDE_TRACEABLE([$1])
1484 if test -n "$at_trace_this"; then
1485     ( $at_traceon; $1 ) >"$at_stdout" 2>"$at_stder1"
1486     at_status=$?
1487     grep '^ *+' "$at_stder1" >&2
1488     grep -v '^ *+' "$at_stder1" >"$at_stderr"
1489 else
1490     ( :; $1 ) >"$at_stdout" 2>"$at_stderr"
1491     at_status=$?
1494 at_failed=false
1495 dnl Check stderr.
1496 m4_case([$4],
1497         stderr, [echo stderr:; tee stderr <"$at_stderr"],
1498         ignore, [echo stderr:; cat "$at_stderr"],
1499         experr, [$at_diff experr "$at_stderr" || at_failed=:],
1500         [],     [$at_diff "$at_devnull" "$at_stderr" || at_failed=:],
1501         [echo >>"$at_stderr"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$4])],[$4])"]) | $at_diff - "$at_stderr" || at_failed=:])
1502 dnl Check stdout.
1503 m4_case([$3],
1504         stdout, [echo stdout:; tee stdout <"$at_stdout"],
1505         ignore, [echo stdout:; cat "$at_stdout"],
1506         expout, [$at_diff expout "$at_stdout" || at_failed=:],
1507         [],     [$at_diff "$at_devnull" "$at_stdout" || at_failed=:],
1508         [echo >>"$at_stdout"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$3])],[$3])"]) | $at_diff - "$at_stdout" || at_failed=:])
1509 dnl Check exit val.  Don't `skip' if we are precisely checking $? = 77.
1510 case $at_status in
1511 m4_if([$2], [77],
1512     [],
1513     [   77) echo 77 > "$at_status_file"; exit 77;;
1514 ])dnl
1515 m4_if([$2], [ignore],
1516     [   *);;],
1517     [   m4_default([$2], [0])) ;;
1518    *) AS_ECHO(["$at_srcdir/AT_LINE: exit code was $at_status, expected m4_default([$2], [0])"])
1519       at_failed=:;;])
1520 esac
1521 AS_IF($at_failed, [$5
1522   m4_ifdef([AT_capture_files],
1523     [for file in AT_capture_files
1524      do AS_ECHO(["$file:"]); sed 's/^/> /' "$file"; done])
1525   echo 1 > "$at_status_file"
1526   exit 1], [$6])
1527 $at_traceon
1528 ])# _AT_CHECK