automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 23/32] tests: split test libs into "generic" and "automake-specif


From: Stefano Lattarini
Subject: [PATCH 23/32] tests: split test libs into "generic" and "automake-specific"
Date: Thu, 26 Jul 2012 14:04:49 +0200

This is the first step in the quest to merge the generically useful
parts of our test suite framework in a more generic project, like
Gnulib.  Time will tell if we'll succeed, and whether the success will
be worth the extra hassle.

* t/ax/test-init.sh: Split out ...
* t/ax/am-test-lib.sh, t/ax/test-lib.sh: ... into these two tests.
* defs, Makefile.am: Adjust.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 Makefile.am                           |   4 +-
 defs                                  |   5 +-
 t/ax/{test-init.sh => am-test-lib.sh} | 242 +--------------------------------
 t/ax/test-lib.sh                      | 247 ++++++++++++++++++++++++++++++++++
 4 files changed, 258 insertions(+), 240 deletions(-)
 rename t/ax/{test-init.sh => am-test-lib.sh} (76%)
 create mode 100644 t/ax/test-lib.sh

diff --git a/Makefile.am b/Makefile.am
index 495fc69..172347f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -398,8 +398,10 @@ $(srcdir)/t/testsuite-part.am: 
$(srcdir)/gen-testsuite-part Makefile.am
 nodist_noinst_SCRIPTS = \
   t/wrap/aclocal-$(APIVERSION) \
   t/wrap/automake-$(APIVERSION)
+
 dist_noinst_DATA = \
-  t/ax/test-init.sh \
+  t/ax/test-lib.sh \
+  t/ax/am-test-lib.sh \
   t/ax/tap-functions.sh
 
 # Few more static dependencies.
diff --git a/defs b/defs
index 93b0bfd..ea6c84c 100644
--- a/defs
+++ b/defs
@@ -15,11 +15,14 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+set -e
+
 # Source the shell static setup and variable definitions.
 . test-defs.sh; test $? -eq 0 || exit 99
 
 # Source the actual code for test initialization and setup.
-. test-init.sh
+. test-lib.sh
+. am-test-lib.sh
 
 # Run that setup, and return control to the test script sourcing us.
 am_test_setup
diff --git a/t/ax/test-init.sh b/t/ax/am-test-lib.sh
similarity index 76%
rename from t/ax/test-init.sh
rename to t/ax/am-test-lib.sh
index 1cf5f5f..aaa8df5 100644
--- a/t/ax/test-init.sh
+++ b/t/ax/am-test-lib.sh
@@ -19,65 +19,12 @@
 ###  IMPORTANT NOTE: keep this file 'set -e' clean.  ###
 ########################################################
 
-# Enable the errexit shell flag early.
-set -e
-
-
-## ------------------ ##
-##  Early variables.  ##
-## ------------------ ##
-
-# A single whitespace character.
-sp=' '
-# A tabulation character.
-tab='  '
-# A newline character.
-nl='
-'
 # A literal escape character.  Used by test checking colored output.
 esc=''
 
-# As autoconf-generated configure scripts do, ensure that IFS
-# is defined initially, so that saving and restoring $IFS works.
-IFS=$sp$tab$nl
-
-## ------------------------------------ ##
-##  General testsuite shell functions.  ##
-## ------------------------------------ ##
-
-# Print warnings (e.g., about skipped and failed tests) to this file
-# number.  Override by putting, say:
-#   AM_TESTS_ENVIRONMENT = stderr_fileno_=9; export stderr_fileno_;
-#   AM_TESTS_FD_REDIRECT = 9>&2
-# in your Makefile.am.
-# This is useful when using automake's parallel tests mode, to print the
-# reason for skip/failure to console, rather than to the *.log files.
-: ${stderr_fileno_=2}
-
-# Helper functions used by "plain" tests of the Automake testsuite
-# (i.e., tests that don't use any test protocol).
-# TAP tests will override these functions with their TAP-enhanced
-# equivalents later  (see sourcing of 'tap-functions.sh' below).
-# These are copied from Gnulib's 'tests/init.sh'.
-warn_ () { echo "$@" 1>&$stderr_fileno_; }
-fail_ () { warn_ "$me: failed test: $@"; exit 1; }
-skip_ () { warn_ "$me: skipped test: $@"; exit 77; }
-fatal_ () { warn_ "$me: hard error: $@"; exit 99; }
-framework_failure_ () { warn_ "$me: set-up failure: $@"; exit 99; }
-# For compatibility with TAP functions.
-skip_all_ () { skip_ "$@"; }
-
-if test $am_using_tap = yes; then
-  am_tap_funcs_file=$am_testauxdir/tap-functions.sh
-  if test -f "$am_tap_funcs_file"; then
-    . "$am_tap_funcs_file" \
-      || fatal_ "error sourcing $am_tap_funcs_file"
-  else
-    fatal_ " $am_tap_funcs_file not found" >&2
-  fi
-  unset am_tap_funcs_file
-fi
-
+# This might be used in testcases checking distribution-related features.
+# Test scripts are free to override this if they need to.
+distdir=$me-1.0
 
 ## ---------------------- ##
 ##  Environment cleanup.  ##
