automake-patches
[Top][All Lists]
Advanced

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

[FYI 1/7] {tap-testsuite-work} test defs: test directory creation more c


From: Stefano Lattarini
Subject: [FYI 1/7] {tap-testsuite-work} test defs: test directory creation more configurable
Date: Tue, 9 Aug 2011 15:35:29 +0200

After this change, the individual tests will be able to tell
`./defs' whether or not to create a temporary test directory
for them, and if yes, whether or not to pre-populate it.
* tests/defs: Only create the temporary test directory if the
variable `$am_create_testdir' is not set to "no".  In this
case, only pre-populate it if that variable is not set to
`$empty'.

* tests/defs-static.in: Check that `$am_create_testdir' is not
exported in the environment.
* tests/self-check-env-sanitize.test: Update.
* tests/self-check-dir.test: Extend, and make deeper and more
robust.
* tests/README (Section "Writing test cases" subsection "Do"):
Update.
* tests/autodist.test: Set `$am_create_testdir' instead of
removing by hand files created by ./defs.
* tests/tap-doc2.test: Likewise.
---
 ChangeLog                          |   21 ++++++++++++
 tests/README                       |   13 +++++---
 tests/autodist.test                |    6 +---
 tests/defs                         |   61 +++++++++++++++++++-----------------
 tests/defs-static.in               |    1 +
 tests/self-check-dir.test          |   49 ++++++++++++++++++++++-------
 tests/self-check-env-sanitize.test |    1 +
 tests/tap-doc2.test                |    6 +---
 8 files changed, 102 insertions(+), 56 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e0f922a..71611ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2011-08-09  Stefano Lattarini  <address@hidden>
+
+       test defs: test directory creation more configurable
+       After this change, the individual tests will be able to tell
+       `./defs' whether or not to create a temporary test directory
+       for them, and if yes, whether or not to pre-populate it.
+       * tests/defs: Only create the temporary test directory if the
+       variable `$am_create_testdir' is not set to "no".  In this
+       case, only pre-populate it if that variable is not set to
+       `$empty'.
+       * tests/defs-static.in: Check that `$am_create_testdir' is not
+       exported in the environment.
+       * tests/self-check-env-sanitize.test: Update.
+       * tests/self-check-dir.test: Extend, and make deeper and more
+       robust.
+       * tests/README (Section "Writing test cases" subsection "Do"):
+       Update.
+       * tests/autodist.test: Set `$am_create_testdir' instead of
+       removing by hand files created by ./defs.
+       * tests/tap-doc2.test: Likewise.
+
 2011-08-08  Stefano Lattarini  <address@hidden>
 
        testsuite: more uses of the `seq_' function
diff --git a/tests/README b/tests/README
index 8b8da14..54ec670 100644
--- a/tests/README
+++ b/tests/README
@@ -191,11 +191,14 @@ Do
   should be very very few), set the shell variable `parallel_tests' to
   "no" before including ./defs.
 
-  ./defs sets a skeleton configure.in.  If possible, append to this
-  file.  In some cases you'll have to overwrite it, but this should
-  be the exception.  Note that configure.in registers Makefile.in
-  but do not output anything by default.  If you need ./configure
-  to create Makefile, append AC_OUTPUT to configure.in.
+  ./defs brings in some commonly required files, and sets a skeleton
+  configure.in.  If possible, append to this file.  In some cases
+  you'll have to overwrite it, but this should be the exception.  Note
+  that configure.in registers Makefile.in but do not output anything by
+  default.  If you need ./configure to create Makefile, append AC_OUTPUT
+  to configure.in.  In case you don't want ./defs to pre-populate your
+  test directory (which is a rare occurrence), set `$am_create_destdir'
+  to "empty" before sourcing ./defs.
 
   By default, the testcases are run with the `errexit' shell flag on,
   to make it easier to catch failures you might not have thought of.
diff --git a/tests/autodist.test b/tests/autodist.test
index f2b31ab..ed8dcc3 100755
--- a/tests/autodist.test
+++ b/tests/autodist.test
@@ -19,13 +19,9 @@
 # Related to automake bug#7819.
 # Keep this test in sync with sister test `autodist-subdir.test'.
 
