tests: use more POSIX shell features our test scripts
[platform/upstream/automake.git] / defs
diff --git a/defs b/defs
index 742c4d4..77d616e 100644 (file)
--- a/defs
+++ b/defs
@@ -20,7 +20,7 @@
 ########################################################
 
 # NOTE: This file should execute correctly with any system's /bin/sh
-# shell, and not only with configure-time detected $CONFIG_SHELL,
+# shell, and not only with configure-time detected $AM_TEST_RUNNER_SHELL,
 # *until differently and explicitly specified*.
 
 ## -------------------------------------------------------- ##
@@ -105,16 +105,16 @@ case ${AM_TESTS_REEXEC-yes} in
       *x*) opts=-x;;
       *) opts=;;
     esac
-    echo $me: exec $SHELL $opts "$0" "$*"
-    exec $SHELL $opts "$0" ${1+"$@"} || {
-      echo "$me: failed to re-execute with $SHELL" >&2
+    echo $me: exec $AM_TEST_RUNNER_SHELL $opts "$0" "$*"
+    exec $AM_TEST_RUNNER_SHELL $opts "$0" ${1+"$@"} || {
+      echo "$me: failed to re-execute with $AM_TEST_RUNNER_SHELL" >&2
       exit 99
     }
     ;;
 esac
 
 # NOTE: From this point on, we can assume this file is being executed
-# by the configure-time detected $CONFIG_SHELL.
+# by the configure-time detected $AM_TEST_RUNNER_SHELL.
 
 
 ## ----------------------- ##
@@ -170,7 +170,7 @@ unset TEST_LOGS
 unset TEST_SUITE_LOG
 unset RECHECK_LOGS
 unset VERBOSE
-for pfx in TEST_ TAP_ ''; do
+for pfx in TEST_ SH_ TAP_ ''; do
   unset ${pfx}LOG_COMPILER
   unset ${pfx}LOG_COMPILE # Not a typo!
   unset ${pfx}LOG_FLAGS
@@ -254,7 +254,7 @@ cross_compiling ()
 # Resolve ties in favor of FILE.
 is_newest ()
 {
-  is_newest_files=`find "$@" -prune -newer "$1"`
+  is_newest_files=$(find "$@" -prune -newer "$1")
   test -z "$is_newest_files"
 }
 
@@ -344,7 +344,7 @@ extract_configure_help ()
   am__opt_re='' am__var_re=''
   case $1 in
     --*'=')   am__opt_re="^  $1";;
-    --*'[=]') am__opt_re='^  '`printf '%s\n' "$1" | sed 's/...$//'`'\[=';;
+    --*'[=]') am__opt_re='^  '$(printf '%s\n' "$1" | sed 's/...$//')'\[=';;
     --*)      am__opt_re="^  $1( .*|$)";;
       *)      am__var_re="^  $1( .*|$)";;
   esac
@@ -507,24 +507,10 @@ seq_ ()
     3) seq_first=$1 seq_incr=$2 seq_last=$3;;
     *) fatal_ "seq_: too many arguments";;
   esac
-  # Try to avoid forks if possible.
-  case "$BASH_VERSION" in
-    ""|[12].*)
-      : Not bash, or a too old bash version. ;;
-    *)
-      # Use eval to protect dumber shells from parsing errors.
-      eval 'for ((i = seq_first; i <= seq_last; i += seq_incr)); do
-              echo $i
-            done'
-      return 0;;
-  esac
-  # Else, use GNU seq if available.
-  seq "$@" && return 0
-  # Otherwise revert to a slower loop using expr(1).
   i=$seq_first
   while test $i -le $seq_last; do
     echo $i
-    i=`expr $i + $seq_incr`
+    i=$(($i + $seq_incr))
   done
 }
 
@@ -561,12 +547,12 @@ count_test_results ()
     # Avoid spurious failures with shells with "overly sensible"
     # errexit shell flag, such as e.g., Solaris /bin/sh.
     set +e
-    test `grep -c '^PASS:'  stdout` -eq $pass  || rc=1
-    test `grep -c '^XFAIL:' stdout` -eq $xfail || rc=1
-    test `grep -c '^SKIP:'  stdout` -eq $skip  || rc=1
-    test `grep -c '^FAIL:'  stdout` -eq $fail  || rc=1
-    test `grep -c '^XPASS:' stdout` -eq $xpass || rc=1
-    test `grep -c '^ERROR:' stdout` -eq $error || rc=1
+    test $(grep -c '^PASS:'  stdout) -eq $pass  || rc=1
+    test $(grep -c '^XFAIL:' stdout) -eq $xfail || rc=1
+    test $(grep -c '^SKIP:'  stdout) -eq $skip  || rc=1
+    test $(grep -c '^FAIL:'  stdout) -eq $fail  || rc=1
+    test $(grep -c '^XPASS:' stdout) -eq $xpass || rc=1
+    test $(grep -c '^ERROR:' stdout) -eq $error || rc=1
     grep "^# TOTAL:  *$total$" stdout || rc=1
     grep "^# PASS:  *$pass$"   stdout || rc=1
     grep "^# XFAIL:  *$xfail$" stdout || rc=1