@@ -137,40 +84,6 @@ unset pfx
 # Re-enable, it had been temporarily disabled above.
 set -e
 
-
-## ---------------------------- ##
-##  Auxiliary shell functions.  ##
-## ---------------------------- ##
-
-# Tell whether we should keep the test directories around, even in
-# case of success.  By default, we don't.
-am_keeping_testdirs ()
-{
-  case $keep_testdirs in
-     ""|n|no|NO) return 1;;
-              *) return 0;;
-  esac
-}
-
-# This is used in '_am_exit' and in the exit trap.  See comments in
-# the latter for more information.
-am__test_skipped=no
-
-# We use a trap below for cleanup.  This requires us to go through
-# hoops to get the right exit status transported through the signal.
-# Turn off errexit here so that we don't trip the bug with OSF1/Tru64
-# sh inside this function (FIXME: is this still relevant now that we
-# require a POSIX shell?).
-_am_exit ()
-{
-  set +e
-  # See comments in the exit trap for the reason we do this.
-  test 77 = $1 && am__test_skipped=yes
-  # Spurious escaping to ensure we do not call our 'exit' alias.
-  (\exit $1); \exit $1
-}
-alias exit=_am_exit
-
 # cross_compiling
 # ---------------
 # Tell whether we are cross-compiling.  This is especially useful to skip
@@ -421,41 +334,6 @@ am__useless_vpath_rebuild=""
 
 yl_distcheck () { useless_vpath_rebuild || $MAKE distcheck ${1+"$@"}; }
 
-# seq_ - print a sequence of numbers
-# ----------------------------------
-# This function simulates GNU seq(1) portably.  Valid usages:
-#  - seq LAST
-#  - seq FIRST LAST
-#  - seq FIRST INCREMENT LAST
-seq_ ()
-{
-  case $# in
-    0) fatal_ "seq_: missing argument";;
-    1) seq_first=1  seq_incr=1  seq_last=$1;;
-    2) seq_first=$1 seq_incr=1  seq_last=$2;;
-    3) seq_first=$1 seq_incr=$2 seq_last=$3;;
-    *) fatal_ "seq_: too many arguments";;
-  esac
-  i=$seq_first
-  while test $i -le $seq_last; do
-    echo $i
-    i=$(($i + $seq_incr))
-  done
-}
-
-# rm_rf_ [FILES OR DIRECTORIES ...]
-# ---------------------------------
-# Recursively remove the given files or directory, also handling the case
-# of non-writable subdirectories.
-rm_rf_ ()
-{
-  test $# -gt 0 || return 0
-  # Ignore failures in find, we are only interested in failures of the
-  # final rm.
-  find "$@" -type d ! -perm -700 -exec chmod u+rwx {} \; || :
-  rm -rf "$@"
-}
-
 # count_test_results total=N pass=N fail=N xpass=N xfail=N skip=N error=N
 # -----------------------------------------------------------------------
 # Check that a testsuite run driven by the parallel-tests harness has
@@ -493,37 +371,6 @@ count_test_results ()
   )
 }
 
-commented_sed_unindent_prog='
-  /^$/b                    # Nothing to do for empty lines.
-  x                        # Get x<indent> into pattern space.
-  /^$/{                    # No prior x<indent>, go prepare it.
-    g                      # Copy this 1st non-blank line into pattern space.
-    s/^\(['"$tab"' ]*\).*/x\1/   # Prepare x<indent> in pattern space.
-  }                        # Now: x<indent> in pattern and <line> in hold.
-  G                        # Build x<indent>\n<line> in pattern space, and
-  h                        # duplicate it into hold space.
-  s/\n.*$//                # Restore x<indent> in pattern space, and
-  x                        # exchange with the above duplicate in hold space.
-  s/^x\(.*\)\n\1//         # Remove leading <indent> from <line>.
-  s/^x.*\n//               # Restore <line> when there is no leading <indent>.
-'
-
-# unindent [input files...]
-# -------------------------
-# Remove the "proper" amount of leading whitespace from the given files,
-# and output the result on stdout.  That amount is determined by looking
-# at the leading whitespace of the first non-blank line in the input
-# files.  If no input file is specified, standard input is implied.
-unindent ()
-{
-  if test x"$sed_unindent_prog" = x; then
-    sed_unindent_prog=$(printf '%s\n' "$commented_sed_unindent_prog" \
-                          | sed -e "s/  *# .*//")
-  fi
-  sed "$sed_unindent_prog" ${1+"$@"}
-}
-sed_unindent_prog="" # Avoid interferences from the environment.
-
 # get_shell_script SCRIPT-NAME
 # -----------------------------
 # Fetch an Automake-provided shell script from the 'lib/' directory into
