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