tests: don't skip if $(abs_builddir) or $(abs_srcdir) contain whitespace
[platform/upstream/automake.git] / t / ax / test-init.sh
1 # -*- shell-script -*-
2 #
3 # Copyright (C) 1996-2012 Free Software Foundation, Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 ########################################################
19 ###  IMPORTANT NOTE: keep this file 'set -e' clean.  ###
20 ########################################################
21
22 # Enable the errexit shell flag early.
23 set -e
24
25 # The name of the current test (without the '.sh' or '.tap' suffix).
26 # Test scripts can override it if they need to (but this should
27 # be done carefully).
28 if test -z "$me"; then
29   # Strip all directory components.
30   me=${argv0##*/}
31   # Strip test suffix.
32   case $me in
33     *.tap) me=${me%.tap};;
34      *.sh) me=${me%.sh} ;;
35   esac
36 fi
37
38
39 ## --------------------- ##
40 ##  Early sanity checks. ##
41 ## --------------------- ##
42
43 # Ensure $am_top_srcdir is set correctly.
44 test -f "$am_top_srcdir/defs-static.in" || {
45    echo "$me: $am_top_srcdir/defs-static.in not found," \
46         "check \$am_top_srcdir" >&2
47    exit 99
48 }
49
50 # Ensure $am_top_builddir is set correctly.
51 test -f "$am_top_builddir/defs-static" || {
52    echo "$me: $am_top_builddir/defs-static not found," \
53         "check \$am_top_builddir" >&2
54    exit 99
55 }
56
57
58 ## ------------------ ##
59 ##  Early variables.  ##
60 ## ------------------ ##
61
62 # A single whitespace character.
63 sp=' '
64 # A tabulation character.
65 tab='   '
66 # A newline character.
67 nl='
68 '
69 # A literal escape character.  Used by test checking colored output.
70 esc='\e'
71
72 # As autoconf-generated configure scripts do, ensure that IFS
73 # is defined initially, so that saving and restoring $IFS works.
74 IFS=$sp$tab$nl
75
76
77 ## ----------------------- ##
78 ##  Early debugging info.  ##
79 ## ----------------------- ##
80
81 echo "Running from installcheck: $am_running_installcheck"
82 echo "Using TAP: $am_using_tap"
83 echo "PATH = $PATH"
84
85
86 ## ---------------------- ##
87 ##  Environment cleanup.  ##
88 ## ---------------------- ##
89
90 # Temporarily disable this, since some shells (e.g., older version
91 # of Bash) can return a non-zero exit status upon the when a non-set
92 # variable is unset.
93 set +e
94
95 # Unset some make-related variables that may cause $MAKE to act like
96 # a recursively invoked sub-make.  Any $MAKE invocation in a test is
97 # conceptually an independent invocation, not part of the main
98 # 'automake' build.
99 unset MFLAGS MAKEFLAGS AM_MAKEFLAGS MAKELEVEL
100 unset __MKLVL__ MAKE_JOBS_FIFO                     # For BSD make.
101 unset DMAKE_CHILD DMAKE_DEF_PRINTED DMAKE_MAX_JOBS # For Solaris dmake.
102 # Unset verbosity flag.
103 unset V
104 # Also unset variables that will let "make -e install" divert
105 # files into unwanted directories.
106 unset DESTDIR
107 unset prefix exec_prefix bindir datarootdir datadir docdir dvidir
108 unset htmldir includedir infodir libdir libexecdir localedir mandir
109 unset oldincludedir pdfdir psdir sbindir sharedstatedir sysconfdir
110 # Unset variables that might change the "make distcheck" behaviour.
111 unset DISTCHECK_CONFIGURE_FLAGS AM_DISTCHECK_CONFIGURE_FLAGS
112 # Used by install rules for info files.
113 unset AM_UPDATE_INFO_DIR
114 # The tests call "make -e" but we do not want $srcdir from the environment
115 # to override the definition from the Makefile.
116 unset srcdir
117 # Also unset variables that control our test driver.  While not
118 # conceptually independent, they cause some changed semantics we
119 # need to control (and test for) in some of the tests to ensure
120 # backward-compatible behavior.
121 unset TESTS_ENVIRONMENT AM_TESTS_ENVIRONMENT
122 unset DISABLE_HARD_ERRORS
123 unset AM_COLOR_TESTS
124 unset TESTS
125 unset XFAIL_TESTS
126 unset TEST_LOGS
127 unset TEST_SUITE_LOG
128 unset RECHECK_LOGS
129 unset VERBOSE
130 for pfx in TEST_ SH_ TAP_ ''; do
131   unset ${pfx}LOG_COMPILER
132   unset ${pfx}LOG_COMPILE # Not a typo!
133   unset ${pfx}LOG_FLAGS
134   unset AM_${pfx}LOG_FLAGS
135   unset ${pfx}LOG_DRIVER
136   unset ${pfx}LOG_DRIVER_FLAGS
137   unset AM_${pfx}LOG_DRIVER_FLAGS
138 done
139 unset pfx
140
141 # Re-enable, it had been temporarily disabled above.
142 set -e
143
144 ## ---------------------------- ##
145 ##  Auxiliary shell functions.  ##
146 ## ---------------------------- ##
147
148 # Tell whether we should keep the test directories around, even in
149 # case of success.  By default, we don't.
150 am_keeping_testdirs ()
151 {
152   case $keep_testdirs in
153      ""|n|no|NO) return 1;;
154               *) return 0;;
155   esac
156 }
157
158 # This is used in '_am_exit' and in the exit trap.  See comments in
159 # the latter for more information.
160 am__test_skipped=no
161
162 # We use a trap below for cleanup.  This requires us to go through
163 # hoops to get the right exit status transported through the signal.
164 # Turn off errexit here so that we don't trip the bug with OSF1/Tru64
165 # sh inside this function (FIXME: is this still relevant now that we
166 # require a POSIX shell?).
167 _am_exit ()
168 {
169   set +e
170   # See comments in the exit trap for the reason we do this.
171   test 77 = $1 && am__test_skipped=yes
172   # Spurious escaping to ensure we do not call our 'exit' alias.
173   (\exit $1); \exit $1
174 }
175 alias exit=_am_exit
176
177 if test $am_using_tap = yes; then
178   am_funcs_file=tap-functions.sh
179 else
180   am_funcs_file=plain-functions.sh
181 fi
182
183 if test -f "$am_testauxdir/$am_funcs_file"; then
184   . "$am_testauxdir/$am_funcs_file" || {
185     echo "$me: error sourcing $am_testauxdir/$am_funcs_file" >&2
186     exit 99
187   }
188 else
189   echo "$me: $am_testauxdir/$am_funcs_file not found" >&2
190   exit 99
191 fi
192 unset am_funcs_file
193
194 # cross_compiling
195 # ---------------
196 # Tell whether we are cross-compiling.  This is especially useful to skip
197 # tests (or portions of them) that requires a native compiler.
198 cross_compiling ()
199 {
200   # Quoting from the autoconf manual:
201   #   ... [$host_alias and $build both] default to the result of running
202   #   config.guess, unless you specify either --build or --host.  In
203   #   this case, the default becomes the system type you specified.
204   #   If you specify both, *and they're different*, configure enters
205   #   cross compilation mode (so it doesn't run any tests that require
206   #   execution).
207   test x"$host_alias" != x && test x"$build_alias" != x"$host_alias"
208 }
209
210 # is_blocked_signal SIGNAL-NUMBER
211 # --------------------------------
212 # Return success if the given signal number is blocked in the shell,
213 # return a non-zero exit status and print a proper diagnostic otherwise.
214 is_blocked_signal ()
215 {
216   # Use perl, since trying to do this portably in the shell can be
217   # very tricky, if not downright impossible.  For reference, see:
218   # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
219   if $PERL -w -e '
220     use strict;
221     use warnings FATAL => "all";
222     use POSIX;
223     my %oldsigaction = ();
224     sigaction('"$1"', 0, \%oldsigaction);
225     exit ($oldsigaction{"HANDLER"} eq "IGNORE" ? 0 : 77);
226   '; then
227     return 0
228   elif test $? -eq 77; then
229     return 1
230   else
231     fatal_ "couldn't determine whether signal $1 is blocked"
232   fi
233 }
234
235 # AUTOMAKE_run [-e STATUS] [-d DESCRIPTION] [--] [AUTOMAKE-ARGS...]
236 # -----------------------------------------------------------------
237 # Run automake with AUTOMAKE-ARGS, and fail if it doesn't exit with
238 # STATUS.  Should be polymorphic for TAP and "plain" tests.  The
239 # DESCRIPTION, when provided, is used for console reporting, only if
240 # the TAP protocol is in use in the current test script.
241 AUTOMAKE_run ()
242 {
243   am__desc=
244   am__exp_rc=0
245   while test $# -gt 0; do
246     case $1 in
247       -d) am__desc=$2; shift;;
248       -e) am__exp_rc=$2; shift;;
249       --) shift; break;;
250        # Don't fail on unknown option: assume they (and the rest of the
251        # command line) are to be passed verbatim to automake (so stop our
252        # own option parsing).
253        *) break;;
254     esac
255     shift
256   done
257   am__got_rc=0
258   $AUTOMAKE ${1+"$@"} >stdout 2>stderr || am__got_rc=$?
259   cat stderr >&2
260   cat stdout
261   if test $am_using_tap != yes; then
262     test $am__got_rc -eq $am__exp_rc || exit 1
263     return
264   fi
265   if test -z "$am__desc"; then
266     if test $am__got_rc -eq $am__exp_rc; then
267       am__desc="automake exited $am__got_rc"
268     else
269       am__desc="automake exited $am__got_rc, expecting $am__exp_rc"
270     fi
271   fi
272   command_ok_ "$am__desc" test $am__got_rc -eq $am__exp_rc
273 }
274
275 # AUTOMAKE_fails [-d DESCRIPTION] [OPTIONS...]
276 # --------------------------------------------
277 # Run automake with OPTIONS, and fail if doesn't exit with status 1.
278 # Should be polymorphic for TAP and "plain" tests.  The DESCRIPTION,
279 # when provided, is used for console reporting, only if the TAP
280 # protocol is in use in the current test script.
281 AUTOMAKE_fails ()
282 {
283   AUTOMAKE_run -e 1 ${1+"$@"}
284 }
285
286 # extract_configure_help { --OPTION | VARIABLE-NAME } [FILES]
287 # -----------------------------------------------------------
288 # Use this to extract from the output of "./configure --help" (or similar)
289 # the description or help message associated to the given --OPTION or
290 # VARIABLE-NAME.
291 extract_configure_help ()
292 {
293   am__opt_re='' am__var_re=''
294   case $1 in
295     --*'=')   am__opt_re="^  $1";;
296     --*'[=]') am__opt_re='^  '$(printf '%s\n' "$1" | sed 's/...$//')'\[=';;
297     --*)      am__opt_re="^  $1( .*|$)";;
298       *)      am__var_re="^  $1( .*|$)";;
299   esac
300   shift
301   if test x"$am__opt_re" != x; then
302     LC_ALL=C awk '
303       /'"$am__opt_re"'/        { print; do_print = 1; next; }
304       /^$/                     { do_print = 0; next }
305       /^  --/                  { do_print = 0; next }
306       (do_print == 1)          { print }
307     ' ${1+"$@"}
308   else
309     LC_ALL=C awk '
310       /'"$am__var_re"'/        { print; do_print = 1; next; }
311       /^$/                     { do_print = 0; next }
312       /^  [A-Z][A-Z0-9_]* /    { do_print = 0; next }
313       /^  [A-Z][A-Z0-9_]*$/    { do_print = 0; next }
314       (do_print == 1)          { print }
315     ' ${1+"$@"}
316   fi
317 }
318
319 # grep_configure_help { --OPTION | VARIABLE-NAME } REGEXP
320 # -------------------------------------------------------
321 # Grep the section of "./configure --help" output associated with either
322 # --OPTION or VARIABLE-NAME for the given *extended* regular expression.
323 grep_configure_help ()
324 {
325   ./configure --help > am--all-help \
326     || { cat am--all-help; exit 1; }
327   cat am--all-help
328   extract_configure_help "$1" am--all-help > am--our-help \
329     || { cat am--our-help; exit 1; }
330   cat am--our-help
331   $EGREP "$2" am--our-help || exit 1
332 }
333
334 # using_gmake
335 # -----------
336 # Return success if $MAKE is GNU make, return failure otherwise.
337 # Caches the result for speed reasons.
338 using_gmake ()
339 {
340   case $am__using_gmake in
341     yes)
342       return 0;;
343     no)
344       return 1;;
345     '')
346       # Use --version AND -v, because SGI Make doesn't fail on --version.
347       # Also grep for GNU because newer versions of FreeBSD make do
348       # not complain about --version (they seem to silently ignore it).
349       if $MAKE --version -v | grep GNU; then
350         am__using_gmake=yes
351         return 0
352       else
353         am__using_gmake=no
354         return 1
355       fi;;
356     *)
357       fatal_ "invalid value for \$am__using_gmake: '$am__using_gmake'";;
358   esac
359 }
360 am__using_gmake="" # Avoid interferences from the environment.
361
362 # make_can_chain_suffix_rules
363 # ---------------------------
364 # Return 0 if $MAKE is a make implementation that can chain suffix rules
365 # automatically, return 1 otherwise.  Caches the result for speed reasons.
366 make_can_chain_suffix_rules ()
367 {
368   if test -z "$am__can_chain_suffix_rules"; then
369     if using_gmake; then
370       am__can_chain_suffix_rules=yes
371       return 0
372     else
373       mkdir am__chain.dir$$
374       cd am__chain.dir$$
375       unindent > Makefile << 'END'
376         .SUFFIXES: .u .v .w
377         .u.v: ; cp $< $@
378         .v.w: ; cp $< $@
379 END
380       echo make can chain suffix rules > foo.u
381       if $MAKE foo.w && diff foo.u foo.w; then
382         am__can_chain_suffix_rules=yes
383       else
384         am__can_chain_suffix_rules=no
385       fi
386       cd ..
387       rm -rf am__chain.dir$$
388     fi
389   fi
390   case $am__can_chain_suffix_rules in
391     yes) return 0;;
392      no) return 1;;
393       *) fatal_ "make_can_chain_suffix_rules: internal error";;
394   esac
395 }
396 am__can_chain_suffix_rules="" # Avoid interferences from the environment.
397
398 # useless_vpath_rebuild
399 # ---------------------
400 # Tell whether $MAKE suffers of the bug triggering automake bug#7884.
401 # For example, this happens with FreeBSD make, since in a VPATH build
402 # it tends to rebuilt files for which there is an explicit or even just
403 # a suffix rule, even if said files are already available in the VPATH
404 # directory.
405 useless_vpath_rebuild ()
406 {
407   if test -z "$am__useless_vpath_rebuild"; then
408     if using_gmake; then
409       am__useless_vpath_rebuild=no
410       return 1
411     fi
412     mkdir am__vpath.dir$$
413     cd am__vpath.dir$$
414     touch foo.a foo.b bar baz
415     mkdir build
416     cd build
417     unindent > Makefile << 'END'
418         .SUFFIXES: .a .b
419         VPATH = ..
420         all: foo.b baz
421         .PHONY: all
422         .a.b: ; cp $< $@
423         baz: bar ; cp ../baz bar
424 END
425     if $MAKE all && test ! -f foo.b && test ! -f bar; then
426       am__useless_vpath_rebuild=no
427     else
428       am__useless_vpath_rebuild=yes
429     fi
430     cd ../..
431     rm -rf am__vpath.dir$$
432   fi
433   case $am__useless_vpath_rebuild in
434     yes) return 0;;
435      no) return 1;;
436      "") ;;
437       *) fatal_ "no_useless_builddir_remake: internal error";;
438   esac
439 }
440 am__useless_vpath_rebuild=""
441
442 yl_distcheck () { useless_vpath_rebuild || $MAKE distcheck ${1+"$@"}; }
443
444 # seq_ - print a sequence of numbers
445 # ----------------------------------
446 # This function simulates GNU seq(1) portably.  Valid usages:
447 #  - seq LAST
448 #  - seq FIRST LAST
449 #  - seq FIRST INCREMENT LAST
450 seq_ ()
451 {
452   case $# in
453     0) fatal_ "seq_: missing argument";;
454     1) seq_first=1  seq_incr=1  seq_last=$1;;
455     2) seq_first=$1 seq_incr=1  seq_last=$2;;
456     3) seq_first=$1 seq_incr=$2 seq_last=$3;;
457     *) fatal_ "seq_: too many arguments";;
458   esac
459   i=$seq_first
460   while test $i -le $seq_last; do
461     echo $i
462     i=$(($i + $seq_incr))
463   done
464 }
465
466 # rm_rf_ [FILES OR DIRECTORIES ...]
467 # ---------------------------------
468 # Recursively remove the given files or directory, also handling the case
469 # of non-writable subdirectories.
470 rm_rf_ ()
471 {
472   test $# -gt 0 || return 0
473   # Ignore failures in find, we are only interested in failures of the
474   # final rm.
475   find "$@" -type d ! -perm -700 -exec chmod u+rwx {} \; || :
476   rm -rf "$@"
477 }
478
479 # count_test_results total=N pass=N fail=N xpass=N xfail=N skip=N error=N
480 # -----------------------------------------------------------------------
481 # Check that a testsuite run driven by the parallel-tests harness has
482 # had the specified numbers of test results (specified by kind).
483 # This function assumes that the output of "make check" or "make recheck"
484 # has been saved in the 'stdout' file in the current directory, and its
485 # log in the 'test-suite.log' file.
486 count_test_results ()
487 {
488   # Use a subshell so that we won't pollute the script namespace.
489   (
490     # TODO: Do proper checks on the arguments?
491     total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
492     eval "$@"
493     # For debugging.
494     $EGREP -i '(total|x?pass|x?fail|skip|error)' stdout || :
495     rc=0
496     # Avoid spurious failures with shells with "overly sensible"
497     # errexit shell flag, such as e.g., Solaris /bin/sh.
498     set +e
499     test $(grep -c '^PASS:'  stdout) -eq $pass  || rc=1
500     test $(grep -c '^XFAIL:' stdout) -eq $xfail || rc=1
501     test $(grep -c '^SKIP:'  stdout) -eq $skip  || rc=1
502     test $(grep -c '^FAIL:'  stdout) -eq $fail  || rc=1
503     test $(grep -c '^XPASS:' stdout) -eq $xpass || rc=1
504     test $(grep -c '^ERROR:' stdout) -eq $error || rc=1
505     grep "^# TOTAL:  *$total$" stdout || rc=1
506     grep "^# PASS:  *$pass$"   stdout || rc=1
507     grep "^# XFAIL:  *$xfail$" stdout || rc=1
508     grep "^# SKIP:  *$skip$"   stdout || rc=1
509     grep "^# FAIL:  *$fail$"   stdout || rc=1
510     grep "^# XPASS:  *$xpass$" stdout || rc=1
511     grep "^# ERROR:  *$error$" stdout || rc=1
512     test $rc -eq 0
513   )
514 }
515
516 commented_sed_unindent_prog='
517   /^$/b                    # Nothing to do for empty lines.
518   x                        # Get x<indent> into pattern space.
519   /^$/{                    # No prior x<indent>, go prepare it.
520     g                      # Copy this 1st non-blank line into pattern space.
521     s/^\(['"$tab"' ]*\).*/x\1/   # Prepare x<indent> in pattern space.
522   }                        # Now: x<indent> in pattern and <line> in hold.
523   G                        # Build x<indent>\n<line> in pattern space, and
524   h                        # duplicate it into hold space.
525   s/\n.*$//                # Restore x<indent> in pattern space, and
526   x                        # exchange with the above duplicate in hold space.
527   s/^x\(.*\)\n\1//         # Remove leading <indent> from <line>.
528   s/^x.*\n//               # Restore <line> when there is no leading <indent>.
529 '
530
531 # unindent [input files...]
532 # -------------------------
533 # Remove the "proper" amount of leading whitespace from the given files,
534 # and output the result on stdout.  That amount is determined by looking
535 # at the leading whitespace of the first non-blank line in the input
536 # files.  If no input file is specified, standard input is implied.
537 unindent ()
538 {
539   if test x"$sed_unindent_prog" = x; then
540     sed_unindent_prog=$(printf '%s\n' "$commented_sed_unindent_prog" \
541                           | sed -e "s/  *# .*//")
542   fi
543   sed "$sed_unindent_prog" ${1+"$@"}
544 }
545 sed_unindent_prog="" # Avoid interferences from the environment.
546
547 # get_shell_script SCRIPT-NAME
548 # -----------------------------
549 # Fetch an Automake-provided shell script from the 'lib/' directory into
550 # the current directory, and, if the '$am_test_prefer_config_shell'
551 # variable is set to "yes", modify its shebang line to use $SHELL instead
552 # of /bin/sh.
553 get_shell_script ()
554 {
555   test ! -f "$1" || rm -f "$1" || return 99
556   if test x"$am_test_prefer_config_shell" = x"yes"; then
557     sed "1s|#!.*|#! $SHELL|" "$am_scriptdir/$1" > "$1" \
558      && chmod a+x "$1" \
559      || return 99
560   else
561     cp -f "$am_scriptdir/$1" . || return 99
562   fi
563   sed 10q "$1" # For debugging.
564 }
565
566 # require_xsi SHELL
567 # -----------------
568 # Skip the test if the given shell fails to support common XSI constructs.
569 require_xsi ()
570 {
571   test $# -eq 1 || fatal_ "require_xsi needs exactly one argument"
572   echo "$me: trying some XSI constructs with $1"
573   $1 -c "$xsi_shell_code" || skip_all_ "$1 lacks XSI features"
574 }
575 # Shell code supposed to work only with XSI shells.  Keep this in sync
576 # with libtool.m4:_LT_CHECK_SHELL_FEATURES.
577 xsi_shell_code='
578   _lt_dummy="a/b/c"
579   test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
580       = c,a/b,b/c, \
581     && eval '\''test $(( 1 + 1 )) -eq 2 \
582     && test "${#_lt_dummy}" -eq 5'\'
583
584 # fetch_tap_driver
585 # ----------------
586 # Fetch the Automake-provided TAP driver from the 'lib/' directory into
587 # the current directory, and edit its shebang line so that it will be
588 # run with the perl interpreter determined at configure time.
589 fetch_tap_driver ()
590 {
591   # TODO: we should devise a way to make the shell TAP driver tested also
592   # TODO: with /bin/sh, for better coverage.
593   case $am_tap_implementation in
594     # Extra quoting required to avoid maintainer-check spurious failures.
595    'perl')
596       $PERL -MTAP::Parser -e 1 \
597         || skip_all_ "cannot import TAP::Parser perl module"
598       sed "1s|#!.*|#! $PERL -w|" "$am_scriptdir"/tap-driver.pl >tap-driver
599       ;;
600     shell)
601       AM_TAP_AWK=$AWK; export AM_TAP_AWK
602       sed "1s|#!.*|#! $SHELL|" "$am_scriptdir"/tap-driver.sh >tap-driver
603       ;;
604     *)
605       fatal_ "invalid \$am_tap_implementation '$am_tap_implementation'" ;;
606   esac \
607     && chmod a+x tap-driver \
608     || framework_failure_ "couldn't fetch $am_tap_implementation TAP driver"
609   sed 10q tap-driver # For debugging.
610 }
611 # The shell/awk implementation of the TAP driver is still mostly dummy, so
612 # use the perl implementation by default for the moment.
613 am_tap_implementation=${am_tap_implementation-shell}
614
615 # Usage: require_compiler_ {cc|c++|fortran|fortran77}
616 require_compiler_ ()
617 {
618   case $# in
619     0) fatal_ "require_compiler_: missing argument";;
620     1) ;;
621     *) fatal_ "require_compiler_: too many arguments";;
622   esac
623   case $1 in
624     cc)
625       am__comp_lang="C"
626       am__comp_var=CC
627       am__comp_flag_vars='CFLAGS CPPFLAGS'
628       ;;
629     c++)
630       am__comp_lang="C++"
631       am__comp_var=CXX
632       am__comp_flag_vars='CXXFLAGS CPPFLAGS'
633       ;;
634     fortran)
635       am__comp_lang="Fortran"
636       am__comp_var=FC
637       am__comp_flag_vars='FCFLAGS'
638       ;;
639     fortran77)
640       am__comp_lang="Fortran 77"
641       am__comp_var=F77
642       am__comp_flag_vars='FFLAGS'
643       ;;
644   esac
645   shift
646   eval "am__comp_prog=\${$am__comp_var}" \
647     || fatal_ "expanding \${$am__comp_var} in require_compiler_"
648   case $am__comp_prog in
649     "")
650       fatal_ "botched configuration: \$$am__comp_var is empty";;
651     false)
652       skip_all_ "no $am__comp_lang compiler available";;
653     autodetect|autodetected)
654       # Let the ./configure commands in the test script try to determine
655       # these automatically.
656       unset $am__comp_var $am__comp_flag_vars;;
657     *)
658       # Pre-set these for the ./configure commands in the test script.
659       export $am__comp_var $am__comp_flag_vars;;
660   esac
661   # Delete private variables.
662   unset am__comp_lang am__comp_prog am__comp_var am__comp_flag_vars
663 }
664
665 ## ----------------------------------------------------------- ##
666 ##  Checks for required tools, and additional setups (if any)  ##
667 ##  required by them.                                          ##
668 ## ----------------------------------------------------------- ##
669
670 # Performance tests must be enabled explicitly.
671 case $argv0 in
672   */perf/*)
673     case $AM_TESTSUITE_PERF in
674       [yY]|[yY]es|1) ;;
675       *) skip_ "performance tests not explicitly enabled" ;;
676     esac
677     ;;
678 esac
679
680 # Look for (and maybe set up) required tools and/or system features; skip
681 # the current test if they are not found.
682 for tool in : $required
683 do
684   # Check that each required tool is present.
685   case $tool in
686     :) ;;
687     cc|c++|fortran|fortran77)
688       require_compiler_ $tool;;
689     xsi-lib-shell)
690       if test x"$am_test_prefer_config_shell" = x"yes"; then
691         require_xsi "$SHELL"
692       else
693         require_xsi "/bin/sh"
694       fi
695       ;;
696     bzip2)
697       # Do not use --version, older versions bzip2 still tries to compress
698       # stdin.
699       echo "$me: running bzip2 --help"
700       bzip2 --help \
701         || skip_all_ "required program 'bzip2' not available"
702       ;;
703     cl)
704       CC=cl
705       # Don't export CFLAGS, as that could have been initialized to only
706       # work with the C compiler detected at configure time.  If the user
707       # wants CFLAGS to also influence 'cl', he can still export CFLAGS
708       # in the environment "by hand" before calling the testsuite.
709       export CC CPPFLAGS
710       echo "$me: running $CC -?"
711       $CC -? || skip_all_ "Microsoft C compiler '$CC' not available"
712       ;;
713     etags)
714       # Exuberant Ctags will create a TAGS file even
715       # when asked for --help or --version.  (Emacs's etags
716       # does not have such problem.)  Use -o /dev/null
717       # to make sure we do not pollute the build directory.
718       echo "$me: running etags --version -o /dev/null"
719       etags --version -o /dev/null \
720         || skip_all_ "required program 'etags' not available"
721       ;;
722     GNUmake)
723       for make_ in "$MAKE" gmake gnumake :; do
724         MAKE=$make_ am__using_gmake=''
725         test "$MAKE" =  : && break
726         echo "$me: determine whether $MAKE is GNU make"
727         using_gmake && break
728         : For shells with busted 'set -e'.
729       done
730       test "$MAKE" = : && skip_all_ "this test requires GNU make"
731       export MAKE
732       unset make_
733       ;;
734     gcj)
735       GCJ=$GNU_GCJ GCJFLAGS=$GNU_GCJFLAGS; export GCJ GCJFLAGS
736       test "$GCJ" = false && skip_all_ "GNU Java compiler unavailable"
737       : For shells with busted 'set -e'.
738       ;;
739     gcc)
740       CC=$GNU_CC CFLAGS=$GNU_CFLAGS; export CC CFLAGS CPPFLAGS
741       test "$CC" = false && skip_all_ "GNU C compiler unavailable"
742       : For shells with busted 'set -e'.
743       ;;
744     g++)
745       CXX=$GNU_CXX CXXFLAGS=$GNU_CXXFLAGS; export CXX CXXFLAGS CPPFLAGS
746       test "$CXX" = false && skip_all_ "GNU C++ compiler unavailable"
747       : For shells with busted 'set -e'.
748       ;;
749     gfortran)
750       FC=$GNU_FC FCFLAGS=$GNU_FCFLAGS; export FC FCFLAGS
751       test "$FC" = false && skip_all_ "GNU Fortran compiler unavailable"
752       case " $required " in
753         *\ g77\ *) ;;
754         *) F77=$FC FFLAGS=$FCFLAGS; export F77 FFLAGS;;
755       esac
756       ;;
757     g77)
758       F77=$GNU_F77 FFLAGS=$GNU_FFLAGS; export F77 FFLAGS
759       test "$F77" = false && skip_all_ "GNU Fortran 77 compiler unavailable"
760       case " $required " in
761         *\ gfortran\ *) ;;
762         *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;;
763       esac
764       ;;
765     grep-nonprint)
766       # Check that grep can parse nonprinting characters correctly.
767       # BSD 'grep' works from a pipe, but not a seekable file.
768       # GNU or BSD 'grep -a' works on files, but is not portable.
769       case $(echo "$esc" | grep .)$(echo "$esc" | grep "$esc") in
770         "$esc$esc") ;;
771         *) skip_ "grep can't handle nonprinting characters correctly";;
772       esac
773       ;;
774     javac)
775       # The Java compiler from JDK 1.5 (and presumably earlier versions)
776       # cannot handle the '-version' option by itself: it bails out
777       # telling that source files are missing.  Adding also the '-help'
778       # option seems to solve the problem.
779       echo "$me: running javac -version -help"
780       javac -version -help || skip_all_ "Sun Java compiler not available"
781       ;;
782     java)
783       # See the comments above about 'javac' for why we use also '-help'.
784       echo "$me: running java -version -help"
785       java -version -help || skip_all_ "Sun Java interpreter not found"
786       ;;
787     lib)
788       AR=lib
789       export AR
790       # Attempting to create an empty archive will actually not
791       # create the archive, but lib will output its version.
792       echo "$me: running $AR -out:defstest.lib"
793       $AR -out:defstest.lib \
794         || skip_all_ "Microsoft 'lib' utility not available"
795       ;;
796     makedepend)
797       echo "$me: running makedepend -f-"
798       makedepend -f- \
799         || skip_all_ "required program 'makedepend' not available"
800       ;;
801     makeinfo-html)
802       # Make sure we have makeinfo, and it understands '--html'.
803       echo "$me: running makeinfo --html --version"
804       makeinfo --html --version \
805         || skip_all_ "cannot find a makeinfo program that groks" \
806                      "the '--html' option"
807       ;;
808     mingw)
809       uname_s=$(uname -s || echo UNKNOWN)
810       echo "$me: system name: $uname_s"
811       case $uname_s in
812         MINGW*) ;;
813         *) skip_all_ "this test requires MSYS in MinGW mode" ;;
814       esac
815       unset uname_s
816       ;;
817     non-root)
818       # Skip this test case if the user is root.
819       # We try to append to a read-only file to detect this.
820       priv_check_temp=priv-check.$$
821       touch $priv_check_temp && chmod a-w $priv_check_temp \
822         || framework_failure_ "creating unwritable file $priv_check_temp"
823       # Not a useless use of subshell: lesser shells like Solaris /bin/sh
824       # can exit if a builtin fails.
825       overwrite_status=0
826       (echo foo >> $priv_check_temp) || overwrite_status=$?
827       rm -f $priv_check_temp
828       if test $overwrite_status -eq 0; then
829         skip_all_ "cannot drop file write permissions"
830       fi
831       unset priv_check_temp overwrite_status
832       ;;
833     # Extra quoting required to avoid maintainer-check spurious failures.
834     'perl-threads')
835       if test "$WANT_NO_THREADS" = "yes"; then
836         skip_all_ "Devel::Cover cannot cope with threads"
837       fi
838       ;;
839     native)
840       # Don't use "&&" here, to avoid a bug of 'set -e' present in
841       # some (even relatively recent) versions of the BSD shell.
842       # We add the dummy "else" branch for extra safety.
843       ! cross_compiling || skip_all_ "doesn't work in cross-compile mode"
844       ;;
845     python)
846       # Python doesn't support --version, it has -V
847       echo "$me: running python -V"
848       python -V || skip_all_ "python interpreter not available"
849       ;;
850     ro-dir)
851       # Skip this test case if read-only directories aren't supported
852       # (e.g., under DOS.)
853       ro_dir_temp=ro_dir.$$
854       mkdir $ro_dir_temp && chmod a-w $ro_dir_temp \
855         || framework_failure_ "creating unwritable directory $ro_dir_temp"
856       # Not a useless use of subshell: lesser shells like Solaris /bin/sh
857       # can exit if a builtin fails.
858       create_status=0
859       (: > $ro_dir_temp/probe) || create_status=$?
860       rm -rf $ro_dir_temp
861       if test $create_status -eq 0; then
862         skip_all_ "cannot drop directory write permissions"
863       fi
864       unset ro_dir_temp create_status
865       ;;
866     runtest)
867       # DejaGnu's runtest program. We rely on being able to specify
868       # the program on the runtest command-line. This requires
869       # DejaGnu 1.4.3 or later.
870       echo "$me: running runtest SOMEPROGRAM=someprogram --version"
871       runtest SOMEPROGRAM=someprogram --version \
872         || skip_all_ "DejaGnu is not available"
873       ;;
874     tex)
875       # No all versions of Tex support '--version', so we use
876       # a configure check.
877       if test -z "$TEX"; then
878         skip_all_ "TeX is required, but it wasn't found by configure"
879       fi
880       ;;
881     texi2dvi-o)
882       # Texi2dvi supports '-o' since Texinfo 4.1.
883       echo "$me: running texi2dvi -o /dev/null --version"
884       texi2dvi -o /dev/null --version \
885         || skip_all_ "required program 'texi2dvi' not available"
886       ;;
887     lex)
888       test x"$LEX" = x"false" && skip_all_ "lex not found or disabled"
889       export LEX
890       ;;
891     yacc)
892       test x"$YACC" = x"false" && skip_all_ "yacc not found or disabled"
893       export YACC
894       ;;
895     flex)
896       LEX=flex; export LEX
897       echo "$me: running flex --version"
898       flex --version || skip_all_ "required program 'flex' not available"
899       ;;
900     bison)
901       YACC='bison -y'; export YACC
902       echo "$me: running bison --version"
903       bison --version || skip_all_ "required program 'bison' not available"
904       ;;
905     *)
906       # Generic case: the tool must support --version.
907       echo "$me: running $tool --version"
908       # It is not likely but possible that $tool is a special builtin,
909       # in which case the shell is allowed to exit after an error.  So
910       # we need the subshell here.  Also, some tools, like Sun cscope,
911       # can be interactive without redirection.
912       ($tool --version) </dev/null \
913         || skip_all_ "required program '$tool' not available"
914       ;;
915   esac
916 done
917
918 # We might need extra macros, e.g., from Libtool or Gettext.
919 case " $required " in *\ libtool*) . ./t/libtool-macros.dir/get.sh;; esac
920 case " $required " in *\ gettext*) . ./t/gettext-macros.dir/get.sh;; esac
921
922
923 ## ---------------------------------------------------------------- ##
924 ##  Create and set up of the temporary directory used by the test.  ##
925 ##  Set up of the exit trap for cleanup of said directory.          ##
926 ## ---------------------------------------------------------------- ##
927
928 # This might be used in testcases checking distribution-related features.
929 # Test scripts are free to override this if they need to.
930 distdir=$me-1.0
931
932 # Set up the exit trap.
933 trap 'exit_status=$?
934   set +e
935   cd "$am_top_builddir"
936   if test $am_using_tap = yes; then
937     if test "$planned_" = later && test $exit_status -eq 0; then
938       plan_ "now"
939     fi
940     test $exit_status -eq 0 && test $tap_pass_count_ -eq $tap_count_ \
941       || keep_testdirs=yes
942   else
943     # This is to ensure that a test script does give a SKIP outcome just
944     # because a command in it happens to exit with status 77.  This
945     # behaviour, while from time to time useful to developers, is not
946     # meant to be enabled by default, as it could cause spurious failures
947     # in the wild.  Thus it will be enabled only when the variable
948     # "am_explicit_skips" is set to a "true" value.
949     case $am_explicit_skips in
950       [yY]|[yY]es|1)
951         if test $exit_status -eq 77 && test $am__test_skipped != yes; then
952           echo "$me: implicit skip turned into failure"
953           exit_status=78
954         fi;;
955     esac
956     test $exit_status -eq 0 || keep_testdirs=yes
957   fi
958   am_keeping_testdirs || rm_rf_ $testSubDir
959   set +x
960   echo "$me: exit $exit_status"
961   # Spurious escaping to ensure we do not call our "exit" alias.
962   \exit $exit_status
963 ' 0
964 trap "fatal_ 'caught signal SIGHUP'" 1
965 trap "fatal_ 'caught signal SIGINT'" 2
966 trap "fatal_ 'caught signal SIGTERM'" 15
967 # Various shells seems to just ignore SIGQUIT under some circumstances,
968 # even if the signal is not blocked; however, if the signal it trapped,
969 # the trap gets correctly executed.  So we also trap SIGQUIT.
970 # Here is a list of some shells that have been verified to exhibit the
971 # problematic behavior with SIGQUIT:
972 #  - zsh 4.3.12 on Debian GNU/Linux
973 #  - /bin/ksh and /usr/xpg4/bin/sh on Solaris 10
974 #  - Bash 3.2.51 on Solaris 10 and bash 4.1.5 on Debian GNU/Linux
975 #  - AT&T ksh on Debian Gnu/Linux (deb package ksh, version 93u-1)
976 # OTOH, at least these shells that do *not* exhibit that behaviour:
977 #  - modern version of the Almquist Shell (at least 0.5.5.1), on
978 #    both Solaris and GNU/Linux
979 #  - Solaris 10 /bin/sh
980 #  - public domain Korn Shell, version 5.2.14, on Debian GNU/Linux
981 trap "fatal_ 'caught signal SIGQUIT'" 3
982 # Ignore further SIGPIPE in the trap code.  This is required to avoid
983 # a very weird issue with some shells, at least when the execution of
984 # the automake testsuite is driven by the 'prove' utility: if prove
985 # (or the make process that has spawned it) gets interrupted with
986 # Ctrl-C, the shell might go in a loop, continually getting a SIGPIPE,
987 # sometimes finally dumping core, other times hanging indefinitely.
988 # See also Test::Harness bug [rt.cpan.org #70855], archived at
989 # <https://rt.cpan.org/Ticket/Display.html?id=70855>
990 trap "trap '' 13; fatal_ 'caught signal SIGPIPE'" 13
991
992 # Create and populate the temporary directory, if and as required.
993 if test x"$am_create_testdir" = x"no"; then
994   testSubDir=
995 else
996   # The subdirectory where the current test script will run and write its
997   # temporary/data files.  This will be created shortly, and will be removed
998   # by the cleanup trap below if the test passes.  If the test doesn't pass,
999   # this directory will be kept, to facilitate debugging.
1000   testSubDir=t/$me.dir
1001   test ! -d $testSubDir || rm_rf_ $testSubDir \
1002     || framework_failure_ "removing old test subdirectory"
1003   test -d t || mkdir t
1004   mkdir $testSubDir \
1005     || framework_failure_ "creating test subdirectory"
1006   # The trailing './'ris to avoid CDPATH issues.
1007   cd ./$testSubDir \
1008     || framework_failure_ "cannot chdir into test subdirectory"
1009   if test x"$am_create_testdir" != x"empty"; then
1010     cp "$am_scriptdir"/install-sh "$am_scriptdir"/missing \
1011        "$am_scriptdir"/depcomp . \
1012       || framework_failure_ "fetching common files from $am_scriptdir"
1013     # Build appropriate environment in test directory.  E.g., create
1014     # configure.ac, touch all necessary files, etc.  Don't use AC_OUTPUT,
1015     # but AC_CONFIG_FILES so that appending still produces a valid
1016     # configure.ac.  But then, tests running config.status really need
1017     # to append AC_OUTPUT.
1018     {
1019       echo "AC_INIT([$me], [1.0])"
1020       if test x"$am_serial_tests" = x"yes"; then
1021         echo "AM_INIT_AUTOMAKE"
1022       else
1023         echo "AM_INIT_AUTOMAKE([parallel-tests])"
1024       fi
1025       echo "AC_CONFIG_FILES([Makefile])"
1026     } >configure.ac || framework_failure_ "creating configure.ac skeleton"
1027   fi
1028 fi
1029
1030
1031 ## ---------------- ##
1032 ##  Ready to go...  ##
1033 ## ---------------- ##
1034
1035 set -x
1036 pwd