@@ -901,79 +748,8 @@ process_requirements ()
 
 ## ---------------------------------------------------------------- ##
 ##  Create and set up of the temporary directory used by the test.  ##
-##  Set up of the exit trap for cleanup of said directory.          ##
 ## ---------------------------------------------------------------- ##
 
-# This might be used in testcases checking distribution-related features.
-# Test scripts are free to override this if they need to.
-distdir=$me-1.0
-
-# Set up the exit trap.
-am_exit_trap ()
-{
-  exit_status=$1
-  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
-  fi
-  am_keeping_testdirs || rm_rf_ $am_test_subdir
-  set +x
-  echo "$me: exit $exit_status"
-  # Spurious escaping to ensure we do not call our "exit" alias.
-  \exit $exit_status
-}
-
-am_set_exit_traps ()
-{
-  trap 'am_exit_trap $?' 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
-  #  - 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
-}
-
 am_setup_testdir ()
 {
   # The subdirectory where the current test script will run and write its
@@ -1012,19 +788,9 @@ am_setup_testdir ()
   fi
 }
 
-am_test_setup ()
+am_extra_info ()
 {
-  process_requirements $required
-  am_set_exit_traps
-  # Create and populate the temporary directory, if required.
-  if test x"$am_create_testdir" = x"no"; then
-    am_test_subdir=
-  else
-    am_setup_testdir
-  fi
   echo "Running from installcheck: $am_running_installcheck"
   echo "Using TAP: $am_using_tap"
   echo "PATH = $PATH"
-  set -x
-  pwd
 }
