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