@@ -602,7 +588,8 @@ commented_sed_unindent_prog='
 unindent ()
 {
   if test x"$sed_unindent_prog" = x; then
-    sed_unindent_prog=`printf '%s\n' "$commented_sed_unindent_prog" | sed -e "s/  *# .*//"`
+    sed_unindent_prog=$(printf '%s\n' "$commented_sed_unindent_prog" \
+                          | sed -e "s/  *# .*//")
   fi
   sed "$sed_unindent_prog" ${1+"$@"}
 }
@@ -730,6 +717,16 @@ require_compiler_ ()
 ##  required by them.                                          ##
 ## ----------------------------------------------------------- ##
 
+# Performance tests must be enabled explicitly.
+case $argv0 in
+  */perf/*)
+    case $AM_TESTSUITE_PERF in
+      [yY]|[yY]es|1) ;;
+      *) skip_ "performance tests not explicitly enabled" ;;
+    esac
+    ;;
+esac
+
 # Look for (and maybe set up) required tools and/or system features; skip
 # the current test if they are not found.
 for tool in : $required
@@ -777,10 +774,8 @@ do
         MAKE=$make_ am__using_gmake=''
         test "$MAKE" =  : && break
         echo "$me: determine whether $MAKE is GNU make"
-        # Don't use "&&" here, or a bug of 'set -e' present in some
-        # versions of the BSD shell will be triggered.  We add the
-        # dummy "else" branch for extra safety.
-        if using_gmake; then break; else :; fi
+        using_gmake && break
+        : For shells with busted 'set -e'.
       done
       test "$MAKE" = : && skip_all_ "this test requires GNU make"
       export MAKE
@@ -852,12 +847,13 @@ do
                      "the '--html' option"
       ;;
     mingw)
-      uname_s=`uname -s || echo UNKNOWN`
+      uname_s=$(uname -s || echo UNKNOWN)
       echo "$me: system name: $uname_s"
       case $uname_s in
         MINGW*) ;;
         *) skip_all_ "this test requires MSYS in MinGW mode" ;;
       esac
+      unset uname_s
       ;;
     non-root)
       # Skip this test case if the user is root.
@@ -884,9 +880,7 @@ do
       # Don't use "&&" here, to avoid a bug of 'set -e' present in
       # some (even relatively recent) versions of the BSD shell.
       # We add the dummy "else" branch for extra safety.
-      if cross_compiling; then
-        skip_all_ "doesn't work in cross-compile mode"
-      else :; fi
+      ! cross_compiling || skip_all_ "doesn't work in cross-compile mode"
       ;;
     python)
       # Python doesn't support --version, it has -V
@@ -1001,65 +995,63 @@ case " $required " in *\ gettext*) . ./t/gettext-macros.dir/get.sh;; esac
 distdir=$me-1.0
 
 # Set up the exit trap.
-if test "$sh_errexit_works" = yes; then
-  trap 'exit_status=$?
-    set +e
-    cd "$am_top_builddir"
-    if test $am_using_tap = yes; then
-      if test "$planned_" = later && test $exit_status -eq 0; then
-        plan_ "now"
-      fi
-      test $exit_status -eq 0 && test $tap_pass_count_ -eq $tap_count_ \
-        || keep_testdirs=yes
-    else
-      # This is to ensure that a test script does give a SKIP outcome just
-      # because a command in it happens to exit with status 77.  This
-      # behaviour, while from time to time useful to developers, is not
-      # meant to be enabled by default, as it could cause spurious failures
-      # in the wild.  Thus it will be enabled only when the variable
-      # "am_explicit_skips" is set to a "true" value.
-      case $am_explicit_skips in
-        [yY]|[yY]es|1)
-          if test $exit_status -eq 77 && test $am__test_skipped != yes; then
-            echo "$me: implicit skip turned into failure"
-            exit_status=78
-          fi;;
-      esac
-      test $exit_status -eq 0 || keep_testdirs=yes
+trap 'exit_status=$?
+  set +e
+  cd "$am_top_builddir"
+  if test $am_using_tap = yes; then
+    if test "$planned_" = later && test $exit_status -eq 0; then
+      plan_ "now"
     fi
-    am_keeping_testdirs || rm_rf_ $testSubDir
-    set +x
-    echo "$me: exit $exit_status"
-    exit $exit_status
-  ' 0
-  trap "fatal_ 'caught signal SIGHUP'" 1
-  trap "fatal_ 'caught signal SIGINT'" 2
-  trap "fatal_ 'caught signal SIGTERM'" 15
-  # Various shells seems to just ignore SIGQUIT under some circumstances,
-  # even if the signal is not blocked; however, if the signal it trapped,
-  # the trap gets correctly executed.  So we also trap SIGQUIT.
-  # Here is a list of some shells that have been verified to exhibit the
-  # problematic behavior with SIGQUIT:
-  #  - zsh 4.3.12 on Debian GNU/Linux
-  #  - /bin/ksh and /usr/xpg4/bin/sh on Solaris 10
-  #  - Bash 3.2.51 on Solaris 10 and bash 4.1.5 on Debian GNU/Linux
-  #  - AT&T ksh on Debian Gnu/Linux (deb package ksh, version 93u-1)
-  # OTOH, at least these shells that do *not* exhibit that behaviour:
-  #  - modern version of the Almquist Shell (at least 0.5.5.1), on
-  #    both Solaris and GNU/Linux
-  #  - Solaris 10 /bin/sh
-  #  - public domain Korn Shell, version 5.2.14, on Debian GNU/Linux
-  trap "fatal_ 'caught signal SIGQUIT'" 3
-  # Ignore further SIGPIPE in the trap code.  This is required to avoid
-  # a very weird issue with some shells, at least when the execution of
-  # the automake testsuite is driven by the 'prove' utility: if prove
-  # (or the make process that has spawned it) gets interrupted with
-  # Ctrl-C, the shell might go in a loop, continually getting a SIGPIPE,
-  # sometimes finally dumping core, other times hanging indefinitely.
-  # See also Test::Harness bug [rt.cpan.org #70855], archived at
-  # <https://rt.cpan.org/Ticket/Display.html?id=70855>
-  trap "trap '' 13; fatal_ 'caught signal SIGPIPE'" 13
-fi
+    test $exit_status -eq 0 && test $tap_pass_count_ -eq $tap_count_ \
+      || keep_testdirs=yes
+  else
+    # This is to ensure that a test script does give a SKIP outcome just
+    # because a command in it happens to exit with status 77.  This
+    # behaviour, while from time to time useful to developers, is not
+    # meant to be enabled by default, as it could cause spurious failures
+    # in the wild.  Thus it will be enabled only when the variable
+    # "am_explicit_skips" is set to a "true" value.
+    case $am_explicit_skips in
+      [yY]|[yY]es|1)
+        if test $exit_status -eq 77 && test $am__test_skipped != yes; then
+          echo "$me: implicit skip turned into failure"
+          exit_status=78
+        fi;;
+    esac
+    test $exit_status -eq 0 || keep_testdirs=yes
+  fi
+  am_keeping_testdirs || rm_rf_ $testSubDir
+  set +x
+  echo "$me: exit $exit_status"
+  exit $exit_status
+' 0
+trap "fatal_ 'caught signal SIGHUP'" 1
+trap "fatal_ 'caught signal SIGINT'" 2
+trap "fatal_ 'caught signal SIGTERM'" 15
+# Various shells seems to just ignore SIGQUIT under some circumstances,
+# even if the signal is not blocked; however, if the signal it trapped,
+# the trap gets correctly executed.  So we also trap SIGQUIT.
+# Here is a list of some shells that have been verified to exhibit the
+# problematic behavior with SIGQUIT:
+#  - zsh 4.3.12 on Debian GNU/Linux
+#  - /bin/ksh and /usr/xpg4/bin/sh on Solaris 10
+#  - Bash 3.2.51 on Solaris 10 and bash 4.1.5 on Debian GNU/Linux
+#  - AT&T ksh on Debian Gnu/Linux (deb package ksh, version 93u-1)
+# OTOH, at least these shells that do *not* exhibit that behaviour:
+#  - modern version of the Almquist Shell (at least 0.5.5.1), on
+#    both Solaris and GNU/Linux
+#  - Solaris 10 /bin/sh
+#  - public domain Korn Shell, version 5.2.14, on Debian GNU/Linux
+trap "fatal_ 'caught signal SIGQUIT'" 3
+# Ignore further SIGPIPE in the trap code.  This is required to avoid
+# a very weird issue with some shells, at least when the execution of
+# the automake testsuite is driven by the 'prove' utility: if prove
+# (or the make process that has spawned it) gets interrupted with
+# Ctrl-C, the shell might go in a loop, continually getting a SIGPIPE,
+# sometimes finally dumping core, other times hanging indefinitely.
+# See also Test::Harness bug [rt.cpan.org #70855], archived at
+# <https://rt.cpan.org/Ticket/Display.html?id=70855>
+trap "trap '' 13; fatal_ 'caught signal SIGPIPE'" 13
 
 # Create and populate the temporary directory, if and as required.
 if test x"$am_create_testdir" = x"no"; then
@@ -1089,10 +1081,10 @@ else
     # to append AC_OUTPUT.
     {
       echo "AC_INIT([$me], [1.0])"
-      if test x"$am_parallel_tests" = x"yes"; then
-        echo "AM_INIT_AUTOMAKE([parallel-tests])"
-      else
+      if test x"$am_serial_tests" = x"yes"; then
         echo "AM_INIT_AUTOMAKE"
+      else
+        echo "AM_INIT_AUTOMAKE([parallel-tests])"
       fi
       echo "AC_CONFIG_FILES([Makefile])"
     } >configure.ac || framework_failure_ "creating configure.ac skeleton"