Speed up execution of subset of testsuite.
[autoconf.git] / lib / autotest / general.m4
blobe34055eb560d73889ea4d7ee05698bfa86b917d1
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 at_func_test_NUMBER from the tail of this file, source it,
295 # then invoke it.
296 at_func_test ()
298   if sed -n '/^@%:@AT_START_'$[1]$'/,/^@%:@AT_STOP_'$[1]$'/p' "$at_myself" \
299        > "$at_test_source" && . "$at_test_source" ; then
300     at_func_test_$[1] || {
301       AS_ECHO(["$as_me: unable to execute test group: $[1]"]) >&2
302       at_failed=:
303     }
304   else
305     AS_ECHO(["$as_me: unable to parse test group: $[1]"]) >&2
306     at_failed=:
307   fi
310 # Load the config file.
311 for at_file in atconfig atlocal
313   test -r $at_file || continue
314   . ./$at_file || AS_ERROR([invalid content: $at_file])
315 done
317 # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
318 : ${at_top_build_prefix=$at_top_builddir}
320 # atconfig delivers names relative to the directory the test suite is
321 # in, but the groups themselves are run in testsuite-dir/group-dir.
322 if test -n "$at_top_srcdir"; then
323   builddir=../..
324   for at_dir in srcdir top_srcdir top_build_prefix
325   do
326     at_val=AS_VAR_GET([at_$at_dir])
327     case $at_val in
328       [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
329       *) at_prefix=../../ ;;
330     esac
331     AS_VAR_SET([$at_dir], [$at_prefix$at_val])
332   done
335 # Not all shells have the 'times' builtin; the subshell is needed to make
336 # sure we discard the 'times: not found' message from the shell.
337 at_times_p=false
338 (times) >/dev/null 2>&1 && at_times_p=:
340 # CLI Arguments to pass to the debugging scripts.
341 at_debug_args=
342 # -e sets to true
343 at_errexit_p=false
344 # Shall we be verbose?  ':' means no, empty means yes.
345 at_verbose=:
346 at_quiet=
348 # Shall we keep the debug scripts?  Must be `:' when the suite is
349 # run by a debug script, so that the script doesn't remove itself.
350 at_debug_p=false
351 # Display help message?
352 at_help_p=false
353 # Display the version message?
354 at_version_p=false
355 # List test groups?
356 at_list_p=false
357 # Test groups to run
358 at_groups=
360 # The directory we are in.
361 at_dir=`pwd`
362 # An absolute reference to this testsuite script.
363 dnl m4-double quote, to preserve []
364 [case $as_myself in
365   [\\/]* | ?:[\\/]* ) at_myself=$as_myself ;;
366   * ) at_myself=$at_dir/$as_myself ;;
367 esac]
368 # The directory the whole suite works in.
369 # Should be absolute to let the user `cd' at will.
370 at_suite_dir=$at_dir/$as_me.dir
371 # The file containing the suite.
372 at_suite_log=$at_dir/$as_me.log
373 # The file containing the location of the last AT_CHECK.
374 at_check_line_file=$at_suite_dir/at-check-line
375 # The file containing the exit status of the last command.
376 at_status_file=$at_suite_dir/at-status
377 # The files containing the output of the tested commands.
378 at_stdout=$at_suite_dir/at-stdout
379 at_stder1=$at_suite_dir/at-stder1
380 at_stderr=$at_suite_dir/at-stderr
381 # The file containing the function to run a test group.
382 at_test_source=$at_suite_dir/at-test-source
383 # The file containing dates.
384 at_times_file=$at_suite_dir/at-times
385 m4_divert_pop([DEFAULTS])dnl
386 m4_wrap([m4_divert_text([DEFAULTS],
388 # List of the tested programs.
389 at_tested='m4_ifdef([AT_tested], [AT_tested])'
390 # List of the all the test groups.
391 at_groups_all='AT_groups_all'
392 # As many question marks as there are digits in the last test group number.
393 # Used to normalize the test group numbers so that `ls' lists them in
394 # numerical order.
395 at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
396 # Description of all the test groups.
397 at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"])])dnl
398 m4_divert_push([PARSE_ARGS])dnl
400 at_prev=
401 for at_option
403   # If the previous option needs an argument, assign it.
404   if test -n "$at_prev"; then
405     at_option=$at_prev=$at_option
406     at_prev=
407   fi
409   case $at_option in
410   *=*) at_optarg=`expr "x$at_option" : 'x[[^=]]*=\(.*\)'` ;;
411   *)   at_optarg= ;;
412   esac
414   # Accept the important Cygnus configure options, so we can diagnose typos.
416   case $at_option in
417     --help | -h )
418         at_help_p=:
419         ;;
421     --list | -l )
422         at_list_p=:
423         ;;
425     --version | -V )
426         at_version_p=:
427         ;;
429     --clean | -c )
430         test -d "$at_suite_dir" &&
431           find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
432         rm -f -r "$at_suite_dir" "$at_suite_log"
433         exit $?
434         ;;
436     --debug | -d )
437         at_debug_p=:
438         ;;
440     --errexit | -e )
441         at_debug_p=:
442         at_errexit_p=:
443         ;;
445     --verbose | -v )
446         at_verbose=; at_quiet=:
447         ;;
449     --trace | -x )
450         at_traceon='set -x'; at_traceoff='set +x'
451         ;;
453     [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
454         at_groups="$at_groups$at_option "
455         ;;
457     # Ranges
458     [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
459         at_range_start=`echo $at_option |tr -d X-`
460         at_range=`AS_ECHO([" $at_groups_all "]) | \
461           sed -e 's/^.* \('$at_range_start' \)/\1/'`
462         at_groups="$at_groups$at_range "
463         ;;
465     [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
466         at_range_end=`echo $at_option |tr -d X-`
467         at_range=`AS_ECHO([" $at_groups_all "]) | \
468           sed -e 's/\( '$at_range_end'\) .*$/\1/'`
469         at_groups="$at_groups$at_range "
470         ;;
472     [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
473     [[0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9]] | \
474     [[0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
475     [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
476     [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
477     [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
478         at_range_start=`expr $at_option : '\(.*\)-'`
479         at_range_end=`expr $at_option : '.*-\(.*\)'`
480         if test $at_range_start -gt $at_range_end; then
481           at_tmp=$at_range_end
482           at_range_end=$at_range_start
483           at_range_start=$at_tmp
484         fi
485         at_range=`AS_ECHO([" $at_groups_all "]) | \
486           sed -e 's/^.*\( '$at_range_start' \)/\1/' \
487               -e 's/\( '$at_range_end'\) .*$/\1/'`
488         at_groups="$at_groups$at_range "
489         ;;
491     # Keywords.
492     --keywords | -k )
493         at_prev=--keywords
494         ;;
495     --keywords=* )
496         at_groups_selected=$at_help_all
497         at_save_IFS=$IFS
498         IFS=,
499         set X $at_optarg
500         shift
501         IFS=$at_save_IFS
502         for at_keyword
503         do
504           at_invert=
505           case $at_keyword in
506           '!'*)
507             at_invert="-v"
508             at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
509             ;;
510           esac
511           # It is on purpose that we match the test group titles too.
512           at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
513               grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
514         done
515         # Smash the newlines.
516         at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//' |
517           tr "$as_nl" ' '
518         `
519         at_groups="$at_groups$at_groups_selected "
520         ;;
521 m4_divert_pop([PARSE_ARGS])dnl
522 dnl Process *=* last to allow for user specified --option=* type arguments.
523 m4_divert_push([PARSE_ARGS_END])dnl
525     *=*)
526         at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
527         # Reject names that are not valid shell variable names.
528         expr "x$at_envvar" : "[.*[^_$as_cr_alnum]]" >/dev/null &&
529           AS_ERROR([invalid variable name: $at_envvar])
530         at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
531         eval "$at_envvar='$at_value'"
532         export $at_envvar
533         # Propagate to debug scripts.
534         at_debug_args="$at_debug_args $at_envvar='$at_value'"
535         ;;
537      *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
538         AS_ECHO(["Try \`$[0] --help' for more information."]) >&2
539         exit 1
540         ;;
541   esac
542 done
544 # Selected test groups.
545 if test -z "$at_groups"; then
546   at_groups=$at_groups_all
547 else
548   # Sort the tests, removing duplicates:
549   at_groups=`AS_ECHO(["$at_groups"]) | tr ' ' "$as_nl" | sort -nu`
550   # and add banners.  (Passing at_groups_all is tricky--see the comment
551   # starting with "Passing at_groups is tricky.")
552   at_groups=`AS_ECHO(["$at_groups$as_nl $at_groups_all"]) |
553     awk ['BEGIN { FS = "@" } # Effectively switch off field splitting.
554         /^$/ { next }  # Ignore the empty line.
555         !/ / { groups++; selected[$ 0] = 1; next }
556         # The last line, containing at_groups_all.
557         {
558                 n = split($ 0, a, " ")
559                 # If there are several tests, select their banners:
560                 if (groups > 1) {
561                         for (i = 1; i <= n; i++) {
562                                 if (a[i] ~ /^banner-/)
563                                         banner = a[i]
564                                 else if (banner != "" && selected[a[i]] == 1)
565                                         selected[banner] = 1
566                         }
567                 }
568                 for (i = 1; i <= n; i++)
569                         if (selected[a[i]] == 1)
570                                 list = list " " a[i]
571                 print list
572         }']`
574 m4_divert_pop([PARSE_ARGS_END])dnl
575 m4_divert_push([HELP])dnl
577 # Help message.
578 if $at_help_p; then
579   cat <<_ATEOF
580 Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
582 Run all the tests, or the selected TESTS, given by numeric ranges, and
583 save a detailed log file.  Upon failure, create debugging scripts.
585 You should not change environment variables unless explicitly passed
586 as command line arguments.  Set \`AUTOTEST_PATH' to select the executables
587 to exercise.  Each relative directory is expanded as build and source
588 directories relatively to the top level of this distribution.  E.g.,
590   $ $[0] AUTOTEST_PATH=bin
592 possibly amounts into
594   PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH
595 _ATEOF
596 m4_divert_pop([HELP])dnl
597 m4_divert_push([HELP_MODES])dnl
598 cat <<_ATEOF
600 Operation modes:
601   -h, --help     print the help message, then exit
602   -V, --version  print version number, then exit
603   -c, --clean    remove all the files this test suite might create and exit
604   -l, --list     describes all the tests, or the selected TESTS
605 _ATEOF
606 m4_divert_pop([HELP_MODES])dnl
607 m4_divert_push([HELP_TUNING])dnl
608 cat <<_ATEOF
610 dnl extra quoting prevents emacs whitespace mode from putting tabs in output
611 Execution tuning:
612   -k, --keywords=KEYWORDS
613 [                 select the tests matching all the comma-separated KEYWORDS]
614 [                 multiple \`-k' accumulate; prefixed \`!' negates a KEYWORD]
615   -e, --errexit  abort as soon as a test fails; implies --debug
616   -v, --verbose  force more detailed output
617 [                 default for debugging scripts]
618   -d, --debug    inhibit clean up and top-level logging
619 [                 default for debugging scripts]
620   -x, --trace    enable tests shell tracing
621 _ATEOF
622 m4_divert_pop([HELP_TUNING])dnl
623 m4_divert_push([HELP_END])dnl
624 cat <<_ATEOF
626 Report bugs to <AT_PACKAGE_BUGREPORT>.
627 _ATEOF
628   exit 0
631 # List of tests.
632 if $at_list_p; then
633   cat <<_ATEOF
634 AT_TESTSUITE_NAME test groups:
636  NUM: FILE-NAME:LINE     TEST-GROUP-NAME
637       KEYWORDS
639 _ATEOF
640   # Passing at_groups is tricky.  We cannot use it to form a literal string
641   # or regexp because of the limitation of AIX awk.  And Solaris' awk
642   # doesn't grok more than 99 fields in a record, so we have to use `split'.
643   AS_ECHO(["$at_groups$as_nl$at_help_all"]) |
644     awk 'BEGIN { FS = ";" }
645          NR == 1 {
646            for (n = split($ 0, a, " "); n; n--) selected[[a[n]]] = 1
647            next
648          }
649          {
650            if (selected[[$ 1]]) {
651              printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
652              if ($ 4) printf "      %s\n", $ 4
653            }
654          }'
655   exit 0
657 m4_divert_pop([HELP_END])dnl
658 m4_divert_push([VERSION])dnl
659 if $at_version_p; then
660   AS_ECHO(["$as_me (AT_PACKAGE_STRING)"])
661   cat <<\_ACEOF
662 m4_divert_pop([VERSION])dnl
663 m4_divert_push([VERSION_END])dnl
664 _ACEOF
665   exit 0
667 m4_divert_pop([VERSION_END])dnl
668 m4_divert_push([PREPARE_TESTS])dnl
670 # Don't take risks: use only absolute directories in PATH.
672 # For stand-alone test suites, AUTOTEST_PATH is relative to `.'.
674 # For embedded test suites, AUTOTEST_PATH is relative to the top level
675 # of the package.  Then expand it into build/src parts, since users
676 # may create executables in both places.
677 AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s|:|$PATH_SEPARATOR|g"`
678 at_path=
679 _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
680 [test -n "$at_path" && at_path=$at_path$PATH_SEPARATOR
681 case $as_dir in
682   [[\\/]]* | ?:[[\\/]]* )
683     at_path=$at_path$as_dir
684     ;;
685   * )
686     if test -z "$at_top_build_prefix"; then
687       # Stand-alone test suite.
688       at_path=$at_path$as_dir
689     else
690       # Embedded test suite.
691       at_path=$at_path$at_top_build_prefix$as_dir$PATH_SEPARATOR
692       at_path=$at_path$at_top_srcdir/$as_dir
693     fi
694     ;;
695 esac])
697 # Now build and simplify PATH.
699 # There might be directories that don't exist, but don't redirect
700 # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
701 at_new_path=
702 _AS_PATH_WALK([$at_path],
703 [as_dir=`(cd "$as_dir" && pwd) 2>/dev/null`
704 test -d "$as_dir" || continue
705 case $PATH_SEPARATOR$at_new_path$PATH_SEPARATOR in
706   *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR*) ;;
707   $PATH_SEPARATOR$PATH_SEPARATOR) at_new_path=$as_dir ;;
708   *) at_new_path=$at_new_path$PATH_SEPARATOR$as_dir ;;
709 esac])
710 PATH=$at_new_path
711 export PATH
713 # Setting up the FDs.
714 # 5 is the log file.  Not to be overwritten if `-d'.
715 m4_define([AS_MESSAGE_LOG_FD], [5])
716 if $at_debug_p; then
717   at_suite_log=/dev/null
718 else
719   : >"$at_suite_log"
721 exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
723 # Banners and logs.
724 AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
726   AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
727   echo
729   AS_ECHO(["$as_me: command line was:"])
730   AS_ECHO(["  \$ $[0] $at_cli_args"])
731   echo
733   # Try to find a few ChangeLogs in case it might help determining the
734   # exact version.  Use the relative dir: if the top dir is a symlink,
735   # find will not follow it (and options to follow the links are not
736   # portable), which would result in no output here.
737   if test -n "$at_top_srcdir"; then
738     AS_BOX([ChangeLogs.])
739     echo
740     for at_file in `find "$at_top_srcdir" -name ChangeLog -print`
741     do
742       AS_ECHO(["$as_me: $at_file:"])
743       sed 's/^/| /;10q' $at_file
744       echo
745     done
747     AS_UNAME
748     echo
749   fi
751   # Contents of the config files.
752   for at_file in atconfig atlocal
753   do
754     test -r $at_file || continue
755     AS_ECHO(["$as_me: $at_file:"])
756     sed 's/^/| /' $at_file
757     echo
758   done
760   AS_BOX([Tested programs.])
761   echo
762 } >&AS_MESSAGE_LOG_FD
764 # Report what programs are being tested.
765 for at_program in : $at_tested
767   test "$at_program" = : && continue
768   _AS_PATH_WALK([$PATH], [test -f "$as_dir/$at_program" && break])
769   if test -f "$as_dir/$at_program"; then
770     {
771       AS_ECHO(["$at_srcdir/AT_LINE: $as_dir/$at_program --version"])
772       "$as_dir/$at_program" --version
773       echo
774     } >&AS_MESSAGE_LOG_FD 2>&1
775   else
776     AS_ERROR([cannot find $at_program])
777   fi
778 done
781   AS_BOX([Running the tests.])
782 } >&AS_MESSAGE_LOG_FD
784 at_start_date=`date`
785 at_start_time=`date +%s 2>/dev/null`
786 AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
787 at_xpass_list=
788 at_xfail_list=
789 at_pass_list=
790 at_fail_list=
791 at_skip_list=
792 at_group_count=0
793 m4_divert_pop([PREPARE_TESTS])dnl
794 m4_divert_push([TESTS])dnl
796 # Create the master directory if it doesn't already exist.
797 test -d "$at_suite_dir" ||
798   mkdir "$at_suite_dir" ||
799   AS_ERROR([cannot create '$at_suite_dir'])
801 # Can we diff with `/dev/null'?  DU 5.0 refuses.
802 if diff /dev/null /dev/null >/dev/null 2>&1; then
803   at_devnull=/dev/null
804 else
805   at_devnull=$at_suite_dir/devnull
806   >"$at_devnull"
809 # Use `diff -u' when possible.
810 if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
811 then
812   at_diff='diff -u'
813 else
814   at_diff=diff
818 m4_text_box([Driver loop.])
819 for at_group in $at_groups
821   # Be sure to come back to the top test directory.
822   cd "$at_suite_dir"
824   # Clearly separate the test groups when verbose.
825   test $at_group_count != 0 && $at_verbose echo
827   case $at_group in
828     banner-*)
829       at_group_log=$at_suite_log
830       ;;
832     *)
833       at_group_normalized=$at_group
834       _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
836       # Create a fresh directory for the next test group, and enter.
837       at_group_dir=$at_suite_dir/$at_group_normalized
838       at_group_log=$at_group_dir/$as_me.log
839       if test -d "$at_group_dir"; then
840         find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
841         rm -fr "$at_group_dir" ||
842           AS_WARN([test directory could not be cleaned.])
843       fi
844       # Be tolerant if the above `rm' was not able to remove the directory.
845       AS_MKDIR_P([$at_group_dir])
846       cd $at_group_dir
847       ;;
848   esac
850   echo 0 > "$at_status_file"
852   # In verbose mode, append to the log file *and* show on
853   # the standard output; in quiet mode only write to the log
854   if test -z "$at_verbose"; then
855     at_tee_pipe='tee -a "$at_group_log"'
856   else
857     at_tee_pipe='cat >> "$at_group_log"'
858   fi
860   case $at_group in
861 dnl Test groups inserted here (TESTS).
862 m4_divert_pop([TESTS])[]dnl
863 m4_divert_push([TESTS_END])[]dnl
865   * )
866     AS_ECHO(["$as_me: no such test group: $at_group"]) >&2
867     continue
868     ;;
869   esac
871   # Be sure to come back to the suite directory, in particular
872   # since below we might `rm' the group directory we are in currently.
873   cd "$at_suite_dir"
875   case $at_group in
876     banner-*) ;;
877     *)
878       if test ! -f "$at_check_line_file"; then
879         sed "s/^ */$as_me: warning: /" <<_ATEOF
880         A failure happened in a test group before any test could be
881         run. This means that test suite is improperly designed.  Please
882         report this failure to <AT_PACKAGE_BUGREPORT>.
883 _ATEOF
884         AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
885       fi
886       at_group_count=`expr 1 + $at_group_count`
887       $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
888       AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
889       case $at_xfail:$at_status in
890         yes:0)
891             at_msg="UNEXPECTED PASS"
892             at_xpass_list="$at_xpass_list $at_group"
893             at_errexit=$at_errexit_p
894             ;;
895         no:0)
896             at_msg="ok"
897             at_pass_list="$at_pass_list $at_group"
898             at_errexit=false
899             ;;
900         *:77)
901             at_msg='skipped ('`cat "$at_check_line_file"`')'
902             at_skip_list="$at_skip_list $at_group"
903             at_errexit=false
904             ;;
905         yes:*)
906             at_msg='expected failure ('`cat "$at_check_line_file"`')'
907             at_xfail_list="$at_xfail_list $at_group"
908             at_errexit=false
909             ;;
910         no:*)
911             at_msg='FAILED ('`cat "$at_check_line_file"`')'
912             at_fail_list="$at_fail_list $at_group"
913             at_errexit=$at_errexit_p
914             ;;
915       esac
916       # Make sure there is a separator even with long titles.
917       AS_ECHO([" $at_msg"])
918       at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
919       case $at_status in
920         0|77)
921           # $at_times_file is only available if the group succeeded.
922           # We're not including the group log, so the success message
923           # is written in the global log separately.  But we also
924           # write to the group log in case they're using -d.
925           if test -f "$at_times_file"; then
926             at_log_msg="$at_log_msg     ("`sed 1d "$at_times_file"`')'
927             rm -f "$at_times_file"
928           fi
929           AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
930           AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
932           # Cleanup the group directory, unless the user wants the files.
933           if $at_debug_p ; then
934             _AT_CREATE_DEBUGGING_SCRIPT
935           elif test -d "$at_group_dir"; then
936             find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
937             rm -fr "$at_group_dir"
938           fi
939           ;;
940         *)
941           # Upon failure, include the log into the testsuite's global
942           # log.  The failure message is written in the group log.  It
943           # is later included in the global log.
944           AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
946           # Upon failure, keep the group directory for autopsy, and
947           # create the debugging script.
948           _AT_CREATE_DEBUGGING_SCRIPT
949           $at_errexit && break
950           ;;
951       esac
952       ;;
953   esac
954 done
956 # Back to the top directory.
957 cd "$at_dir"
959 # Compute the duration of the suite.
960 at_stop_date=`date`
961 at_stop_time=`date +%s 2>/dev/null`
962 AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
963 case $at_start_time,$at_stop_time in
964   [[0-9]*,[0-9]*])
965     at_duration_s=`expr $at_stop_time - $at_start_time`
966     at_duration_m=`expr $at_duration_s / 60`
967     at_duration_h=`expr $at_duration_m / 60`
968     at_duration_s=`expr $at_duration_s % 60`
969     at_duration_m=`expr $at_duration_m % 60`
970     at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
971     AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
972     ;;
973 esac
975 # Wrap up the test suite with summary statistics.
976 set X $at_skip_list; shift; at_skip_count=$[@%:@]
977 set X $at_fail_list; shift; at_fail_count=$[@%:@]
978 set X $at_xpass_list; shift; at_xpass_count=$[@%:@]
979 set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
981 at_run_count=`expr $at_group_count - $at_skip_count`
982 at_unexpected_count=`expr $at_xpass_count + $at_fail_count`
983 at_total_fail_count=`expr $at_xfail_count + $at_fail_count`
985 echo
986 AS_BOX([Test results.])
987 echo
989   echo
990   AS_BOX([Test results.])
991   echo
992 } >&AS_MESSAGE_LOG_FD
995 dnl FIXME: this code is as far from i18n-cleanness as man
996 dnl could imagine...
998 if test $at_run_count = 1; then
999   at_result="1 test"
1000   at_were=was
1001 else
1002   at_result="$at_run_count tests"
1003   at_were=were
1005 if $at_errexit_p && test $at_unexpected_count != 0; then
1006   if test $at_xpass_count = 1; then
1007     at_result="$at_result $at_were run, one passed"
1008   else
1009     at_result="$at_result $at_were run, one failed"
1010   fi
1011   at_result="$at_result unexpectedly and inhibited subsequent tests."
1012 else
1013   # Don't you just love exponential explosion of the number of cases?
1014   case $at_xpass_count:$at_fail_count:$at_xfail_count in
1015     # So far, so good.
1016     0:0:0) at_result="$at_result $at_were successful." ;;
1017     0:0:*) at_result="$at_result behaved as expected." ;;
1019     # Some unexpected failures
1020     0:*:0) at_result="$at_result $at_were run,
1021 $at_fail_count failed unexpectedly." ;;
1023     # Some failures, both expected and unexpected
1024     0:*:1) at_result="$at_result $at_were run,
1025 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1026     0:*:*) at_result="$at_result $at_were run,
1027 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1029     # No unexpected failures, but some xpasses
1030     *:0:*) at_result="$at_result $at_were run,
1031 $at_xpass_count passed unexpectedly." ;;
1033     # No expected failures, but failures and xpasses
1034     *:1:0) at_result="$at_result $at_were run,
1035 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failure)." ;;
1036     *:*:0) at_result="$at_result $at_were run,
1037 $at_unexpected_count did not behave as expected ($at_fail_count unexpected failures)." ;;
1039     # All of them.
1040     *:*:1) at_result="$at_result $at_were run,
1041 $at_xpass_count passed unexpectedly,
1042 $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
1043     *:*:*) at_result="$at_result $at_were run,
1044 $at_xpass_count passed unexpectedly,
1045 $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
1046   esac
1048   if test $at_skip_count = 0 && test $at_run_count -gt 1; then
1049     at_result="All $at_result"
1050   fi
1053 # Now put skips in the mix.
1054 case $at_skip_count in
1055   0) ;;
1056   1) at_result="$at_result
1057 1 test was skipped." ;;
1058   *) at_result="$at_result
1059 $at_skip_count tests were skipped." ;;
1060 esac
1062 if test $at_unexpected_count = 0; then
1063   echo "$at_result"
1064   echo "$at_result" >&AS_MESSAGE_LOG_FD
1065 else
1066   echo "ERROR: $at_result" >&2
1067   echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
1068   {
1069     echo
1070     AS_BOX([Summary of the failures.])
1072     # Summary of failed and skipped tests.
1073     if test $at_fail_count != 0; then
1074       echo "Failed tests:"
1075       $SHELL "$[0]" $at_fail_list --list
1076       echo
1077     fi
1078     if test $at_skip_count != 0; then
1079       echo "Skipped tests:"
1080       $SHELL "$[0]" $at_skip_list --list
1081       echo
1082     fi
1083     if test $at_xpass_count != 0; then
1084       echo "Unexpected passes:"
1085       $SHELL "$[0]" $at_xpass_list --list
1086       echo
1087     fi
1088     if test $at_fail_count != 0; then
1089       AS_BOX([Detailed failed tests.])
1090       echo
1091       for at_group in $at_fail_list
1092       do
1093         at_group_normalized=$at_group
1094         _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
1095         cat "$at_suite_dir/$at_group_normalized/$as_me.log"
1096         echo
1097       done
1098       echo
1099     fi
1100     if test -n "$at_top_srcdir"; then
1101       AS_BOX([${at_top_build_prefix}config.log])
1102       sed 's/^/| /' ${at_top_build_prefix}config.log
1103       echo
1104     fi
1105   } >&AS_MESSAGE_LOG_FD
1107   AS_BOX([$as_me.log was created.])
1109   echo
1110   AS_ECHO(["Please send \`${at_testdir+${at_testdir}/}$as_me.log' and all information you think might help:
1112    To: <AT_PACKAGE_BUGREPORT>
1113    Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me:dnl
1114 $at_fail_list${at_fail_list:+ failed${at_xpass_list:+,}}dnl
1115 $at_xpass_list${at_xpass_list:+ passed unexpectedly}
1117   if test $at_debug_p = false; then
1118     echo
1119     echo 'You may investigate any problem if you feel able to do so, in which'
1120     echo 'case the test suite provides a good starting point.  Its output may'
1121     AS_ECHO(["be found below \`${at_testdir+${at_testdir}/}$as_me.dir'."])
1122     echo
1123   fi
1124     exit 1
1127 exit 0
1129 m4_text_box([Actual tests.])
1130 m4_divert_pop([TESTS_END])dnl
1131 dnl End of AT_INIT: divert to KILL, only test groups are to be
1132 dnl output, the rest is ignored.  Current diversion is BODY, inherited
1133 dnl from M4sh.
1134 m4_divert_pop([BODY])
1135 m4_divert_push([KILL])
1136 ])# AT_INIT
1139 # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
1140 #                [ACTION-IF-NOT-GIVEN])
1141 # ---------------------------------------------------------------------------
1142 # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
1143 m4_defun([_AT_ARG_OPTION],
1144 [m4_divert_once([HELP_OTHER],
1145 [cat <<_ATEOF
1147 Other options:
1148 _ATEOF
1149 ])dnl m4_divert_once HELP_OTHER
1150 m4_divert_text([HELP_OTHER],
1151 [cat <<_ATEOF
1153 _ATEOF])dnl
1154 dnl Turn our options into our desired strings
1155 m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
1156 m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
1157 m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
1158 m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
1159 m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
1160 [m4_define_default([AT_first_option],AT_option)dnl
1161 m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
1162 m4_append([AT_case_no],[--no]AT_option, [ | ])dnl
1163 m4_append([AT_case_arg],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
1164 ])dnl m4_foreach AT_option
1165 dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
1166 m4_divert_once([PARSE_ARGS_BEGIN],
1169 ## Set up package specific options.
1171 ])dnl
1172 m4_divert_text([PARSE_ARGS_BEGIN],
1173 [dnl Provide a default value for options without arguments.
1174 m4_ifvaln([$3],,[at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false])dnl
1175 at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=false
1176 ])dnl m4_divert_text DEFAULTS
1177 m4_ifval([$3],[m4_divert_once([PARSE_ARGS_END],
1180 ## Verify our last option didn't require an argument
1182 AS_IF([test -n "$at_prev"],[AS_ERROR([`$at_prev' requires an argument.])])])])
1183 m4_divert_text([PARSE_ARGS],
1184 [dnl Parse the options and args when necessary.
1185 m4_ifvaln([$3],
1186 [    AT_case )
1187         at_prev=--m4_bpatsubst([AT_first_option], -, _)
1188         ;;
1189     AT_case_arg )
1190         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=$at_optarg
1191         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1192         $4
1193         ;;],
1194 [    AT_case )
1195         at_optarg=:
1196         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=:
1197         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1198         m4_ifval([$4],[$4])dnl
1199         ;;
1200     AT_case_no )
1201         at_optarg=false
1202         at_arg_[]m4_bpatsubst([AT_first_option], -, _)=false
1203         at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)=:
1204         m4_ifval([$4],[$4])dnl
1205         ;;])dnl m4_ifvaln $3
1206 ])dnl m4_divert_text PARSE_ARGS
1207 m4_ifvaln([$5],
1208 [m4_divert_once([PARSE_ARGS_END],
1211 ## Process package specific options when _not_ supplied.
1212 ##])dnl m4_divert_once PARSE_ARGS_END
1213 m4_divert_text([PARSE_ARGS_END],
1215 AS_IF([$at_arg_given_[]m4_bpatsubst([AT_first_option], -, _)],,[$5])dnl
1216 ])dnl m4_divert_text PARSE_ARGS_END
1217 ])dnl m4_ifvaln $5
1218 ])dnl _AT_ARG_OPTION
1221 # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1222 # ------------------------------------------------------------------------
1223 # Accept a set of OPTIONS with arguments.  Add HELP-TEXT to the HELP_OTHER
1224 # diversion.
1226 # Preceding dashes should not be passed into OPTIONS.  Users will be required
1227 # to pass `--' before long options and `-' before single character options.
1229 # $at_arg_OPTION will be set to `:' if this option is received, `false' if
1230 # if --noOPTION is received, and `false' by default.
1232 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1233 # $at_optarg set to `:' or `false' as appropriate.  $at_optarg is actually
1234 # just a copy of $at_arg_OPTION.
1236 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1237 # if no option from OPTIONS was found.
1238 m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
1241 # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
1242 # ---------------------------------------------------------------------------
1243 # Accept a set of OPTIONS with arguments, seperated by commas.  Add HELP-TEXT
1244 # to the HELP_OTHER diversion.
1246 # Preceding dashes should not be passed into OPTIONS.  Users will be required
1247 # to pass `--' before long options and `-' before single character options.
1249 # By default, any argument to these options will be assigned to the shell
1250 # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
1251 # any `-' characters replaced with `_'.
1253 # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered with
1254 # $at_optarg set.  $at_optarg is actually just a copy of $at_arg_OPTION.
1256 # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
1257 # if no option from OPTIONS was found.
1258 m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
1261 # AT_TESTED(PROGRAMS)
1262 # -------------------
1263 # Specify the list of programs exercised by the test suite.  Their
1264 # versions are logged, and in the case of embedded test suite, they
1265 # must correspond to the version of the package.  PATH should be
1266 # already preset so the proper executable will be selected.
1267 m4_define([AT_TESTED],
1268 [m4_append_uniq([AT_tested], [$1], [
1269 ])])
1272 # AT_COPYRIGHT(TEXT)
1273 # ------------------
1274 # Emit TEXT, a copyright notice, in the top of the test suite and in
1275 # --version output.  Macros in TEXT are evaluated once.
1276 m4_define([AT_COPYRIGHT],
1277 [AS_COPYRIGHT([$1])[]dnl
1278 m4_divert_text([VERSION_NOTICES],
1280 $1])])# AT_COPYRIGHT
1283 # AT_SETUP(DESCRIPTION)
1284 # ---------------------
1285 # Start a group of related tests, all to be executed in the same subshell.
1286 # The group is testing what DESCRIPTION says.
1287 m4_define([AT_SETUP],
1288 [m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
1289 m4_define([AT_capture_files], [])
1290 m4_define([AT_line], AT_LINE)
1291 m4_define([AT_xfail], [at_xfail=no])
1292 m4_define([AT_description], m4_quote($1))
1293 m4_define([AT_ordinal], m4_incr(AT_ordinal))
1294 m4_append([AT_groups_all], [ ]m4_defn([AT_ordinal]))
1295 m4_divert_push([TEST_FUNCTIONS])dnl
1296 [#AT_START_]AT_ordinal
1297 @%:@ AT_ordinal. m4_defn([AT_line]): m4_defn([AT_description])
1298 at_func_test_[]AT_ordinal ()
1300     at_setup_line='m4_defn([AT_line])'
1301     at_desc="AS_ESCAPE(m4_dquote(m4_defn([AT_description])))"
1302     $at_quiet AS_ECHO_N([m4_format(["%3d: $at_desc%*s"], AT_ordinal,
1303       m4_max(0, m4_eval(47 - m4_qlen(m4_defn([AT_description])))), [])])
1304 m4_divert_push([TEST_SCRIPT])dnl
1308 # AT_XFAIL_IF(SHELL-EXPRESSION)
1309 # -----------------------------
1310 # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
1311 # true (exitcode = 0).
1312 m4_define([AT_XFAIL_IF],
1313 [dnl
1314 dnl Try to limit the amount of conditionals that we emit.
1315 m4_case([$1],
1316       [], [],
1317       [false], [],
1318       [:], [m4_define([AT_xfail], [at_xfail=yes])],
1319       [true], [m4_define([AT_xfail], [at_xfail=yes])],
1320       [m4_append([AT_xfail], [
1321       $1 && at_xfail=yes])])])
1324 # AT_KEYWORDS(KEYWORDS)
1325 # ---------------------
1326 # Declare a list of keywords associated to the current test group.
1327 m4_define([AT_KEYWORDS],
1328 [m4_append_uniq([AT_keywords], [$1], [ ])])
1331 # AT_CAPTURE_FILE(FILE)
1332 # ---------------------
1333 # If the current test group does not behave as expected, save the contents of
1334 # FILE in the test suite log.
1335 m4_define([AT_CAPTURE_FILE],
1336 [m4_append_uniq([AT_capture_files], ["$1"], [ \
1337 ])])
1340 # AT_CLEANUP
1341 # ----------
1342 # Complete a group of related tests.
1343 m4_define([AT_CLEANUP],
1344 [m4_append([AT_help_all],
1345 m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
1346 )dnl
1347 m4_divert_pop([TEST_SCRIPT])dnl Back to TEST_FUNCTIONS
1348     AT_xfail
1349     echo "#                             -*- compilation -*-" >> "$at_group_log"
1350     (
1351       AS_ECHO(["AT_ordinal. m4_defn([AT_line]): testing $1..."])
1352       $at_traceon
1353 m4_undivert([TEST_SCRIPT])dnl Insert the code here
1354       $at_traceoff
1355       $at_times_p && times >"$at_times_file"
1356     ) AS_MESSAGE_LOG_FD>&1 2>&1 | eval $at_tee_pipe
1357     at_status=`cat "$at_status_file"`
1359 [#AT_STOP_]AT_ordinal
1360 m4_divert_pop([TEST_FUNCTIONS])dnl Back to KILL.
1361 m4_divert_text([TESTS],
1362 [  AT_ordinal ) at_func_test AT_ordinal ;;])
1363 ])# AT_CLEANUP
1366 # AT_BANNER(TEXT)
1367 # ---------------
1368 # Output TEXT without any shell expansion.
1369 m4_define([AT_BANNER],
1370 [m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
1371 m4_append([AT_groups_all], [ banner-]m4_defn([AT_banner_ordinal]))
1372 m4_divert_text([TESTS],
1374   banner-AT_banner_ordinal ) @%:@ Banner AT_banner_ordinal. AT_LINE
1375     cat <<\_ATEOF
1379 _ATEOF
1380     ;;
1381 ])dnl
1382 ])# AT_BANNER
1385 # AT_DATA(FILE, CONTENTS)
1386 # -----------------------
1387 # Initialize an input data FILE with given CONTENTS, which should end with
1388 # an end of line.
1389 # This macro is not robust to active symbols in CONTENTS *on purpose*.
1390 # If you don't want CONTENTS to be evaluated, quote it twice.
1391 m4_define([AT_DATA],
1392 [cat >$1 <<'_ATEOF'
1393 $2[]_ATEOF
1397 # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1398 #          [RUN-IF-FAIL], [RUN-IF-PASS])
1399 # ------------------------------------------------
1400 # Execute a test by performing given shell COMMANDS.  These commands
1401 # should normally exit with STATUS, while producing expected STDOUT and
1402 # STDERR contents.  Shell metacharacters in STDOUT and STDERR are
1403 # _not_ processed by the shell, but are treated as string literals.
1405 # STATUS, STDOUT, and STDERR are not checked if equal to `ignore'.
1407 # If STDOUT is `expout', then stdout is compared to the content of the file
1408 # `expout'.  Likewise for STDERR and `experr'.
1410 # If STDOUT is `stdout', then the stdout is left in the file `stdout',
1411 # likewise for STDERR and `stderr'.  Don't do this:
1413 #    AT_CHECK([command >out])
1414 #    # Some checks on `out'
1416 # do this instead:
1418 #    AT_CHECK([command], [], [stdout])
1419 #    # Some checks on `stdout'
1421 # You might wonder why you can't just use `ignore', then directly use stdout
1422 # and stderr left by the test suite:
1424 #    AT_CHECK([command], [], [ignore])
1425 #    AT_CHECK([check stdout])
1427 # If the test suite always captured data in the file `stdout', then the
1428 # second command would be trying to read and write from the same file, with
1429 # undefined behavior.  Therefore, the test suite actually captures data in
1430 # an internal file of a different name, and only creates `stdout' when
1431 # explicitly requested.
1433 # Any line of stderr starting with leading blanks and a `+' are filtered
1434 # out, since most shells when tracing include subshell traces in stderr.
1435 # This may cause spurious failures when the test suite is run with `-x'.
1437 m4_define([AT_CHECK],
1438 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6],1)])
1440 # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1441 #                   [RUN-IF-FAIL], [RUN-IF-PASS])
1442 # ---------------------------------------------------------
1443 # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
1444 # and STDERR arguments before running the comparison.
1445 m4_define([AT_CHECK_NOESCAPE],
1446 [_AT_CHECK([$1],[$2],[$3],[$4],[$5],[$6])])
1449 # _AT_DECIDE_TRACEABLE(COMMANDS)
1450 # ------------------------------
1451 # Worker for for _AT_CHECK that expands to shell code.  If COMMANDS are safe to
1452 # trace with `set -x', the shell code will evaluate to true.  Otherwise,
1453 # the shell code will print a message stating an aspect of COMMANDS that makes
1454 # tracing them unsafe, and evaluate to false.
1456 # Tracing COMMANDS is not safe if they contain a command that spans multiple
1457 # lines.  When the test suite user passes `-x' or `--trace', the test suite
1458 # precedes every command with a `set -x'.  Since most tests expect a specific
1459 # stderr, if only to confirm that it is empty, the test suite filters ^+ from
1460 # the captured stderr before comparing with the expected stderr.  If a command
1461 # spans multiple lines, so will its trace, but a `+' only prefixes the first
1462 # line of that trace:
1464 # $ echo 'foo
1465 # bar'
1466 # => stdout
1467 # foo
1468 # bar
1469 # => stderr
1470 # + foo
1471 # bar
1473 # In a subset of cases, one could filter such extended shell traces from stderr.
1474 # Since test commands spanning several lines are rare, I chose instead to simply
1475 # not trace COMMANDS that could yield multiple trace lines.  Distinguishing such
1476 # COMMANDS became the task at hand.
1478 # These features may cause a shell command to span multiple lines:
1480 # (a) A quoted literal newline.
1481 # Example:
1482 #   echo foo'
1483 #   'bar
1484 # M4 is a hostile language for the job of parsing COMMANDS to determine whether
1485 # each literal newline is quoted, so we simply disable tracing for all COMMANDS
1486 # that bear literal newlines.
1488 # (b) A command substitution not subject to word splitting.
1489 # Example:
1490 #   var=$(printf 'foo\nbar')
1491 # Example:
1492 #   echo "`printf 'foo\\nbar`"
1493 # One cannot know in general the number of lines a command substitution will
1494 # yield without executing the substituted command.  As such, we disable tracing
1495 # for all COMMANDS containing these constructs.
1497 # (c) A parameter expansion not subject to word splitting.
1498 # Example:
1499 #   var=foo'
1500 #   'bar
1501 #   echo "$var"
1502 # Parameter expansions appear in COMMANDS with much greater frequency than do
1503 # newlines and command substitutions, so disabling tracing for all such COMMANDS
1504 # would much more substantially devalue `testsuite -x'.  To determine which
1505 # parameter expansions yield multiple lines, we escape all ``', `"', and `\' in
1506 # a copy of COMMANDS and expand that string within double quotes at runtime.  If
1507 # the result of that expansion contains multiple lines, the test suite disables
1508 # tracing for the command in question.
1510 # This method leads the test suite to expand some parameters that the shell
1511 # itself will never expand due to single-quotes or backslash escapes.  This is
1512 # not a problem for `$foo' expansions, which will simply yield the empty string
1513 # or some unrelated value.  A `${...}' expansion could actually form invalid
1514 # shell code, however; consider `${=foo}'.  Therefore, we disable tracing for
1515 # all COMMANDS containing `${...}'.  This affects few COMMANDS.
1517 # This macro falls in a very hot path; the Autoconf test suite expands it 1640
1518 # times as of this writing.  To give a sense of the impact of the heuristics I
1519 # just described, the test suite preemptively disables tracing for 31 of those,
1520 # and 268 contain parameter expansions that require runtime evaluation.  The
1521 # balance are always safe to trace.
1523 # _AT_CHECK expands COMMANDS, but the Autoconf language does not provide a way
1524 # to safely expand arbitrary COMMANDS in an argument list, so the below tests
1525 # examine COMMANDS unexpanded.
1526 m4_define([_AT_DECIDE_TRACEABLE],
1527 dnl Utility macro.
1529 dnl Examine COMMANDS for a reason to never trace COMMANDS.
1530 [m4_pushdef([at_reason],
1531 m4_cond([m4_eval(m4_index([$1], [`]) >= 0)], [1],
1532                 [[a `...` command substitution]],
1533         [m4_eval(m4_index([$1], [$(]) >= 0)], [1],
1534                 [[a $(...) command substitution]],
1535         [m4_eval(m4_index([$1], [${]) >= 0)], [1],
1536                 [[a ${...} parameter expansion]],
1537         [m4_eval(m4_index([$1], m4_newline) >= 0)], [1],
1538                 [[an embedded newline]],
1539         []dnl No reason.
1540 ))dnl
1542 m4_ifval(m4_defn([at_reason]),
1543 [{ echo 'Not enabling shell tracing (command contains ]m4_defn([at_reason])[)'; false; }],
1544 [m4_if(m4_index([$1], [$]), [-1],
1545 dnl We know at build time that tracing COMMANDS is always safe.
1546 [test -n "$at_traceon"],
1547 dnl COMMANDS may contain parameter expansions; expand them at runtime.
1548 [test -n "$at_traceon" && at_func_check_newline "AS_ESCAPE([$1], [`\"])"])])[]dnl
1549 m4_popdef([at_reason])])
1552 # AT_DIFF_STDERR/AT_DIFF_STDOUT
1553 # -----------------------------
1554 # These are subroutines of AT_CHECK.  Using indirect dispatch is a tad
1555 # faster than using m4_case, and these are called very frequently.
1556 m4_define([AT_DIFF_STDERR(stderr)],
1557           [echo stderr:; tee stderr <"$at_stderr"])
1558 m4_define([AT_DIFF_STDERR(ignore)],
1559           [echo stderr:; cat "$at_stderr"])
1560 m4_define([AT_DIFF_STDERR(experr)],
1561           [$at_diff experr "$at_stderr" || at_failed=:])
1562 m4_define([AT_DIFF_STDERR()],
1563           [at_func_diff_devnull "$at_stderr" || at_failed=:])
1565 m4_define([AT_DIFF_STDOUT(stdout)],
1566           [echo stdout:; tee stdout <"$at_stdout"])
1567 m4_define([AT_DIFF_STDOUT(ignore)],
1568           [echo stdout:; cat "$at_stdout"])
1569 m4_define([AT_DIFF_STDOUT(expout)],
1570           [$at_diff expout "$at_stdout" || at_failed=:])
1571 m4_define([AT_DIFF_STDOUT()],
1572           [at_func_diff_devnull "$at_stdout" || at_failed=:])
1574 # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
1575 #           [RUN-IF-FAIL], [RUN-IF-PASS], SHELL_ESCAPE_IO)
1576 # ---------------------------------------------------------
1577 # Worker for AT_CHECK & AT_CHECK_NOESCAPE.  The final SHELL-ESCAPE-IO
1578 # argument determines whether the STDOUT & STDERR arguments will be escaped or
1579 # not.
1582 # Implementation Details
1583 # ----------------------
1584 # Ideally, we would like to run
1586 #    ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
1588 # but we must group COMMANDS as it is not limited to a single command, and
1589 # then the shells will save the traces in at-stderr. So we have to filter
1590 # them out when checking stderr, and we must send them into the test suite's
1591 # stderr to honor -x properly. Since only the first line of the trace of a
1592 # multiline command starts with a `+', and I know of no straightforward way to
1593 # filter out the unadorned trace lines, we disable shell tracing entirely for
1594 # commands that could span multiple lines.
1596 # Limiting COMMANDS to a single command is not good either, since them
1597 # the user herself would use {} or (), and then we face the same problem.
1599 # But then, there is no point in running
1601 #   ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
1603 # instead of the simpler
1605 #  ( $at_traceon; $1 ) >at-stdout 2>at-stder1
1607 m4_define([_AT_CHECK],
1608 [$at_traceoff
1609 AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([$1])"])
1610 echo AT_LINE >"$at_check_line_file"
1612 if _AT_DECIDE_TRACEABLE([$1]); then
1613     ( $at_traceon; $1 ) >"$at_stdout" 2>"$at_stder1"
1614     at_func_filter_trace $?
1615 else
1616     ( :; $1 ) >"$at_stdout" 2>"$at_stderr"
1618 at_status=$?
1619 at_failed=false
1620 m4_ifdef([AT_DIFF_STDERR($4)], [m4_indir([AT_DIFF_STDERR($4)])],
1621          [echo >>"$at_stderr"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$4])],[$4])"]) | \
1622           $at_diff - "$at_stderr" || at_failed=:])
1623 m4_ifdef([AT_DIFF_STDOUT($3)], [m4_indir([AT_DIFF_STDOUT($3)])],
1624          [echo >>"$at_stdout"; AS_ECHO(["m4_ifval([$7],[AS_ESCAPE([$3])],[$3])"]) | \
1625           $at_diff - "$at_stdout" || at_failed=:])
1626 m4_if([$2], [ignore], [at_func_check_skip],
1627       [at_func_check_status m4_default([$2], [0])]) dnl
1628      $at_status "$at_srcdir/AT_LINE"
1629 AS_IF($at_failed, [$5], [$6])
1630 $at_failed && at_func_log_failure AT_capture_files
1631 $at_traceon
1632 ])# _AT_CHECK