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