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