+am_create_testdir=empty
 . ./defs || Exit 1
 
-# Ensure we are run from the right directory.
-# (The last thing we want is to delete some random user files.)
-test -f ../defs-static && test -f ../defs || Exit 99
-rm -f *
-
 cat > configure.in <<END
 AC_INIT([$me], [1.0])
 AC_CONFIG_AUX_DIR([.])
diff --git a/tests/defs b/tests/defs
index dc2fee7..0ba984e 100644
--- a/tests/defs
+++ b/tests/defs
@@ -809,17 +809,7 @@ esac
 # Test scripts are free to override this if they need to.
 distdir=$me-1.0
 
-# The subdirectory where the current test script will run and write its
-# temporary/data files.  This will be created shortly, and will be removed
-# by the cleanup trap below if the test passes.  If the test doesn't pass,
-# this directory will be kept, to facilitate debugging.
-testSubDir=$me.dir
-
-test ! -d $testSubDir || rm_rf_ $testSubDir
-mkdir $testSubDir || framework_failure_ "creating test subdirectory"
-
-cd ./$testSubDir
-
+# Set up the exit trap.
 if test "$sh_errexit_works" = yes; then
   trap 'exit_status=$?
     set +e
@@ -865,25 +855,38 @@ if test "$sh_errexit_works" = yes; then
   unset signal
 fi
 
-# Copy in some files we need.
-cp "$top_testsrcdir"/lib/install-sh "$top_testsrcdir"/lib/missing \
-   "$top_testsrcdir"/lib/depcomp . \
-  || framework_failure_ "fetching common files from lib/"
-
-# Build appropriate environment in test directory.  Eg create
-# configure.in, touch all necessary files, etc.
-# Don't use AC_OUTPUT, but AC_CONFIG_FILES so that appending
-# still produces a valid configure.ac.  But then, tests running
-# config.status really need to append AC_OUTPUT.
-{
-  echo "AC_INIT([$me], [1.0])"
-  if test x"$parallel_tests" = x"yes"; then
-    echo "AM_INIT_AUTOMAKE([parallel-tests])"
-  else
-    echo "AM_INIT_AUTOMAKE"
+# Create and populate the temporary directory, if and as required.
+if test x"$am_create_testdir" = x"no"; then
+  testSubDir=
+else
+  # The subdirectory where the current test script will run and write its
+  # temporary/data files.  This will be created shortly, and will be removed
+  # by the cleanup trap below if the test passes.  If the test doesn't pass,
+  # this directory will be kept, to facilitate debugging.
+  testSubDir=$me.dir
+  test ! -d $testSubDir || rm_rf_ $testSubDir
+  mkdir $testSubDir || framework_failure_ "creating test subdirectory"
+  cd ./$testSubDir
+  if test x"$am_create_testdir" != x"empty"; then
+    cp "$top_testsrcdir"/lib/install-sh "$top_testsrcdir"/lib/missing \
+       "$top_testsrcdir"/lib/depcomp . \
+      || framework_failure_ "fetching common files from lib/"
+    # Build appropriate environment in test directory.  E.g., create
+    # configure.in, touch all necessary files, etc.  Don't use AC_OUTPUT,
+    # but AC_CONFIG_FILES so that appending still produces a valid
+    # configure.in.  But then, tests running config.status really need
+    # to append AC_OUTPUT.
+    {
+      echo "AC_INIT([$me], [1.0])"
+      if test x"$parallel_tests" = x"yes"; then
+        echo "AM_INIT_AUTOMAKE([parallel-tests])"
+      else
+        echo "AM_INIT_AUTOMAKE"
+      fi
+      echo "AC_CONFIG_FILES([Makefile])"
+    } > configure.in
   fi
-  echo "AC_CONFIG_FILES([Makefile])"
-} >configure.in
+fi
 
 ## ---------------- ##
 ##  Ready to go...  ##
