]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
test defs: new function 'am_keeping_testdirs', for better APIs
authorStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 25 Oct 2011 13:20:42 +0000 (15:20 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 25 Oct 2011 13:21:23 +0000 (15:21 +0200)
This change is meant to make it easier for TAP-based test scripts
to remove files left over by completed (sub)tests, while still
honoring the user-provided `$keep_testdirs' setting.

* tests/defs (am_keeping_testdirs): New function, telling whether
we should keep the test directories around, even in case of
success (by default, we don't).
(exit trap): Use it.
* tests/depmod.tap: Likewise.
* tests/instspc.tap: Likewise.  Also, fix some pre-existing
"copy & paste" bugs, and a typo in comments.

ChangeLog
tests/defs
tests/depmod.tap
tests/instspc.tap

index adba25e7258ef25a5f2783fd7965141a152727b0..d493ba3334072bf14851356f7d4290d4d3d74560 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2011-10-25  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       test defs: new function 'am_keeping_testdirs', for better APIs
+
+       This change is meant to make it easier for TAP-based test scripts
+       to remove files left over by completed (sub)tests, while still
+       honoring the user-provided `$keep_testdirs' setting.
+
+       * tests/defs (am_keeping_testdirs): New function, telling whether
+       we should keep the test directories around, even in case of
+       success (by default, we don't).
+       (exit trap): Use it.
+       * tests/depmod.tap: Likewise.
+       * tests/instspc.tap: Likewise.  Also, fix some pre-existing
+       "copy & paste" bugs, and a typo in comments.
+
 2011-10-25  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tests: remove redundant `set -e', and other minor improvements
index e5f66a52a98620bce29032f6709e471fc8a2a8a7..7b9db87001765563671c3fc29ac4fe9e1240452e 100644 (file)
@@ -184,6 +184,16 @@ 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 `Exit' and in the exit trap.  See comments in the latter
 # for more information,
 am__test_skipped=no
@@ -933,11 +943,6 @@ if test "$sh_errexit_works" = yes; then
   trap 'exit_status=$?
     set +e
     cd "$testbuilddir"
-    if test -n "$keep_testdirs"; then
-      keep_testdirs=yes
-    else
-      keep_testdirs=no
-    fi
     if test $am_using_tap = yes; then
       if test $have_tap_plan_ != yes && test $exit_status -eq 0; then
         plan_ "now"
@@ -960,7 +965,7 @@ if test "$sh_errexit_works" = yes; then
       esac
       test $exit_status -eq 0 || keep_testdirs=yes
     fi
-    test $keep_testdirs = no && rm_rf_ $testSubDir
+    am_keeping_testdirs || rm_rf_ $testSubDir
     set +x
     echo "$me: exit $exit_status"
     exit $exit_status
index f2f59b4e54b823d69179aed8981331da942d6500..e1fbef52702080f423187f5a41608758b65a784b 100755 (executable)
@@ -196,10 +196,12 @@ for vpath in simple long absolute; do
     # expected to be skipped (which ones exactly depends on the system),
     # thus causing the test directory not to be removed when the script
     # terminates.
-    case $keep_testdirs,$r0,$r1 in
-      ,ok,ok) rm_rf_ $depmode-$vpath.d;;
-      *) : For lesser shells with broken 'set -e';;
-    esac
+    if not am_keeping_testdirs && test "$r0,$r1" = ok,ok; then
+      rm_rf_ $depmode-$vpath.d \
+        || fatal_ "removing directory \`$depmode-$vpath.d'"
+    else
+      : For lesser shells with broken 'set -e'.
+    fi
 
   done
 done
index 6f819efbc14cc979593130d8804c728ed4250cae..5486346caa665c6d17976350f616a288f0d2b906 100755 (executable)
@@ -223,7 +223,7 @@ if test $# -gt 0; then
   unset n
 else
   test_names_list=$all_test_names_list
-  # Prefer static TAP plan if possible, minimizes the chance of errors.
+  # Prefer static TAP plan if possible, it minimizes the chance of errors.
   plan_ 94
 fi
 
@@ -295,10 +295,11 @@ for test_name in $test_names_list; do
     # with a too big test directory.  This is especially important since
     # some tests in this tests are expected to fail, and this will cause
     # the test directory not to be removed when the script terminates.
-    case $keep_testdirs,$r1 in
-      ,ok) rm_rf_ $depmode-$vpath.d;;
-        *) : For lesser shells with broken 'set -e';;
-    esac
+    if not am_keeping_testdirs && test "$r" = ok; then
+      rm_rf_ "$build" "$dest" || fatal_ "removing temporary subdirectory"
+    else
+      : For lesser shells with broken 'set -e'.
+    fi
 
   done # $instspc_action