diff --git a/t/ax/test-lib.sh b/t/ax/test-lib.sh
new file mode 100644
index 0000000..1efcaa9
--- /dev/null
+++ b/t/ax/test-lib.sh
@@ -0,0 +1,247 @@
+# -*- shell-script -*-
+#
+# Copyright (C) 1996-2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+########################################################
+###  IMPORTANT NOTE: keep this file 'set -e' clean.  ###
+########################################################
+
+# A single whitespace character.
+sp=' '
+# A tabulation character.
+tab='  '
+# A newline character.
+nl='
+'
+
+# As autoconf-generated configure scripts do, ensure that IFS
+# is defined initially, so that saving and restoring $IFS works.
+IFS=$sp$tab$nl
+
+# We use a trap below for cleanup.  This requires us to go through
+# hoops to get the right exit status transported through the signal.
+# Turn off errexit here so that we don't trip the bug with OSF1/Tru64
+# sh inside this function (FIXME: is this still relevant now that we
+# require a POSIX shell?).
+_am_exit ()
+{
+  set +e
+  # See comments in the exit trap for the reason we do this.
+  test 77 = $1 && am__test_skipped=yes
+  # Spurious escaping to ensure we do not call our 'exit' alias.
+  (\exit $1); \exit $1
+}
+# Avoid interferences from the environment
+am__test_skipped=no
+# This alias must actually be placed before any use if 'exit' -- even
+# just inside a function definition.  Weird, but real.
+alias exit=_am_exit
+
+## ------------------------------------ ##
+##  General testsuite shell functions.  ##
+## ------------------------------------ ##
+
+# Print warnings (e.g., about skipped and failed tests) to this file
+# number.  Override by putting, say:
+#   AM_TESTS_ENVIRONMENT = stderr_fileno_=9; export stderr_fileno_;
+#   AM_TESTS_FD_REDIRECT = 9>&2
+# in your Makefile.am.
+# This is useful when using automake's parallel tests mode, to print the
+# reason for skip/failure to console, rather than to the *.log files.
+: ${stderr_fileno_=2}
+
+# Helper functions used by "plain" tests of the Automake testsuite
+# (i.e., tests that don't use any test protocol).
+# TAP tests will override these functions with their TAP-enhanced
+# equivalents later  (see sourcing of 'tap-functions.sh' below).
+# These are copied from Gnulib's 'tests/init.sh'.
+warn_ () { echo "$@" 1>&$stderr_fileno_; }
+fail_ () { warn_ "$me: failed test: $@"; exit 1; }
+skip_ () { warn_ "$me: skipped test: $@"; exit 77; }
+fatal_ () { warn_ "$me: hard error: $@"; exit 99; }
+framework_failure_ () { warn_ "$me: set-up failure: $@"; exit 99; }
+# For compatibility with TAP functions.
+skip_all_ () { skip_ "$@"; }
+
+if test $am_using_tap = yes; then
+  . tap-functions.sh
+fi
+
+## ---------------------------- ##
+##  Auxiliary shell functions.  ##
+## ---------------------------- ##
+
+# Tell whether we should keep the test directories around, even in
+# case of success.  By default, we don't.
+am_keeping_testdirs ()
+{
+  case $keep_testdirs in
+     ""|n|no|NO) return 1;;
+              *) return 0;;
+  esac
+}
+
+# seq_ - print a sequence of numbers
+# ----------------------------------
+# This function simulates GNU seq(1) portably.  Valid usages:
+#  - seq LAST
+#  - seq FIRST LAST
+#  - seq FIRST INCREMENT LAST
+seq_ ()
+{
+  case $# in
+    0) fatal_ "seq_: missing argument";;
+    1) seq_first=1  seq_incr=1  seq_last=$1;;
+    2) seq_first=$1 seq_incr=1  seq_last=$2;;
+    3) seq_first=$1 seq_incr=$2 seq_last=$3;;
+    *) fatal_ "seq_: too many arguments";;
+  esac
+  i=$seq_first
+  while test $i -le $seq_last; do
+    echo $i
+    i=$(($i + $seq_incr))
+  done
+}
+
+# rm_rf_ [FILES OR DIRECTORIES ...]
+# ---------------------------------
+# Recursively remove the given files or directory, also handling the case
+# of non-writable subdirectories.
+rm_rf_ ()
+{
+  test $# -gt 0 || return 0
+  # Ignore failures in find, we are only interested in failures of the
+  # final rm.
+  find "$@" -type d ! -perm -700 -exec chmod u+rwx {} \; || :
+  rm -rf "$@"
+}
+
+commented_sed_unindent_prog='
+  /^$/b                    # Nothing to do for empty lines.
+  x                        # Get x<indent> into pattern space.
+  /^$/{                    # No prior x<indent>, go prepare it.
+    g                      # Copy this 1st non-blank line into pattern space.
+    s/^\(['"$tab"' ]*\).*/x\1/   # Prepare x<indent> in pattern space.
+  }                        # Now: x<indent> in pattern and <line> in hold.
+  G                        # Build x<indent>\n<line> in pattern space, and
+  h                        # duplicate it into hold space.
+  s/\n.*$//                # Restore x<indent> in pattern space, and
+  x                        # exchange with the above duplicate in hold space.
+  s/^x\(.*\)\n\1//         # Remove leading <indent> from <line>.
+  s/^x.*\n//               # Restore <line> when there is no leading <indent>.
+'
+
+# unindent [input files...]
+# -------------------------
+# Remove the "proper" amount of leading whitespace from the given files,
+# and output the result on stdout.  That amount is determined by looking
+# at the leading whitespace of the first non-blank line in the input
+# files.  If no input file is specified, standard input is implied.
+unindent ()
+{
+  if test x"$sed_unindent_prog" = x; then
+    sed_unindent_prog=$(printf '%s\n' "$commented_sed_unindent_prog" \
+                          | sed -e "s/  *# .*//")
+  fi
+  sed "$sed_unindent_prog" ${1+"$@"}
+}
+sed_unindent_prog="" # Avoid interferences from the environment.
+
+## ---------------------------------------------------------------- ##
+##  Create and set up of the temporary directory used by the test.  ##
+##  Set up of the exit trap for cleanup of said directory.          ##
+## ---------------------------------------------------------------- ##
+
+# Set up the exit trap.
+am_exit_trap ()
+{
+  exit_status=$1
+  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
+  fi
+  am_keeping_testdirs || rm_rf_ $am_test_subdir
+  set +x
+  echo "$me: exit $exit_status"
+  # Spurious escaping to ensure we do not call our "exit" alias.
+  \exit $exit_status
+}
+
+am_set_exit_traps ()
+{
+  trap 'am_exit_trap $?' 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
+  #  - 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
+}
+
+am_test_setup ()
+{
+  process_requirements $required
+  am_set_exit_traps
+  # Create and populate the temporary directory, if required.
+  if test x"$am_create_testdir" = x"no"; then
+    am_test_subdir=
+  else
+    am_setup_testdir
+  fi
+  am_extra_info
+  set -x
+  pwd
+}
-- 
1.7.12.rc0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]