3 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 # 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
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)
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/>.
21 # IMPORTANT NOTE: This file should execute correctly with any system's
22 # /bin/sh shell, and not only with configure-time detected $CONFIG_SHELL,
23 # until differently and explicitly specified.
26 ## -------------------------------------------------------- ##
27 ## Source static setup and definitions for the testsuite. ##
28 ## -------------------------------------------------------- ##
30 # This code needs to be 'set -e' clean.
32 # Ensure we are running from the right directory.
33 test -f ./defs-static || {
34 echo "$0: ./defs-static: not found in current directory" >&2
38 # Source the shell sanitization and variables' definitions.
39 . ./defs-static || exit 99
41 # The name of the current test (without the `.test' suffix).
42 # Test scripts can override it if they need to (but this should
43 # be done carefully, and *before* including ./defs).
44 if test -z "$me"; then
45 # Guard against failure to spawn sed (seen on MSYS), or empty $argv0.
46 me=`echo "$argv0" | sed -e 's,.*[\\/],,;s/\.test$//'` \
48 || { echo "$argv0: failed to define \$me" >&2; exit 99; }
51 ## ---------------------- ##
52 ## Early sanity checks. ##
53 ## ---------------------- ##
55 # A single whitespace character.
57 # A tabulation character.
59 # A newline character.
63 # As autoconf-generated configure scripts do, ensure that IFS
64 # is defined initially, so that saving and restoring $IFS works.
67 # Ensure $testsrcdir is set correctly.
68 test -f "$testsrcdir/defs-static.in" || {
69 echo "$me: $testsrcdir/defs-static.in not found, check \$testsrcdir" >&2
73 # Ensure $testbuilddir is set correctly.
74 test -f "$testbuilddir/defs-static" || {
75 echo "$me: $testbuilddir/defs-static not found, check \$testbuilddir" >&2
80 ## ------------------------------------ ##
81 ## Ensure we run with a proper shell. ##
82 ## ------------------------------------ ##
84 # Make sure we run with the shell detected at configure time (unless
85 # the user forbids it).
86 case ${AM_TESTS_REEXEC-yes} in
90 # Ensure we can find ourselves.
91 if test ! -f "$0"; then
92 echo "$me: unable to find myself: $0" >&2
95 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
96 # Cannot simply do `opts=$-', since the content of $- is not
97 # portable among different shells. So try to propagate only
98 # the portable and interesting options.
100 *x*v*|*v*x) opts=-vx;;
105 echo $me: exec $SHELL $opts "$0" "$*"
106 exec $SHELL $opts "$0" ${1+"$@"}
107 echo "$me: failed to re-execute with $SHELL" >&2
112 # NOTE: From this point on, we can assume this file is being executed
113 # by the configure-time detected $CONFIG_SHELL.
116 ## ---------------------- ##
117 ## Environment cleanup. ##
118 ## ---------------------- ##
120 # Unset some MAKE... variables that may cause $MAKE to act like a
121 # recursively invoked sub-make. Any $MAKE invocation in a test is
122 # conceptually an independent invocation, not part of the main
124 unset MFLAGS MAKEFLAGS AM_MAKEFLAGS MAKELEVEL __MKLVL__ MAKE_JOBS_FIFO
125 # Unset verbosity flag.
127 # Also unset variables that will let `make -e install' divert
128 # files into unwanted directories.
130 unset prefix exec_prefix bindir datarootdir datadir docdir dvidir
131 unset htmldir includedir infodir libdir libexecdir localedir mandir
132 unset oldincludedir pdfdir psdir sbindir sharedstatedir sysconfdir
133 # Unset variables that might change the "make distcheck" behaviour.
134 unset DISTCHECK_CONFIGURE_FLAGS AM_DISTCHECK_CONFIGURE_FLAGS
135 # The tests call `make -e' but we do not want $srcdir from the environment
136 # to override the definition from the Makefile.
138 # Also unset variables that control our test driver. While not
139 # conceptually independent, they cause some changed semantics we
140 # need to control (and test for) in some of the tests to ensure
141 # backward-compatible behavior.
142 unset TESTS_ENVIRONMENT
143 unset DISABLE_HARD_ERRORS
145 unset TEST_LOG_COMPILER
151 ## ---------------------------- ##
152 ## Auxiliary shell functions. ##
153 ## ---------------------------- ##
155 # This is used in `Exit' and in the exit trap. See comments in the latter
156 # for more information,
159 # We use a trap below for cleanup. This requires us to go through
160 # hoops to get the right exit status transported through the signal.
161 # So use `Exit STATUS' instead of `exit STATUS' inside of the tests.
162 # Turn off errexit here so that we don't trip the bug with OSF1/Tru64
163 # sh inside this function.
167 # See comments in the exit trap for the reason we do this.
168 test 77 = $1 && am__test_skipped=yes
172 # Print warnings (e.g., about skipped and failed tests) to this file
173 # number. Override by putting, say:
174 # stderr_fileno_=9; export stderr_fileno_; 9>&2
175 # at the *end* (yes, this is mandatory; see comments in Makefile.am) of
176 # the definition of AM_TESTS_ENVIRONMENT.
177 # This is useful when using automake's parallel tests mode, to print the
178 # reason for skip/failure to console, rather than to the *.log files.
179 : ${stderr_fileno_=2}
181 # Copied from Gnulib's `tests/init.sh'.
182 warn_ () { echo "$@" 1>&$stderr_fileno_; }
183 fail_ () { warn_ "$me: failed test: $@"; Exit 1; }
184 skip_ () { warn_ "$me: skipped test: $@"; Exit 77; }
185 fatal_ () { warn_ "$me: hard error: $@"; Exit 99; }
186 framework_failure_ () { warn_ "$me: set-up failure: $@"; Exit 99; }
190 # Tell whether we are cross-compiling. This is especially useful to skip
191 # tests (or portions of them) that requires a native compiler.
194 test x"$host_alias" != x && test x"$build_alias" != x"$host_alias"
197 # is_newest FILE FILES
198 # --------------------
199 # Return false if any file in FILES is newer than FILE.
200 # Resolve ties in favor of FILE.
203 is_newest_files=`find "$@" -prune -newer "$1"`
204 test -z "$is_newest_files"
207 # AUTOMAKE_run status [options...]
208 # --------------------------------
209 # Run Automake with OPTIONS, and fail if automake
210 # does not exit with STATUS.
216 $AUTOMAKE ${1+"$@"} >stdout 2>stderr || exitcode=$?
219 test $exitcode = $expected_exitcode || Exit 1
222 # AUTOMAKE_fails [options...]
223 # ---------------------------
224 # Run Automake with OPTIONS, and fail if automake
225 # does not exit with STATUS.
228 AUTOMAKE_run 1 ${1+"$@"}
233 # Return success if $MAKE is GNU make, return failure otherwise.
234 # Caches the result for speed reasons.
237 case $am__using_gmake in
243 # Use --version AND -v, because SGI Make doesn't fail on --version.
244 # Also grep for GNU because newer versions of FreeBSD make do
245 # not complain about `--version' (they seem to silently ignore it).
246 if $MAKE --version -v | grep GNU; then
254 echo "invalid value for \$am__using_gmake: '$am__using_gmake'" >&2
258 am__using_gmake="" # Avoid interferences from the environment.
260 # seq_ - print a sequence of numbers
261 # ----------------------------------
262 # This function simulates GNU seq(1) portably. Valid usages:
265 # - seq FIRST INCREMENT LAST
269 0) fatal_ "seq_: missing argument";;
270 1) seq_first=1 seq_incr=1 seq_last=$1;;
271 2) seq_first=$1 seq_incr=1 seq_last=$2;;
272 3) seq_first=$1 seq_incr=$2 seq_last=$3;;
273 *) fatal_ "seq_: too many arguments";;
275 # Try to avoid forks if possible.
276 case "$BASH_VERSION" in
278 : Not bash, or a too old bash version. ;;
280 # Use eval to protect dumber shells from parsing errors.
281 eval 'for ((i = seq_first; i <= seq_last; i += seq_incr)); do
286 # Else, use GNU seq if available.
288 # Otherwise revert to a slower loop using expr(1).
290 while test $i -le $seq_last; do
292 i=`expr $i + $seq_incr`
296 commented_sed_unindent_prog='
297 /^$/b # Nothing to do for empty lines.
298 x # Get x<indent> into pattern space.
299 /^$/{ # No prior x<indent>, go prepare it.
300 g # Copy this 1st non-blank line into pattern space.
301 s/^\(['"$tab"' ]*\).*/x\1/ # Prepare x<indent> in pattern space.
302 } # Now: x<indent> in pattern and <line> in hold.
303 G # Build x<indent>\n<line> in pattern space, and
304 h # duplicate it into hold space.
305 s/\n.*$// # Restore x<indent> in pattern space, and
306 x # exchange with the above duplicate in hold space.
307 s/^x\(.*\)\n\1// # Remove leading <indent> from <line>.
308 s/^x.*\n// # Restore <line> when there is no leading <indent>.
311 # unindent [input files...]
312 # -------------------------
313 # Remove the "proper" amount of leading whitespace from the given files,
314 # and output the result on stdout. That amount is determined by looking
315 # at the leading whitespace of the first non-blank line in the input
316 # files. If no input file is specified, standard input is implied.
319 if test x"$sed_unindent_prog" = x; then
320 sed_unindent_prog=`printf '%s\n' "$commented_sed_unindent_prog" | sed -e "s/ *# .*//"`
322 sed "$sed_unindent_prog" ${1+"$@"}
324 sed_unindent_prog="" # Avoid interferences from the environment.
326 # get_shell_script SCRIPT-NAME
327 # -----------------------------
328 # Fetch an Automake-provided test script from the `lib/' directory into
329 # the current directory, and, if the `$test_prefer_config_shell' variable
330 # is set to "yes", modify its shebang line to use $SHELL instead of
334 if test x"$test_prefer_config_shell" = x"yes"; then
335 sed "1s|#!.*|#! $SHELL|" "$top_testsrcdir/lib/$1" > "$1"
338 cp "$top_testsrcdir/lib/$1" .
340 sed 10q "$1" # For debugging.
345 # Skip the test if the given shell fails to support common XSI constructs.
348 test $# -eq 1 || fatal_ "require_xsi needs exactly one argument"
349 echo "$me: trying some XSI constructs with $1"
350 $1 -c "$xsi_shell_code" || skip_ "$1 lacks XSI features"
352 # Shell code supposed to work only with XSI shells. Keep this in sync
353 # with libtool.m4:_LT_CHECK_SHELL_FEATURES.
356 test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
358 && eval '\''test $(( 1 + 1 )) -eq 2 \
359 && test "${#_lt_dummy}" -eq 5'\'
362 ## ----------------------------------------------------------- ##
363 ## Checks for required tools, and additional setups (if any) ##
364 ## required by them. ##
365 ## ----------------------------------------------------------- ##
367 # Print it here, so that the user will see it also if the test
368 # will be skipped due to some tool missing in $PATH itself.
371 # So that we can force the use of correct gcc, g++ etc., consistently
372 # with cross-compilation settings.
373 if cross_compiling; then
374 am__tool_prefix="$host_alias-"
379 # Look for (and maybe set up) required tools and/or system features; skip
380 # the current test if they are not found.
381 for tool in : $required
383 # Check that each required tool is present.
387 test "$CC" = false && skip_ "no C compiler available";;
389 test "$CXX" = false && skip_ "no C++ compiler available";;
391 test "$FC" = false && skip_ "no Fortran compiler available";;
393 test "$F77" = false && skip_ "no Fortran 77 compiler available";;
395 require_xsi "$SHELL";;
397 require_xsi "/bin/sh";;
399 if test x"$test_prefer_config_shell" = x"yes"; then
402 require_xsi "/bin/sh"
406 # Do not use --version, bzip2 still tries to compress stdin.
407 echo "$me: running bzip2 --help"
409 || skip_ "required program \`bzip2' not available"
414 echo "$me: running $CC -?"
415 $CC -? || skip_ "Microsoft C compiler \`$CC' not available"
418 # Sun cscope is interactive without redirection.
419 echo "$me: running cscope --version </dev/null"
420 cscope --version </dev/null \
421 || skip_ "required program \`cscope' not available"
424 # Exuberant Ctags will create a TAGS file even
425 # when asked for --help or --version. (Emacs's etags
426 # does not have such problem.) Use -o /dev/null
427 # to make sure we do not pollute the tests/ directory.
428 echo "$me: running etags --version -o /dev/null"
429 etags --version -o /dev/null \
430 || skip_ "required program \`etags' not available"
433 for make_ in "$MAKE" gmake gnumake :; do
434 MAKE=$make_ am__using_gmake=''
435 test "$MAKE" = : && break
436 echo "$me: determine whether $MAKE is GNU make"
439 test "$MAKE" = : && skip_ "this test requires GNU make"
444 # When gcc is required, export `CC=gcc' so that ./configure
445 # always use it. This is important only when the user
446 # has defined CC in his environment, otherwise ./configure will
447 # prefer gcc to other compilers.
448 CC=${am__tool_prefix}gcc
450 echo "$me: running $CC --version"
451 $CC --version || skip_ "GNU C compiler not available"
452 echo "$me: running $CC -v"
453 $CC -v || skip_ "botched installation for GNU C compiler"
456 GCJ=${am__tool_prefix}gcj
458 echo "$me: running $GCJ --version"
459 $GCJ --version || skip_ "GNU Java compiler not available"
460 echo "$me: running $GCJ -v"
461 $GCJ -v || skip_ "botched installation for GNU Java compiler"
464 CXX=${am__tool_prefix}g++
466 echo "$me: running $CXX --version"
467 $CXX --version || skip_ "GNU C++ compiler not available"
468 echo "$me: running $CXX -v"
469 $CXX -v || skip_ "botched installation for GNU C++ compiler"
472 FC=${am__tool_prefix}gfortran
474 echo "$me: running $FC --version"
475 $FC --version || skip_ "GNU Fortran compiler not available"
476 echo "$me: running $FC -v"
477 $FC -v || skip_ "botched installation for GNU Fortran compiler"
478 case " $required " in
480 *) F77=$FC; export F77;;
484 F77=${am__tool_prefix}g77
486 echo "$me: running $F77 --version"
487 $F77 --version || skip_ "GNU Fortran 77 compiler not available"
488 echo "$me: running $F77 -v"
489 $F77 -v || skip_ "botched installation for GNU Fortran 77 compiler"
490 case " $required " in
492 *) FC=$F77; export FC;;
498 # There is no way to ask *only* the compiler's version.
499 # This tool always wants to do something (by default
500 # it will try link *nothing* and complain it cannot find
501 # main(); funny). Use -help so it does not try linking anything.
502 echo "$me: running $CC -V -help"
503 $CC -V -help || skip_ "Intel C compiler \`$CC' not available"
506 # The Java compiler from JDK 1.5 (and presumably earlier versions)
507 # cannot handle the `-version' option by itself: it bails out
508 # telling that source files are missing. Adding also the `-help'
509 # option seems to solve the problem.
510 echo "$me: running javac -version -help"
511 javac -version -help || skip_ "Sun Java compiler not available"
514 echo "$me: running makedepend -f-"
516 || skip_ "required program \`makedepend' not available"
519 # Make sure we have makeinfo, and it understands `--html'.
520 echo "$me: running makeinfo --html --version"
521 makeinfo --html --version \
522 || skip_ "cannot find a makeinfo program that groks the" \
526 # Skip this test case if the user is root.
527 # We try to append to a read-only file to detect this.
528 priv_check_temp=priv-check.$$
529 touch $priv_check_temp || exit 99
530 chmod a-w $priv_check_temp || exit 99
531 (echo foo >> $priv_check_temp) >/dev/null 2>&1
533 rm -f $priv_check_temp
534 if test $overwrite_status -eq 0; then
535 skip_ "cannot drop file write permissions"
537 unset priv_check_temp overwrite_status
540 if test "$WANT_NO_THREADS" = "yes"; then
541 skip_ "Devel::Cover cannot cope with threads"
545 cross_compiling && skip_ "doesn't work in cross-compile mode"
548 # Python doesn't support --version, it has -V
549 echo "$me: running python -V"
550 python -V || skip_ "python interpreter not available"
553 # Skip this test case if read-only directories aren't supported
555 ro_dir_temp=ro_dir.$$
556 mkdir $ro_dir_temp || exit 99
557 chmod a-w $ro_dir_temp || exit 99
558 (: > $ro_dir_temp/probe) >/dev/null 2>/dev/null
561 if test $create_status -eq 0; then
562 skip_ "cannot drop directory write permissions"
564 unset ro_dir_temp create_status
567 # Try the variants that are tried in check.am.
569 for r2h in $RST2HTML rst2html rst2html.py; do
570 echo "$me: running $r2h --version"
571 $r2h --version && break 2
573 skip_ "no proper rst2html program found"
578 # DejaGnu's runtest program. We rely on being able to specify
579 # the program on the runtest command-line. This requires
580 # DejaGnu 1.4.3 or later.
581 echo "$me: running runtest SOMEPROGRAM=someprogram --version"
582 runtest SOMEPROGRAM=someprogram --version \
583 || skip_ "DejaGnu is not available"
586 # No all versions of Tex support `--version', so we use
588 if test -z "$TEX"; then
589 skip_ "TeX is required, but it wasn't found by configure"
593 # Texi2dvi supports `-o' since Texinfo 4.1.
594 echo "$me: running texi2dvi -o /dev/null --version"
595 texi2dvi -o /dev/null --version \
596 || skip_ "required program \`texi2dvi' not available"
599 # Since flex is required, we pick LEX for ./configure.
602 echo "$me: running flex --version"
603 flex --version || skip_ "required program \`flex' not available"
606 test "$LEX" = false && skip_ "no Lex program available"
607 if test -z "$LEX"; then
608 # The user hasn't explicitly specified any lex program in the
609 # environment, so we try to use flex, skipping the test if it's
613 echo "$me: running flex --version"
614 flex --version || skip_ "required program \`flex' not available"
618 test "$YACC" = false && skip_ "no Yacc program available"
619 if test -z "$YACC"; then
620 # The user hasn't explicitly specified any yacc program in the
621 # environment, so we try to use bison, skipping the test if it's
625 echo "$me: running bison --version"
626 bison --version || skip_ "required program \`bison' not available"
630 # Generic case: the tool must support --version.
631 echo "$me: running $tool --version"
632 # It is not likely but possible that $tool is a special builtin,
633 # in which case the shell is allowed to exit after an error.
634 # So, please leave the subshell here.
635 ($tool --version) || skip_ "required program \`$tool' not available"
640 # Using just `$testbuilddir' for the check here is ok, since the
641 # further temporary subdirectory where the test will be run is
642 # ensured not to contain any whitespace character.
643 case $testbuilddir in
645 case " $required " in
646 *' libtool '* | *' libtoolize '* )
647 skip_ "libtool has problems with spaces in builddir name";;
652 # This test is necessary, although Automake's configure script bails out
653 # when $srcdir contains spaces. This is because $testsrcdir is in not
654 # configure-time $srcdir, but is instead configure-time $abs_srcdir, and
655 # that is allowed to contain spaces.
658 case " $required " in
659 *' libtool '* | *' libtoolize '* | *' gettext '* )
660 skip_ "spaces in srcdir name: libtool/gettext tests won't work";;
665 # We might need extra macros, e.g., from Libtool or Gettext.
666 # Find them on the system.
667 # Use `-I $top_testsrcdir/m4' in addition to `--acdir=$top_testsrcdir/m4',
668 # because the other `-I' directories added for libtool and gettext might
669 # contain files from an old version of Automake that we don't want to use.
670 # Use `-Wno-syntax' because we do not want our test suite to fail because
671 # some third-party .m4 file is underquoted.
672 case " $required " in
673 *' libtool '* | *' libtoolize '* | *' gettext '* )
674 aclocaldir=$testprefix/share/aclocal
676 if test -f $aclocaldir/dirlist; then
678 <$aclocaldir/dirlist \
679 sed 's/#.*//;s/[ ][ ]*$//g' \
680 | while read dir; do test ! -d "$dir" || echo "-I $dir"; done`
685 for d in $extra_includes $aclocaldir ; do
686 test "x$d" != x-I || continue
687 if test -f "$d/libtool.m4"; then
690 if test -f "$d/gettext.m4"; then
694 case " $required " in
695 *' libtool '*|*' libtoolize '*)
696 if test $libtool_found != yes; then
697 # Write more diagnostic to the log file than to the console.
698 echo "$me: \`libtool.m4' wasn't found in directories" \
699 "$aclocaldir $extra_includes"
700 skip_ "libtool m4 macros won't be found by aclocal"
704 if test $gettext_found != yes; then
705 # Write more diagnostic to the log file than to the console.
706 echo "$me: \`gettext.m4' wasn't found in directories" \
707 "$aclocaldir $extra_includes"
708 skip_ "gettext m4 macros won't be found by aclocal"
712 ACLOCAL="$ACLOCAL -Wno-syntax -I $top_testsrcdir/m4 $extra_includes -I $aclocaldir"
713 unset libtool_found gettext_found
714 unset extra_includes aclocaldir
719 ## ---------------------------------------------------------------- ##
720 ## Create and set up of the temporary directory used by the test. ##
721 ## Set up of the exit trap for cleanup of said directory. ##
722 ## ---------------------------------------------------------------- ##
724 # This might be used in testcases checking distribution-related features.
725 # Test scripts are free to override this if they need to.
728 # The subdirectory where the current test script will run and write its
729 # temporary/data files. This will be created shortly, and will be removed
730 # by the cleanup trap below if the test passes. If the test doesn't pass,
731 # this directory will be kept, to facilitate debugging.
734 test ! -d $testSubDir || {
735 find $testSubDir -type d ! -perm -700 -exec chmod u+rwx {} ";"
742 if test "$sh_errexit_works" = yes; then
746 # This is to ensure that a test script does give a SKIP outcome just
747 # because a command in it happens to exit with status 77. This
748 # behaviour, while from time to time useful to developers, is not
749 # meant to be enabled by default, as it could cause spurious failures
750 # in the wild. Thus it will be enabled only when the variable
751 # "am_explicit_skips" is set to a "true" value.
752 case $am_explicit_skips in
754 if test $exit_status -eq 77 && test $am__test_skipped != yes; then
759 case $exit_status,$keep_testdirs in
761 find $testSubDir -type d ! -perm -700 -exec chmod u+rwx {} ";"
765 test "$signal" != 0 && echo "$me: caught signal $signal"
766 echo "$me: exit $exit_status"
769 for signal in 1 2 13 15; do
770 trap 'signal='$signal'; { Exit 99; }' $signal
775 # Copy in some files we need.
776 for file in install-sh missing depcomp; do
777 cp "$top_testsrcdir/lib/$file" . || Exit 99
780 # Build appropriate environment in test directory. Eg create
781 # configure.in, touch all necessary files, etc.
782 # Don't use AC_OUTPUT, but AC_CONFIG_FILES so that appending
783 # still produces a valid configure.ac. But then, tests running
784 # config.status really need to append AC_OUTPUT.
786 echo "AC_INIT([$me], [1.0])"
787 if test x"$parallel_tests" = x"yes"; then
788 echo "AM_INIT_AUTOMAKE([parallel-tests])"
790 echo "AM_INIT_AUTOMAKE"
792 echo "AC_CONFIG_FILES([Makefile])"
795 ## ---------------- ##
797 ## ---------------- ##