diff --git a/tests/defs-static.in b/tests/defs-static.in
index 62f7486..0a7b77a 100644
--- a/tests/defs-static.in
+++ b/tests/defs-static.in
@@ -75,6 +75,7 @@ for var in \
   required \
   use_tap \
   parallel_tests \
+  am_create_testdir \
   test_prefer_config_shell \
   original_AUTOMAKE \
   original_ACLOCAL \
diff --git a/tests/self-check-dir.test b/tests/self-check-dir.test
index 0b4dd4e..1aae601 100755
--- a/tests/self-check-dir.test
+++ b/tests/self-check-dir.test
@@ -16,26 +16,51 @@
 
 # Sanity check for the automake testsuite.
 # Check that tests using `./defs' create a proper temporary directory,
-# and run in it.
+# and run in it.  Also check that we can prevent the pre-population
+# and the creation of such directory if we want.
 
 . ./defs-static || exit 1
 
 set -ex
-
 AM_TESTS_REEXEC=no; export AM_TESTS_REEXEC
 
-this=S_dir
-outcome=:
-pwd
+# This needs to be consistent with what $SHELL deems to be the
+# current working directory.
+cwd=`$SHELL -c 'pwd'` || exit 99
+echo "$cwd"
+
+rm -f _self.tmp
 
-rm -f $this.tmp
+st=0
+$SHELL -c '
+  . ./defs || Exit 1
+  pwd; ls -l; # For debugging.
+  : > _self.tmp
+  test -f install-sh
+  test -f configure.in
+  case `pwd` in '"$cwd"'/_self.dir);; *) Exit 1;; esac
+' _self.test || st=1
+test -f _self.tmp && { rm -f _self.tmp; st=1; }
+test $st -eq 0 || exit 1
 
-$SHELL -c "
+st=0
+$SHELL -c '
+  am_create_testdir=empty
   . ./defs || Exit 1
-  : > $this.tmp
-  case \`pwd\` in '`pwd`'/$this.dir);; *) Exit 1;; esac
-" $this.test || outcome=false
+  pwd; ls -l; # For debugging.
+  ls -a | grep -v "^\\.\\{1,2\\}$" | grep . && Exit 1
+  : > _self.tmp
+  case `pwd` in '"$cwd"'/_self.dir);; *) Exit 1;; esac
+  :
+' _self.test || st=1
+test -f _self.tmp && { rm -f _self.tmp; st=1; }
+test $st -eq 0 || exit 1
 
-test -f $this.tmp && { rm -f $this.tmp; outcome=false; }
+$SHELL -c '
+  am_create_testdir=no
+  . ./defs || Exit 1
+  test -f self-check-dir.test
+  case `pwd` in '"$cwd"');; *) Exit 1;; esac
+' _self.test || exit 1
 
-$outcome
+:
diff --git a/tests/self-check-env-sanitize.test 
b/tests/self-check-env-sanitize.test
index e2d8f2a..a7c66de 100755
--- a/tests/self-check-env-sanitize.test
+++ b/tests/self-check-env-sanitize.test
@@ -28,6 +28,7 @@ vars='
   parallel_tests
   required
   use_tap
+  am_create_testdir
   test_prefer_config_shell
   original_AUTOMAKE
   original_ACLOCAL
diff --git a/tests/tap-doc2.test b/tests/tap-doc2.test
index 63bdc23..45d09ca 100755
--- a/tests/tap-doc2.test
+++ b/tests/tap-doc2.test
@@ -18,14 +18,10 @@
 # See section "Using the TAP test protocol", subsection "Use TAP
 # with the Automake test harness".
 
+am_create_testdir=empty
 parallel_tests=yes
 . ./defs || Exit 1
 
-# Ensure we are run from the right directory.
-# (The last thing we want is to delete some random user files.)
-test -f ../defs-static && test -f ../defs || Exit 99
-rm -f *
-
 cat > Makefile.am <<'END'
 TEST_LOG_DRIVER = $(PERL) $(srcdir)/build-aux/tap-driver
 TESTS = foo.test bar.test baz.test
-- 
1.7.2.3




reply via email to

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