Kill trailing whitespace.
[autoconf/ericb.git] / lib / autotest / general.m4
blobf94b10c7e66460c81082b3856618cedfc63ef8a4
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 collector for code for each test, the ``normal'' diversion, but
109 #    undiverted into other locations before final output.
111 #  - TEST_FUNCTIONS
112 #    Series of functions for each test group.  The functions deliberately
113 #    occur after the end of the shell script, so that the shell need not
114 #    spend time parsing functions it will not execute.
116 m4_define([_m4_divert(DEFAULTS)],           100)
117 m4_define([_m4_divert(PARSE_ARGS_BEGIN)],   200)
118 m4_define([_m4_divert(PARSE_ARGS)],         201)
119 m4_define([_m4_divert(PARSE_ARGS_END)],     202)
120 m4_define([_m4_divert(HELP)],               300)
121 m4_define([_m4_divert(HELP_MODES)],         301)
122 m4_define([_m4_divert(HELP_TUNING)],        302)
123 m4_define([_m4_divert(HELP_OTHER)],         303)
124 m4_define([_m4_divert(HELP_END)],           304)
125 m4_define([_m4_divert(VERSION)],            350)
126 m4_define([_m4_divert(VERSION_NOTICES)],    351)
127 m4_define([_m4_divert(VERSION_END)],        352)
128 m4_define([_m4_divert(PREPARE_TESTS)],      400)
129 m4_define([_m4_divert(TESTS)],              401)
130 m4_define([_m4_divert(TESTS_END)],          402)
131 m4_define([_m4_divert(TEST_SCRIPT)],        403)
132 m4_define([_m4_divert(TEST_FUNCTIONS)],     500)
135 # AT_LINE
136 # -------
137 # Return the current file sans directory, a colon, and the current
138 # line.  Be sure to return a _quoted_ file name, so if, for instance,
139 # the user is lunatic enough to have a file named `dnl' (and I, for
140 # one, love to be brainless and stubborn sometimes), then we return a
141 # quoted name.
143 # Gee, we can't use simply
145 #  m4_bpatsubst(__file__, [^.*/\(.*\)], [[\1]])
147 # since then, since `dnl' doesn't match the pattern, it is returned
148 # with once quotation level less, so you lose!  And since GNU M4
149 # is one of the biggest junk in the whole universe wrt regexp, don't
150 # even think about using `?' or `\?'.  Bah, `*' will do.
151 # Pleeeeeeeease, Gary, provide us with dirname and ERE!
153 # M4 recompiles the regular expression for every m4_bpatsubst, but __file__
154 # rarely changes.  Be fast - only compute the dirname when necessary; for
155 # autoconf alone, this shaves off several seconds in building testsuite.
156 m4_define([_AT_LINE_file])
157 m4_define([_AT_LINE_base])
158 m4_define([AT_LINE],
159 [m4_if(m4_defn([_AT_LINE_file]), __file__, [],
160        [m4_do([m4_define([_AT_LINE_file], __file__)],
161               [m4_define([_AT_LINE_base],
162                          m4_bpatsubst(__file__, [^.*/\([^/]*\)$],
163                                       [[\1]]))])])dnl
164 m4_defn([_AT_LINE_base]):__line__])
167 # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR)
168 # ------------------------------------------
169 # Normalize SHELL-VAR so that its value has the same number of digits as
170 # all the other test group numbers.
171 m4_define([_AT_NORMALIZE_TEST_GROUP_NUMBER],
173   eval 'while :; do
174     case $$1 in #(
175     '"$at_format"'*) break;;
176     esac
177     $1=0$$1
178   done'
181 # _AT_CREATE_DEBUGGING_SCRIPT
182 # ---------------------------
183 # Create the debugging script $at_group_dir/run which will reproduce the
184 # current test group.
185 m4_define([_AT_CREATE_DEBUGGING_SCRIPT],
187             echo "#! /bin/sh"
188             echo 'test "${ZSH_VERSION+set}" = set && alias -g '\''${1+"$[@]"}'\''='\''"$[@]"'\'''
189             AS_ECHO(["cd '$at_dir'"])
190             AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} $[0] -v -d $at_debug_args $at_group \${1+\"\$[@]\"}"])
191             echo 'exit 1'
192           } >$at_group_dir/run
193           chmod +x $at_group_dir/run
194 ])# _AT_CREATE_DEBUGGING_SCRIPT
197 # AT_INIT([TESTSUITE-NAME])
198 # -------------------------
199 # Begin test suite.
200 m4_define([AT_INIT],
201 [m4_pattern_forbid([^_?AT_])
202 m4_define([AT_TESTSUITE_NAME],
203           m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1], [: $1]))
204 m4_define([AT_ordinal], 0)
205 m4_define([AT_banner_ordinal], 0)
206 m4_define([AT_groups_all], [])
207 m4_define([AT_help_all], [])
208 AS_INIT[]dnl
209 m4_divert_push([DEFAULTS])dnl
210 AT_COPYRIGHT(
211 [Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
212 Foundation, Inc.
213 This test suite is free software; the Free Software Foundation gives
214 unlimited permission to copy, distribute and modify it.])
215 AS_PREPARE
217 SHELL=${CONFIG_SHELL-/bin/sh}
219 # How were we run?
220 at_cli_args="$[@]"
222 ## --------------- ##
223 ## Shell functions ##
224 ## --------------- ##
226 # at_func_check_newline COMMAND
227 # Test if COMMAND includes a newline and, if so, print a message and return exit code 1
228 at_func_check_newline ()
230   case "$[1]" in
231  *'
232 '*) echo 'Not enabling shell tracing (command contains an embedded newline)' ; return 1 ;;
233  *) return 0 ;;
234   esac
237 # at_func_filter_trace EXIT-CODE
238 # Split the contents of file "$at_stder1" into the "set -x" trace (on stderr) and
239 # the other lines (on file "$at_stderr").  Return the exit code EXIT-CODE.
240 at_func_filter_trace ()
242   grep '^ *+' "$at_stder1" >&2
243   grep -v '^ *+' "$at_stder1" >"$at_stderr"
244   return $[1]
247 # at_func_log_failure FILE-LIST
248 # Copy the files in the list on stdout with a "> " prefix, and exit the shell
249 # with a failure exit code.
250 at_func_log_failure ()
252   for file
253    do AS_ECHO(["$file:"]); sed 's/^/> /' "$file"; done
254   echo 1 > "$at_status_file"
255   exit 1
258 # at_func_check_skip EXIT-CODE
259 # Check whether EXIT-CODE is the special exit code 77, and if so exit the shell
260 # with that same exit code.
261 at_func_check_skip ()
263   case $[1] in
264     77) echo 77 > "$at_status_file"; exit 77;;
265   esac
268 # at_func_check_status EXPECTED EXIT-CODE LINE
269 # Check whether EXIT-CODE is the expected exit code, and if so do nothing.  Else,
270 # if it is 77 exit the shell with that same exit code; if it is anything else
271 # print an error message and fail the test.
272 at_func_check_status ()
274   dnl This order ensures that we don't `skip' if we are precisely checking $? = 77.
275   case $[2] in
276     $[1] ) ;;
277     77) echo 77 > "$at_status_file"; exit 77;;
278     *) AS_ECHO(["$[3]: exit code was $[2], expected $[1]"])
279       at_failed=:;;
280   esac
283 # at_func_diff_devnull FILE
284 # Emit a diff between /dev/null and FILE.  Uses "test -s" to avoid useless
285 # diff invocations.
286 at_func_diff_devnull ()
288   test -s "$[1]" || return 0
289   $at_diff "$at_devnull" "$[1]"
292 # at_func_test NUMBER
293 # -------------------
294 # Parse out test NUMBER from the tail of this file.
295 at_func_test ()
297   sed -n '/^@%:@AT_START_'$[1]'$/,/^@%:@AT_STOP_'$[1]'$/p' "$at_myself" \
298        > "$at_test_source"
301 # Load the config file.
302 for at_file in atconfig atlocal
304   test -r $at_file || continue
305   . ./$at_file || AS_ERROR([invalid content: $at_file])
306 done
308 # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
309 : ${at_top_build_prefix=$at_top_builddir}
311 # atconfig delivers names relative to the directory the test suite is
312 # in, but the groups themselves are run in testsuite-dir/group-dir.
313 if test -n "$at_top_srcdir"; then
314   builddir=../..
315   for at_dir in srcdir top_srcdir top_build_prefix
316   do
317     at_val=AS_VAR_GET([at_$at_dir])
318     case $at_val in
319       [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
320       *) at_prefix=../../ ;;
321     esac
322     AS_VAR_SET([$at_dir], [$at_prefix$at_val])
323   done
326 # Not all shells have the 'times' builtin; the subshell is needed to make
327 # sure we discard the 'times: not found' message from the shell.
328 at_times_p=false
329 (times) >/dev/null 2>&1 && at_times_p=:
331 # CLI Arguments to pass to the debugging scripts.
332 at_debug_args=
333 # -e sets to true
334 at_errexit_p=false
335 # Shall we be verbose?  ':' means no, empty means yes.
336 at_verbose=:
337 at_quiet=
339 # Shall we keep the debug scripts?  Must be `:' when the suite is
340 # run by a debug script, so that the script doesn't remove itself.
341 at_debug_p=false
342 # Display help message?
343 at_help_p=false
344 # Display the version message?
345 at_version_p=false
346 # List test groups?
347 at_list_p=false
348 # Test groups to run
349 at_groups=
351 # The directory we are in.
352 at_dir=`pwd`
353 # An absolute reference to this testsuite script.
354 dnl m4-double quote, to preserve []
355 [case $as_myself in
356   [\\/]* | ?:[\\/]* ) at_myself=$as_myself ;;
357   * ) at_myself=$at_dir/$as_myself ;;
358 esac]
359 # The directory the whole suite works in.
360 # Should be absolute to let the user `cd' at will.
361 at_suite_dir=$at_dir/$as_me.dir
362 # The file containing the suite.
363 at_suite_log=$at_dir/$as_me.log
364 # The file containing the location of the last AT_CHECK.
365 at_check_line_file=$at_suite_dir/at-check-line
366 # The file containing the exit status of the last command.
367 at_status_file=$at_suite_dir/at-status
368 # The files containing the output of the tested commands.
369 at_stdout=$at_suite_dir/at-stdout
370 at_stder1=$at_suite_dir/at-stder1
371 at_stderr=$at_suite_dir/at-stderr
372 # The file containing the function to run a test group.
373 at_test_source=$at_suite_dir/at-test-source
374 # The file containing dates.
375 at_times_file=$at_suite_dir/at-times
376 m4_divert_pop([DEFAULTS])dnl
377 m4_wrap([m4_divert_text([DEFAULTS],
379 # List of the tested programs.
380 at_tested='m4_ifdef([AT_tested], [AT_tested])'
381 # List of the all the test groups.
382 at_groups_all='AT_groups_all'
383 # As many question marks as there are digits in the last test group number.
384 # Used to normalize the test group numbers so that `ls' lists them in
385 # numerical order.
386 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
387 # Description of all the test groups.
388 at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"])])dnl
389 m4_divert_push([PARSE_ARGS])dnl
391 at_prev=
392 for at_option
394   # If the previous option needs an argument, assign it.
395   if test -n "$at_prev"; then
396     at_option=$at_prev=$at_option
397     at_prev=
398   fi
400   case $at_option in
401   *=*) at_optarg=`expr "x$at_option" : 'x[[^=]]*=\(.*\)'` ;;
402   *)   at_optarg= ;;
403   esac
405   # Accept the important Cygnus configure options, so we can diagnose typos.
407   case $at_option in
408     --help | -h )
409         at_help_p=:
410         ;;
412     --list | -l )
413         at_list_p=:
414         ;;
416     --version | -V )
417         at_version_p=:
418         ;;
420     --clean | -c )
421         test -d "$at_suite_dir" &&
422           find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
423         rm -f -r "$at_suite_dir" "$at_suite_log"
424         exit $?
425         ;;
427     --debug | -d )
428         at_debug_p=:
429         ;;
431     --errexit | -e )
432         at_debug_p=:
433         at_errexit_p=:
434         ;;
436     --verbose | -v )
437         at_verbose=; at_quiet=:
438         ;;
440     --trace | -x )
441         at_traceon='set -x'; at_traceoff='set +x'
442         ;;
444     [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
445         at_groups="$at_groups$at_option "
446         ;;
448     # Ranges
449     [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
450         at_range_start=`echo $at_option |tr -d X-`
451         at_range=`AS_ECHO([" $at_groups_all "]) | \
452           sed -e 's/^.* \('$at_range_start' \)/\1/'`
453         at_groups="$at_groups$at_range "
454         ;;
456     [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
457         at_range_end=`echo $at_option |tr -d X-`
458         at_range=`AS_ECHO([" $at_groups_all "]) | \
459           sed -e 's/\( '$at_range_end'\) .*$/\1/'`
460         at_groups="$at_groups$at_range "
461         ;;
463     [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
464     [[0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9]] | \
465     [[0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
466     [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
467     [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
468     [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
469         at_range_start=`expr $at_option : '\(.*\)-'`
470         at_range_end=`expr $at_option : '.*-\(.*\)'`
471         if test $at_range_start -gt $at_range_end; then
472           at_tmp=$at_range_end
473           at_range_end=$at_range_start
474           at_range_start=$at_tmp
475         fi
476         at_range=`AS_ECHO([" $at_groups_all "]) | \
477           sed -e 's/^.*\( '$at_range_start' \)/\1/' \
478               -e 's/\( '$at_range_end'\) .*$/\1/'`
479         at_groups="$at_groups$at_range "
480         ;;
482     # Keywords.
483     --keywords | -k )
484         at_prev=--keywords
485         ;;
486     --keywords=* )
487         at_groups_selected=$at_help_all
488         at_save_IFS=$IFS
489         IFS=,
490         set X $at_optarg
491         shift
492         IFS=$at_save_IFS
493         for at_keyword
494         do
495           at_invert=
496           case $at_keyword in
497           '!'*)
498             at_invert="-v"
499             at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
500             ;;
501           esac
502           # It is on purpose that we match the test group titles too.
503           at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
504               grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
505         done
506         # Smash the newlines.
507         at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//' |
508           tr "$as_nl" ' '
509         `
510         at_groups="$at_groups$at_groups_selected "
511         ;;
512 m4_divert_pop([PARSE_ARGS])dnl
513 dnl Process *=* last to allow for user specified --option=* type arguments.
514 m4_divert_push([PARSE_ARGS_END])dnl
516     *=*)
517         at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
518         # Reject names that are not valid shell variable names.
519         expr "x$at_envvar" : "[.*[^_$as_cr_alnum]]" >/dev/null &&
520           AS_ERROR([invalid variable name: $at_envvar])
521         at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
522         eval "$at_envvar='$at_value'"
523         export $at_envvar
524         # Propagate to debug scripts.
525         at_debug_args="$at_debug_args $at_envvar='$at_value'"
526         ;;
528      *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
529         AS_ECHO(["Try \`$[0] --help' for more information."]) >&2
530         exit 1
531         ;;
532   esac
533 done
535 # Selected test groups.
536 if test -z "$at_groups"; then
537   at_groups=$at_groups_all
538 else
539   # Sort the tests, removing duplicates:
540   at_groups=`AS_ECHO(["$at_groups"]) | tr ' ' "$as_nl" | sort -nu`
541   # and add banners.  (Passing at_groups_all is tricky--see the comment
542   # starting with "Passing at_groups is tricky.")
543   at_groups=`AS_ECHO(["$at_groups$as_nl $at_groups_all"]) |
544     awk ['BEGIN { FS = "@" } # Effectively switch off field splitting.
545         /^$/ { next }  # Ignore the empty line.
546         !/ / { groups++; selected[$ 0] = 1; next }
547         # The last line, containing at_groups_all.
548         {
549                 n = split($ 0, a, " ")
550                 # If there are several tests, select their banners:
551                 if (groups > 1) {
552                         for (i = 1; i <= n; i++) {
553                                 if (a[i] ~ /^banner-/)
554                                         banner = a[i]
555                                 else if (banner != "" && selected[a[i]] == 1)
556                                         selected[banner] = 1
557                         }
558                 }
559                 for (i = 1; i <= n; i++)
560                         if (selected[a[i]] == 1)
561                                 list = list " " a[i]
562                 print list
563         }']`
565 m4_divert_pop([PARSE_ARGS_END])dnl
566 m4_divert_push([HELP])dnl
568 # Help message.
569 if $at_help_p; then
570   cat <<_ATEOF
571 Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
573 Run all the tests, or the selected TESTS, given by numeric ranges, and
574 save a detailed log file.  Upon failure, create debugging scripts.
576 You should not change environment variables unless explicitly passed
577 as command line arguments.  Set \`AUTOTEST_PATH' to select the executables
578 to exercise.  Each relative directory is expanded as build and source
579 directories relatively to the top level of this distribution.  E.g.,
581   $ $[0] AUTOTEST_PATH=bin
583 possibly amounts into
585   PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH
586 _ATEOF
587 m4_divert_pop([HELP])dnl
588 m4_divert_push([HELP_MODES])dnl
589 cat <<_ATEOF
591 Operation modes:
592   -h, --help     print the help message, then exit
593   -V, --version  print version number, then exit
594   -c, --clean    remove all the files this test suite might create and exit
595   -l, --list     describes all the tests, or the selected TESTS
596 _ATEOF
597 m4_divert_pop([HELP_MODES])dnl
598 m4_divert_push([HELP_TUNING])dnl
599 cat <<_ATEOF
601 dnl extra quoting prevents emacs whitespace mode from putting tabs in output
602 Execution tuning:
603   -k, --keywords=KEYWORDS
604 [                 select the tests matching all the comma-separated KEYWORDS]
605 [                 multiple \`-k' accumulate; prefixed \`!' negates a KEYWORD]
606   -e, --errexit  abort as soon as a test fails; implies --debug
607   -v, --verbose  force more detailed output
608 [                 default for debugging scripts]
609   -d, --debug    inhibit clean up and top-level logging
610 [                 default for debugging scripts]
611   -x, --trace    enable tests shell tracing
612 _ATEOF
613 m4_divert_pop([HELP_TUNING])dnl
614 m4_divert_push([HELP_END])dnl
615 cat <<_ATEOF
617 Report bugs to <AT_PACKAGE_BUGREPORT>.
618 _ATEOF
619   exit 0
622 # List of tests.
623 if $at_list_p; then
624   cat <<_ATEOF
625 AT_TESTSUITE_NAME test groups:
627  NUM: FILE-NAME:LINE     TEST-GROUP-NAME
628       KEYWORDS
630 _ATEOF
631   # Passing at_groups is tricky.  We cannot use it to form a literal string
632   # or regexp because of the limitation of AIX awk.  And Solaris' awk
633   # doesn't grok more than 99 fields in a record, so we have to use `split'.
634   AS_ECHO(["$at_groups$as_nl$at_help_all"]) |
635     awk 'BEGIN { FS = ";" }
636          NR == 1 {
637            for (n = split($ 0, a, " "); n; n--) selected[[a[n]]] = 1
638            next
639          }
640          {
641            if (selected[[$ 1]]) {
642              printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
643              if ($ 4) printf "      %s\n", $ 4
644            }
645          }'
646   exit 0
648 m4_divert_pop([HELP_END])dnl
649 m4_divert_push([VERSION])dnl
650 if $at_version_p; then
651   AS_ECHO(["$as_me (AT_PACKAGE_STRING)"])
652   cat <<\_ACEOF
653 m4_divert_pop([VERSION])dnl
654 m4_divert_push([VERSION_END])dnl
655 _ACEOF
656   exit 0
658 m4_divert_pop([VERSION_END])dnl
659 m4_divert_push([PREPARE_TESTS])dnl
661 # Don't take risks: use only absolute directories in PATH.
663 # For stand-alone test suites, AUTOTEST_PATH is relative to `.'.
665 # For embedded test suites, AUTOTEST_PATH is relative to the top level
666 # of the package.  Then expand it into build/src parts, since users
667 # may create executables in both places.
668 AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s|:|$PATH_SEPARATOR|g"`
669 at_path=
670 _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
671 [test -n "$at_path" && at_path=$at_path$PATH_SEPARATOR
672 case $as_dir in
673   [[\\/]]* | ?:[[\\/]]* )
674     at_path=$at_path$as_dir
675     ;;
676   * )
677     if test -z "$at_top_build_prefix"; then
678       # Stand-alone test suite.
679       at_path=$at_path$as_dir
680     else
681       # Embedded test suite.
682       at_path=$at_path$at_top_build_prefix$as_dir$PATH_SEPARATOR
683       at_path=$at_path$at_top_srcdir/$as_dir
684     fi
685     ;;
686 esac])
688 # Now build and simplify PATH.
690 # There might be directories that don't exist, but don't redirect
691 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
692 at_new_path=
693 _AS_PATH_WALK([$at_path],
694 [as_dir=`(cd "$as_dir" && pwd) 2>/dev/null`
695 test -d "$as_dir" || continue
696 case $PATH_SEPARATOR$at_new_path$PATH_SEPARATOR in
697   *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR*) ;;
698   $PATH_SEPARATOR$PATH_SEPARATOR) at_new_path=$as_dir ;;
699   *) at_new_path=$at_new_path$PATH_SEPARATOR$as_dir ;;
700 esac])
701 PATH=$at_new_path
702 export PATH
704 # Setting up the FDs.
705 # 5 is the log file.  Not to be overwritten if `-d'.
706 m4_define([AS_MESSAGE_LOG_FD], [5])
707 if $at_debug_p; then
708   at_suite_log=/dev/null
709 else
710   : >"$at_suite_log"
712 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
714 # Banners and logs.
715 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
717   AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
718   echo
720   AS_ECHO(["$as_me: command line was:"])
721   AS_ECHO(["  \$ $[0] $at_cli_args"])
722   echo
724   # Try to find a few ChangeLogs in case it might help determining the
725   # exact version.  Use the relative dir: if the top dir is a symlink,
726   # find will not follow it (and options to follow the links are not
727   # portable), which would result in no output here.
728   if test -n "$at_top_srcdir"; then
729     AS_BOX([ChangeLogs.])
730     echo
731     for at_file in `find "$at_top_srcdir" -name ChangeLog -print`
732     do
733       AS_ECHO(["$as_me: $at_file:"])
734       sed 's/^/| /;10q' $at_file
735       echo
736     done
738     AS_UNAME
739     echo
740   fi
742   # Contents of the config files.
743   for at_file in atconfig atlocal
744   do
745     test -r $at_file || continue
746     AS_ECHO(["$as_me: $at_file:"])
747     sed 's/^/| /' $at_file
748     echo
749   done
751   AS_BOX([Tested programs.])
752   echo
753 } >&AS_MESSAGE_LOG_FD
755 # Report what programs are being tested.
756 for at_program in : $at_tested
758   test "$at_program" = : && continue
759   _AS_PATH_WALK([$PATH], [test -f "$as_dir/$at_program" && break])
760   if test -f "$as_dir/$at_program"; then
761     {
762       AS_ECHO(["$at_srcdir/AT_LINE: $as_dir/$at_program --version"])
763       "$as_dir/$at_program" --version
764       echo
765     } >&AS_MESSAGE_LOG_FD 2>&1
766   else
767     AS_ERROR([cannot find $at_program])
768   fi
769 done
772   AS_BOX([Running the tests.])
773 } >&AS_MESSAGE_LOG_FD
775 at_start_date=`date`
776 at_start_time=`date +%s 2>/dev/null`
777 AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
778 at_xpass_list=
779 at_xfail_list=
780 at_pass_list=
781 at_fail_list=
782 at_skip_list=
783 at_group_count=0
784 m4_divert_pop([PREPARE_TESTS])dnl
785 m4_divert_push([TESTS])dnl
787 # Create the master directory if it doesn't already exist.
788 test -d "$at_suite_dir" ||
789   mkdir "$at_suite_dir" ||
790   AS_ERROR([cannot create '$at_suite_dir'])
792 # Can we diff with `/dev/null'?  DU 5.0 refuses.
793 if diff /dev/null /dev/null >/dev/null 2>&1; then
794   at_devnull=/dev/null
795 else
796   at_devnull=$at_suite_dir/devnull
797   >"$at_devnull"
800 # Use `diff -u' when possible.
801 if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
802 then
803   at_diff='diff -u'
804 else
805   at_diff=diff
809 m4_text_box([Driver loop.])
810 for at_group in $at_groups
812   # Be sure to come back to the top test directory.
813   cd "$at_suite_dir"
815   # Clearly separate the test groups when verbose.
816   test $at_group_count != 0 && $at_verbose echo
818   case $at_group in
819     banner-*)
820       at_group_log=$at_suite_log
821       ;;
823     *)
824       at_group_normalized=$at_group
825       _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
827       # Create a fresh directory for the next test group, and enter.
828       at_group_dir=$at_suite_dir/$at_group_normalized
829       at_group_log=$at_group_dir/$as_me.log
830       if test -d "$at_group_dir"; then
831         find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
832         rm -fr "$at_group_dir" ||
833           AS_WARN([test directory could not be cleaned.])
834       fi
835       # Be tolerant if the above `rm' was not able to remove the directory.
836       AS_MKDIR_P([$at_group_dir])
837       cd $at_group_dir
838       ;;
839   esac
841   echo 0 > "$at_status_file"
843   # In verbose mode, append to the log file *and* show on
844   # the standard output; in quiet mode only write to the log
845   if test -z "$at_verbose"; then
846     at_tee_pipe='tee -a "$at_group_log"'
847   else
848     at_tee_pipe='cat >> "$at_group_log"'
849   fi
851   case $at_group in
852 dnl Test groups inserted here (TESTS).
853 m4_divert_pop([TESTS])[]dnl
854 m4_divert_push([TESTS_END])[]dnl
856   * )
857     AS_ECHO(["$as_me: no such test group: $at_group"]) >&2
858     continue
859     ;;
860   esac
862   # Be sure to come back to the suite directory, in particular
863   # since below we might `rm' the group directory we are in currently.
864   cd "$at_suite_dir"
866   case $at_group in
867     banner-*) ;;
868     *)
869       if test ! -f "$at_check_line_file"; then
870         sed "s/^ */$as_me: warning: /" <<_ATEOF
871         A failure happened in a test group before any test could be
872         run. This means that test suite is improperly designed.  Please
873         report this failure to <AT_PACKAGE_BUGREPORT>.
874 _ATEOF
875         AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
876       fi
877       at_group_count=`expr 1 + $at_group_count`
878       $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
879       AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
880       case $at_xfail:$at_status in
881         yes:0)
882             at_msg="UNEXPECTED PASS"
883             at_xpass_list="$at_xpass_list $at_group"
884             at_errexit=$at_errexit_p
885             ;;
886         no:0)
887             at_msg="ok"
888             at_pass_list="$at_pass_list $at_group"
889             at_errexit=false
890             ;;
891         *:77)
892             at_msg='skipped ('`cat "$at_check_line_file"`')'
893             at_skip_list="$at_skip_list $at_group"
894             at_errexit=false
895             ;;
896         yes:*)
897             at_msg='expected failure ('`cat "$at_check_line_file"`')'
898             at_xfail_list="$at_xfail_list $at_group"
899             at_errexit=false
900             ;;
901         no:*)
902             at_msg='FAILED ('`cat "$at_check_line_file"`')'
903             at_fail_list="$at_fail_list $at_group"
904             at_errexit=$at_errexit_p
905             ;;
906       esac
907       # Make sure there is a separator even with long titles.
908       AS_ECHO([" $at_msg"])
909       at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
910       case $at_status in
911         0|77)
912           # $at_times_file is only available if the group succeeded.
913           # We're not including the group log, so the success message
914           # is written in the global log separately.  But we also
915           # write to the group log in case they're using -d.
916           if test -f "$at_times_file"; then
917             at_log_msg="$at_log_msg     ("`sed 1d "$at_times_file"`')'
918             rm -f "$at_times_file"
919           fi
920           AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
921           AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
923           # Cleanup the group directory, unless the user wants the files.
924           if $at_debug_p ; then
925             _AT_CREATE_DEBUGGING_SCRIPT
926           elif test -d "$at_group_dir"; then
927             find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
928             rm -fr "$at_group_dir"
929           fi
930           ;;
931         *)
932           # Upon failure, include the log into the testsuite's global
933           # log.  The failure message is written in the group log.  It
934           # is later included in the global log.
935           AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
937           # Upon failure, keep the group directory for autopsy, and
938           # create the debugging script.
939           _AT_CREATE_DEBUGGING_SCRIPT
940           $at_errexit && break
941           ;;
942       esac
943       ;;
944   esac
945 done
947 # Back to the top directory.
948 cd "$at_dir"
950 # Compute the duration of the suite.
951 at_stop_date=`date`
952 at_stop_time=`date +%s 2>/dev/null`
953 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
954 case $at_start_time,$at_stop_time in
955   [[0-9]*,[0-9]*])
956     at_duration_s=`expr $at_stop_time - $at_start_time`
957     at_duration_m=`expr $at_duration_s / 60`
958     at_duration_h=`expr $at_duration_m / 60`
959     at_duration_s=`expr $at_duration_s % 60`
960     at_duration_m=`expr $at_duration_m % 60`
961     at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
962     AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
963     ;;
964 esac
966 # Wrap up the test suite with summary statistics.
967 set X $at_skip_list; shift; at_skip_count=$[@%:@]
968 set X $at_fail_list; shift; at_fail_count=$[@%:@]
969 set X $at_xpass_list; shift; at_xpass_count=$[@%:@]
970 set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
972 at_run_count=`expr $at_group_count - $at_skip_count`
973 at_unexpected_count=`expr $at_xpass_count + $at_fail_count`
974 at_total_fail_count=`expr $at_xfail_count + $at_fail_count`
976 echo
977 AS_BOX([Test results.])
978 echo
980   echo
981   AS_BOX([Test results.])
982   echo
983 } >&AS_MESSAGE_LOG_FD
986 dnl FIXME: this code is as far from i18n-cleanness as man
987 dnl could imagine...
989 if test $at_run_count = 1; then
990   at_result="1 test"
991   at_were=was
992 else
993   at_result="$at_run_count tests"
994   at_were=were
996 if $at_errexit_p && test $at_unexpected_count != 0; then
997   if test $at_xpass_count = 1; then
998     at_result="$at_result $at_were run, one passed"
999   else
1000     at_result="$at_result $at_were run, one failed"
1001   fi
1002   at_result="$at_result unexpectedly and inhibited subsequent tests."
1003 else
1004   # Don't you just love exponential explosion of the number of cases?
1005   case $at_xpass_count:$at_fail_count:$at_xfail_count in
1006     # So far, so good.
1007     0:0:0) at_result="$at_result $at_were successful." ;;
1008     0:0:*) at_result="$at_result behaved as expected." ;;
1010     # Some unexpected failures
1011     0:*:0) at_result="$at_result $at_were run,
1012 $at_fail_count failed unexpectedly." ;;
1014     # Some failures, both expected and unexpected
1015     0:*:1) at_result="$at_result $at_were run,
1016 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1017     0:*:*) at_result="$at_result $at_were run,
1018 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1020     # No unexpected failures, but some xpasses
1021     *:0:*) at_result="$at_result $at_were run,
1022 $at_xpass_count passed unexpectedly." ;;
1024     # No expected failures, but failures and xpasses
1025     *:1:0) at_result="$at_result $at_were run,
1026 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failure)." ;;
1027     *:*:0) at_result="$at_result $at_were run,
1028 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failures)." ;;
1030     # All of them.
1031     *:*:1) at_result="$at_result $at_were run,
1032 $at_xpass_count passed unexpectedly,
1033 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1034     *:*:*) at_result="$at_result $at_were run,
1035 $at_xpass_count passed unexpectedly,
1036 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1037   esac
1039   if test $at_skip_count = 0 && test $at_run_count -gt 1; then
1040     at_result="All $at_result"
1041   fi
1044 # Now put skips in the mix.
1045 case $at_skip_count in
1046   0) ;;
1047   1) at_result="$at_result
1048 1 test was skipped." ;;
1049   *) at_result="$at_result
1050 $at_skip_count tests were skipped." ;;
1051 esac
1053 if test $at_unexpected_count = 0; then
1054   echo "$at_result"
1055   echo "$at_result" >&AS_MESSAGE_LOG_FD
1056 else
1057   echo "ERROR: $at_result" >&2
1058   echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
1059   {
1060     echo
1061     AS_BOX([Summary of the failures.])
1063     # Summary of failed and skipped tests.
1064     if test $at_fail_count != 0; then
1065       echo "Failed tests:"
1066       $SHELL "$[0]" $at_fail_list --list
1067       echo
1068     fi
1069     if test $at_skip_count != 0; then
1070       echo "Skipped tests:"
1071       $SHELL "$[0]" $at_skip_list --list
1072       echo
1073     fi
1074     if test $at_xpass_count != 0; then
1075       echo "Unexpected passes:"
1076       $SHELL "$[0]" $at_xpass_list --list
1077       echo
1078     fi
1079     if test $at_fail_count != 0; then
1080       AS_BOX([Detailed failed tests.])
1081       echo
1082       for at_group in $at_fail_list
1083       do
1084         at_group_normalized=$at_group
1085         _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1086         cat "$at_suite_dir/$at_group_normalized/$as_me.log"
1087         echo
1088       done
1089       echo
1090     fi
1091     if test -n "$at_top_srcdir"; then
1092       AS_BOX([${at_top_build_prefix}config.log])
1093       sed 's/^/| /' ${at_top_build_prefix}config.log
1094       echo
1095     fi
1096   } >&AS_MESSAGE_LOG_FD
1098   AS_BOX([$as_me.log was created.])
1100   echo
1101   AS_ECHO(["Please send \`${at_testdir+${at_testdir}/}$as_me.log' and all information you think might help:
1103    To: <AT_PACKAGE_BUGREPORT>
1104    Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me:dnl
1105 $at_fail_list${at_fail_list:+ failed${at_xpass_list:+,}}dnl
1106 $at_xpass_list${at_xpass_list:+ passed unexpectedly}
1108   if test $at_debug_p = false; then
1109     echo
1110     echo 'You may investigate any problem if you feel able to do so, in which'
1111     echo 'case the test suite provides a good starting point.  Its output may'
1112     AS_ECHO(["be found below \`${at_testdir+${at_testdir}/}$as_me.dir'."])
1113     echo
1114   fi
1115     exit 1
1118 exit 0
1120 m4_text_box([Actual tests.])
1121 m4_divert_pop([TESTS_END])dnl
1122 dnl End of AT_INIT: divert to KILL, only test groups are to be
1123 dnl output, the rest is ignored.  Current diversion is BODY, inherited
1124 dnl from M4sh.
1125 m4_divert_pop([BODY])
1126 m4_divert_push([KILL])
1127 ])# AT_INIT
1130 # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
1131 #                [ACTION-IF-NOT-GIVEN])
1132 # ---------------------------------------------------------------------------
1133 # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
1134 m4_defun([_AT_ARG_OPTION],
1135 [m4_divert_once([HELP_OTHER],
1136 [cat <<_ATEOF
1138 Other options:
1139 _ATEOF
1140 ])dnl m4_divert_once HELP_OTHER
1141 m4_divert_text([HELP_OTHER],
1142 [cat <<_ATEOF
1144 _ATEOF])dnl
1145 dnl Turn our options into our desired strings
1146 m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
1147 m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
1148 m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
1149 m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
1150 m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
1151 [m4_define_default([AT_first_option],AT_option)dnl
1152 m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
1153 m4_append([AT_case_no],[--no]AT_option, [ | ])dnl
1154 m4_append([AT_case_arg],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
1155 ])dnl m4_foreach AT_option
1156 dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
1157 m4_divert_once([PARSE_ARGS_BEGIN],
1160 ## Set up package specific options.
1162 ])dnl
1163 m4_divert_text([PARSE_ARGS_BEGIN],
1164 [dnl Provide a default value for options without arguments.
1165 m4_ifvaln([$3],,[at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false])dnl
1166 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=false
1167 ])dnl m4_divert_text DEFAULTS
1168 m4_ifval([$3],[m4_divert_once([PARSE_ARGS_END],
1171 ## Verify our last option didn't require an argument
1173 AS_IF([test -n "$at_prev"],[AS_ERROR([`$at_prev' requires an argument.])])])])
1174 m4_divert_text([PARSE_ARGS],
1175 [dnl Parse the options and args when necessary.
1176 m4_ifvaln([$3],
1177 [    AT_case )
1178         at_prev=--m4_bpatsubst([AT_first_option], -, _)
1179         ;;
1180     AT_case_arg )
1181         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=$at_optarg
1182         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1183         $4
1184         ;;],
1185 [    AT_case )
1186         at_optarg=:
1187         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=:
1188         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1189         m4_ifval([$4],[$4])dnl
1190         ;;
1191     AT_case_no )
1192         at_optarg=false
1193         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false
1194         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1195         m4_ifval([$4],[$4])dnl
1196         ;;])dnl m4_ifvaln $3
1197 ])dnl m4_divert_text PARSE_ARGS
1198 m4_ifvaln([$5],
1199 [m4_divert_once([PARSE_ARGS_END],
1202 ## Process package specific options when _not_ supplied.
1203 ##])dnl m4_divert_once PARSE_ARGS_END
1204 m4_divert_text([PARSE_ARGS_END],
1206 AS_IF([$at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)],,[$5])dnl
1207 ])dnl m4_divert_text PARSE_ARGS_END
1208 ])dnl m4_ifvaln $5
1209 ])dnl _AT_ARG_OPTION
1212 # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1213 # ------------------------------------------------------------------------
1214 # Accept a set of OPTIONS with arguments.  Add HELP-TEXT to the HELP_OTHER
1215 # diversion.
1217 # Preceding dashes should not be passed into OPTIONS.  Users will be required
1218 # to pass `--' before long options and `-' before single character options.
1220 # $at_arg_OPTION will be set to `:' if this option is received, `false' if
1221 # if --noOPTION is received, and `false' by default.
1223 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1224 # $at_optarg set to `:' or `false' as appropriate.  $at_optarg is actually
1225 # just a copy of $at_arg_OPTION.
1227 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1228 # if no option from OPTIONS was found.
1229 m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
1232 # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1233 # ---------------------------------------------------------------------------
1234 # Accept a set of OPTIONS with arguments, seperated by commas.  Add HELP-TEXT
1235 # to the HELP_OTHER diversion.
1237 # Preceding dashes should not be passed into OPTIONS.  Users will be required
1238 # to pass `--' before long options and `-' before single character options.
1240 # By default, any argument to these options will be assigned to the shell
1241 # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
1242 # any `-' characters replaced with `_'.
1244 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1245 # $at_optarg set.  $at_optarg is actually just a copy of $at_arg_OPTION.
1247 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1248 # if no option from OPTIONS was found.
1249 m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
1252 # AT_TESTED(PROGRAMS)
1253 # -------------------
1254 # Specify the list of programs exercised by the test suite.  Their
1255 # versions are logged, and in the case of embedded test suite, they
1256 # must correspond to the version of the package.  PATH should be
1257 # already preset so the proper executable will be selected.
1258 m4_define([AT_TESTED],
1259 [m4_append_uniq([AT_tested], [$1], [
1260 ])])
1263 # AT_COPYRIGHT(TEXT)
1264 # ------------------
1265 # Emit TEXT, a copyright notice, in the top of the test suite and in
1266 # --version output.  Macros in TEXT are evaluated once.
1267 m4_define([AT_COPYRIGHT],
1268 [AS_COPYRIGHT([$1])[]dnl
1269 m4_divert_text([VERSION_NOTICES],
1271 $1])])# AT_COPYRIGHT
1274 # AT_SETUP(DESCRIPTION)
1275 # ---------------------
1276 # Start a group of related tests, all to be executed in the same subshell.
1277 # The group is testing what DESCRIPTION says.
1278 m4_define([AT_SETUP],
1279 [m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
1280 m4_define([AT_capture_files], [])
1281 m4_define([AT_line], AT_LINE)
1282 m4_define([AT_xfail], [at_xfail=no])
1283 m4_define([AT_description], m4_expand([$1]))
1284 m4_define([AT_ordinal], m4_incr(AT_ordinal))
1285 m4_append([AT_groups_all], [ ]m4_defn([AT_ordinal]))
1286 m4_divert_push([TEST_FUNCTIONS])dnl
1287 [#AT_START_]AT_ordinal
1288 @%:@ AT_ordinal. m4_defn([AT_line]): m4_defn([AT_description])
1289 at_setup_line='m4_defn([AT_line])'
1290 at_desc="AS_ESCAPE(m4_dquote(m4_defn([AT_description])))"
1291 $at_quiet AS_ECHO_N([m4_format(["%3d: $at_desc%*s"], AT_ordinal,
1292   m4_max(0, m4_eval(47 - m4_qlen(m4_defn([AT_description])))), [])])
1293 m4_divert_push([TEST_SCRIPT])dnl
1297 # AT_XFAIL_IF(SHELL-EXPRESSION)
1298 # -----------------------------
1299 # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
1300 # true (exitcode = 0).
1301 m4_define([AT_XFAIL_IF],
1302 [dnl
1303 dnl Try to limit the amount of conditionals that we emit.
1304 m4_case([$1],
1305       [], [],
1306       [false], [],
1307       [:], [m4_define([AT_xfail], [at_xfail=yes])],
1308       [true], [m4_define([AT_xfail], [at_xfail=yes])],
1309       [m4_append([AT_xfail], [
1310       $1 && at_xfail=yes])])])
1313 # AT_KEYWORDS(KEYWORDS)
1314 # ---------------------
1315 # Declare a list of keywords associated to the current test group.
1316 m4_define([AT_KEYWORDS],
1317 [m4_append_uniq([AT_keywords], [$1], [ ])])
1320 # AT_CAPTURE_FILE(FILE)
1321 # ---------------------
1322 # If the current test group does not behave as expected, save the contents of
1323 # FILE in the test suite log.
1324 m4_define([AT_CAPTURE_FILE],
1325 [m4_append_uniq([AT_capture_files], ["$1"], [ \
1326 ])])
1329 # AT_CLEANUP
1330 # ----------
1331 # Complete a group of related tests.
1332 m4_define([AT_CLEANUP],
1333 [m4_append([AT_help_all],
1334 m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
1335 )dnl
1336 m4_divert_pop([TEST_SCRIPT])dnl Back to TEST_FUNCTIONS
1337 AT_xfail
1338 echo "#                             -*- compilation -*-" >> "$at_group_log"
1340   AS_ECHO(["AT_ordinal. m4_defn([AT_line]): testing $1..."])
1341   $at_traceon
1342 m4_undivert([TEST_SCRIPT])dnl Insert the code here
1343   $at_traceoff
1344   $at_times_p && times >"$at_times_file"
1345 ) AS_MESSAGE_LOG_FD>&1 2>&1 | eval $at_tee_pipe
1346 at_status=`cat "$at_status_file"`
1347 [#AT_STOP_]AT_ordinal
1348 m4_divert_pop([TEST_FUNCTIONS])dnl Back to KILL.
1349 m4_divert_text([TESTS],
1350 [  AT_ordinal )
1351     if at_func_test AT_ordinal && . "$at_test_source"; then :; else
1352       AS_ECHO(["$as_me: unable to parse test group: $[1]"]) >&2
1353       at_failed=:
1354     fi ;;])
1355 ])# AT_CLEANUP
1358 # AT_BANNER(TEXT)
1359 # ---------------
1360 # Output TEXT without any shell expansion.
1361 m4_define([AT_BANNER],
1362 [m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
1363 m4_append([AT_groups_all], [ banner-]m4_defn([AT_banner_ordinal]))
1364 m4_divert_text([TESTS],
1366   banner-AT_banner_ordinal ) @%:@ Banner AT_banner_ordinal. AT_LINE
1367     cat <<\_ATEOF
1371 _ATEOF
1372     ;;
1373 ])dnl
1374 ])# AT_BANNER
1377 # AT_DATA(FILE, CONTENTS)
1378 # -----------------------
1379 # Initialize an input data FILE with given CONTENTS, which should end with
1380 # an end of line.
1381 # This macro is not robust to active symbols in CONTENTS *on purpose*.
1382 # If you don't want CONTENTS to be evaluated, quote it twice.
1383 m4_define([AT_DATA],
1384 [cat >$1 <<'_ATEOF'
1385 $2[]_ATEOF
1389 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1390 #          [RUN-IF-FAIL], [RUN-IF-PASS])
1391 # ------------------------------------------------
1392 # Execute a test by performing given shell COMMANDS.  These commands
1393 # should normally exit with STATUS, while producing expected STDOUT and
1394 # STDERR contents.  Shell metacharacters in STDOUT and STDERR are
1395 # _not_ processed by the shell, but are treated as string literals.
1397 # STATUS, STDOUT, and STDERR are not checked if equal to `ignore'.
1399 # If STDOUT is `expout', then stdout is compared to the content of the file
1400 # `expout'.  Likewise for STDERR and `experr'.
1402 # If STDOUT is `stdout', then the stdout is left in the file `stdout',
1403 # likewise for STDERR and `stderr'.  Don't do this:
1405 #    AT_CHECK([command >out])
1406 #    # Some checks on `out'
1408 # do this instead:
1410 #    AT_CHECK([command], [], [stdout])
1411 #    # Some checks on `stdout'
1413 # You might wonder why you can't just use `ignore', then directly use stdout
1414 # and stderr left by the test suite:
1416 #    AT_CHECK([command], [], [ignore])
1417 #    AT_CHECK([check stdout])
1419 # If the test suite always captured data in the file `stdout', then the
1420 # second command would be trying to read and write from the same file, with
1421 # undefined behavior.  Therefore, the test suite actually captures data in
1422 # an internal file of a different name, and only creates `stdout' when
1423 # explicitly requested.
1425 # Any line of stderr starting with leading blanks and a `+' are filtered
1426 # out, since most shells when tracing include subshell traces in stderr.
1427 # This may cause spurious failures when the test suite is run with `-x'.
1429 m4_define([AT_CHECK],
1430 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6],1)])
1432 # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1433 #                   [RUN-IF-FAIL], [RUN-IF-PASS])
1434 # ---------------------------------------------------------
1435 # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
1436 # and STDERR arguments before running the comparison.
1437 m4_define([AT_CHECK_NOESCAPE],
1438 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6])])
1441 # _AT_DECIDE_TRACEABLE(COMMANDS)
1442 # ------------------------------
1443 # Worker for for _AT_CHECK that expands to shell code.  If COMMANDS are safe to
1444 # trace with `set -x', the shell code will evaluate to true.  Otherwise,
1445 # the shell code will print a message stating an aspect of COMMANDS that makes
1446 # tracing them unsafe, and evaluate to false.
1448 # Tracing COMMANDS is not safe if they contain a command that spans multiple
1449 # lines.  When the test suite user passes `-x' or `--trace', the test suite
1450 # precedes every command with a `set -x'.  Since most tests expect a specific
1451 # stderr, if only to confirm that it is empty, the test suite filters ^+ from
1452 # the captured stderr before comparing with the expected stderr.  If a command
1453 # spans multiple lines, so will its trace, but a `+' only prefixes the first
1454 # line of that trace:
1456 # $ echo 'foo
1457 # bar'
1458 # => stdout
1459 # foo
1460 # bar
1461 # => stderr
1462 # + foo
1463 # bar
1465 # In a subset of cases, one could filter such extended shell traces from stderr.
1466 # Since test commands spanning several lines are rare, I chose instead to simply
1467 # not trace COMMANDS that could yield multiple trace lines.  Distinguishing such
1468 # COMMANDS became the task at hand.
1470 # These features may cause a shell command to span multiple lines:
1472 # (a) A quoted literal newline.
1473 # Example:
1474 #   echo foo'
1475 #   'bar
1476 # M4 is a hostile language for the job of parsing COMMANDS to determine whether
1477 # each literal newline is quoted, so we simply disable tracing for all COMMANDS
1478 # that bear literal newlines.
1480 # (b) A command substitution not subject to word splitting.
1481 # Example:
1482 #   var=$(printf 'foo\nbar')
1483 # Example:
1484 #   echo "`printf 'foo\\nbar`"
1485 # One cannot know in general the number of lines a command substitution will
1486 # yield without executing the substituted command.  As such, we disable tracing
1487 # for all COMMANDS containing these constructs.
1489 # (c) A parameter expansion not subject to word splitting.
1490 # Example:
1491 #   var=foo'
1492 #   'bar
1493 #   echo "$var"
1494 # Parameter expansions appear in COMMANDS with much greater frequency than do
1495 # newlines and command substitutions, so disabling tracing for all such COMMANDS
1496 # would much more substantially devalue `testsuite -x'.  To determine which
1497 # parameter expansions yield multiple lines, we escape all ``', `"', and `\' in
1498 # a copy of COMMANDS and expand that string within double quotes at runtime.  If
1499 # the result of that expansion contains multiple lines, the test suite disables
1500 # tracing for the command in question.
1502 # This method leads the test suite to expand some parameters that the shell
1503 # itself will never expand due to single-quotes or backslash escapes.  This is
1504 # not a problem for `$foo' expansions, which will simply yield the empty string
1505 # or some unrelated value.  A `${...}' expansion could actually form invalid
1506 # shell code, however; consider `${=foo}'.  Therefore, we disable tracing for
1507 # all COMMANDS containing `${...}'.  This affects few COMMANDS.
1509 # This macro falls in a very hot path; the Autoconf test suite expands it 1640
1510 # times as of this writing.  To give a sense of the impact of the heuristics I
1511 # just described, the test suite preemptively disables tracing for 31 of those,
1512 # and 268 contain parameter expansions that require runtime evaluation.  The
1513 # balance are always safe to trace.
1515 # _AT_CHECK expands COMMANDS, but the Autoconf language does not provide a way
1516 # to safely expand arbitrary COMMANDS in an argument list, so the below tests
1517 # examine COMMANDS unexpanded.
1518 m4_define([_AT_DECIDE_TRACEABLE],
1519 dnl Utility macro.
1521 dnl Examine COMMANDS for a reason to never trace COMMANDS.
1522 [m4_pushdef([at_reason],
1523 m4_cond([m4_eval(m4_index([$1], [`]) >= 0)], [1],
1524                 [[a `...` command substitution]],
1525         [m4_eval(m4_index([$1], [$(]) >= 0)], [1],
1526                 [[a $(...) command substitution]],
1527         [m4_eval(m4_index([$1], [${]) >= 0)], [1],
1528                 [[a ${...} parameter expansion]],
1529         [m4_eval(m4_index([$1], m4_newline) >= 0)], [1],
1530                 [[an embedded newline]],
1531         []dnl No reason.
1532 ))dnl
1534 m4_ifval(m4_defn([at_reason]),
1535 [{ echo 'Not enabling shell tracing (command contains ]m4_defn([at_reason])[)'; false; }],
1536 [m4_if(m4_index([$1], [$]), [-1],
1537 dnl We know at build time that tracing COMMANDS is always safe.
1538 [test -n "$at_traceon"],
1539 dnl COMMANDS may contain parameter expansions; expand them at runtime.
1540 [test -n "$at_traceon" && at_func_check_newline "AS_ESCAPE([$1], [`\"])"])])[]dnl
1541 m4_popdef([at_reason])])
1544 # AT_DIFF_STDERR/AT_DIFF_STDOUT
1545 # -----------------------------
1546 # These are subroutines of AT_CHECK.  Using indirect dispatch is a tad
1547 # faster than using m4_case, and these are called very frequently.
1548 m4_define([AT_DIFF_STDERR(stderr)],
1549           [echo stderr:; tee stderr <"$at_stderr"])
1550 m4_define([AT_DIFF_STDERR(ignore)],
1551           [echo stderr:; cat "$at_stderr"])
1552 m4_define([AT_DIFF_STDERR(experr)],
1553           [$at_diff experr "$at_stderr" || at_failed=:])
1554 m4_define([AT_DIFF_STDERR()],
1555           [at_func_diff_devnull "$at_stderr" || at_failed=:])
1557 m4_define([AT_DIFF_STDOUT(stdout)],
1558           [echo stdout:; tee stdout <"$at_stdout"])
1559 m4_define([AT_DIFF_STDOUT(ignore)],
1560           [echo stdout:; cat "$at_stdout"])
1561 m4_define([AT_DIFF_STDOUT(expout)],
1562           [$at_diff expout "$at_stdout" || at_failed=:])
1563 m4_define([AT_DIFF_STDOUT()],
1564           [at_func_diff_devnull "$at_stdout" || at_failed=:])
1566 # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1567 #           [RUN-IF-FAIL], [RUN-IF-PASS], SHELL_ESCAPE_IO)
1568 # ---------------------------------------------------------
1569 # Worker for AT_CHECK & AT_CHECK_NOESCAPE.  The final SHELL-ESCAPE-IO
1570 # argument determines whether the STDOUT & STDERR arguments will be escaped or
1571 # not.
1574 # Implementation Details
1575 # ----------------------
1576 # Ideally, we would like to run
1578 #    ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
1580 # but we must group COMMANDS as it is not limited to a single command, and
1581 # then the shells will save the traces in at-stderr. So we have to filter
1582 # them out when checking stderr, and we must send them into the test suite's
1583 # stderr to honor -x properly. Since only the first line of the trace of a
1584 # multiline command starts with a `+', and I know of no straightforward way to
1585 # filter out the unadorned trace lines, we disable shell tracing entirely for
1586 # commands that could span multiple lines.
1588 # Limiting COMMANDS to a single command is not good either, since them
1589 # the user herself would use {} or (), and then we face the same problem.
1591 # But then, there is no point in running
1593 #   ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
1595 # instead of the simpler
1597 #  ( $at_traceon; $1 ) >at-stdout 2>at-stder1
1599 m4_define([_AT_CHECK],
1600 [$at_traceoff
1601 AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([$1])"])
1602 echo AT_LINE >"$at_check_line_file"
1604 if _AT_DECIDE_TRACEABLE([$1]); then
1605     ( $at_traceon; $1 ) >"$at_stdout" 2>"$at_stder1"
1606     at_func_filter_trace $?
1607 else
1608     ( :; $1 ) >"$at_stdout" 2>"$at_stderr"
1610 at_status=$?
1611 at_failed=false
1612 m4_ifdef([AT_DIFF_STDERR($4)], [m4_indir([AT_DIFF_STDERR($4)])],
1613          [echo >>"$at_stderr"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$4])],[$4])"]) | \
1614           $at_diff - "$at_stderr" || at_failed=:])
1615 m4_ifdef([AT_DIFF_STDOUT($3)], [m4_indir([AT_DIFF_STDOUT($3)])],
1616          [echo >>"$at_stdout"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$3])],[$3])"]) | \
1617           $at_diff - "$at_stdout" || at_failed=:])
1618 m4_if([$2], [ignore], [at_func_check_skip],
1619       [at_func_check_status m4_default([$2], [0])]) dnl
1620      $at_status "$at_srcdir/AT_LINE"
1621 AS_IF($at_failed, [$5], [$6])
1622 $at_failed && at_func_log_failure AT_capture_files
1623 $at_traceon
1624 ])# _AT_CHECK