automake-patches
[Top][All Lists]
Advanced

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

[FYI] {micro} tests: use perl, not find+rm, to remove temporary director


From: Stefano Lattarini
Subject: [FYI] {micro} tests: use perl, not find+rm, to remove temporary directories
Date: Thu, 16 May 2013 16:27:20 +0200

The File::Path::rmtree function from perl, if used right, is
more reliable and more portable of our past idiom:

    find $dirs -type d ! -perm -700 -exec chmod u+rwx {} ';';
    rm -rf $$dirs || exit 1

at least of the face of unreadable dirs/files and other similar
permission issues (and we have those in our test directories).

In fact, this change fixes some spurious failures seen in
"make distcheck" on Solaris 10.

* t/ax/deltree.pl: New.
* Makefile.am (EXTRA_DIST): Add it.
(clean-local-check): Use it.
* t/ax/test-lib.sh (rm_rf_): Use it.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 Makefile.am      | 13 ++-----------
 t/ax/deltree.pl  | 19 +++++++++++++++++++
 t/ax/test-lib.sh |  5 +----
 3 files changed, 22 insertions(+), 15 deletions(-)
 create mode 100644 t/ax/deltree.pl

diff --git a/Makefile.am b/Makefile.am
index 0b337f1..602d8ee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -337,7 +337,7 @@ TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' $(SHELL) 
$(srcdir)/lib/tap-driver.sh
 
 AM_TAP_LOG_DRIVER_FLAGS = --merge
 
-EXTRA_DIST += t/README t/ax/is t/ax/is_newest
+EXTRA_DIST += t/README t/ax/is t/ax/is_newest t/ax/deltree.pl
 
 ## Will be updated later.
 TESTS =
@@ -545,16 +545,7 @@ EXTRA_DIST += $(perf_TESTS)
 clean-local: clean-local-check
 .PHONY: clean-local-check
 clean-local-check:
-## Directories candidate to be test directories match this wildcard.
-       @globs='t/*.dir t/*/*.dir */t/*.dir */t/*/*.dir'; \
-## The 'nullglob' bash option is not portable, so use perl.
-       dirs=`$(PERL) -e "print join(' ', glob('$$globs'));"` || exit 1; \
-       if test -n "$$dirs"; then \
-## Errors in find are acceptable, errors in rm are not.
-           find $$dirs -type d ! -perm -700 -exec chmod u+rwx {} ';'; \
-           echo " rm -rf $$dirs"; \
-           rm -rf $$dirs || exit 1; \
-       fi
+       $(AM_V_GEN)$(PERL) $(srcdir)/t/ax/deltree.pl t/*.dir t/*/*.dir */t/*.dir
 
 
 ## ---------------- ##
diff --git a/t/ax/deltree.pl b/t/ax/deltree.pl
new file mode 100644
index 0000000..7060766
--- /dev/null
+++ b/t/ax/deltree.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+# deltree: recursively removes file and directory,
+# trying to handle permissions and other complications.
+
+use strict;
+use warnings FATAL => 'all';
+use File::Path qw/rmtree/;
+
+my $exit_status = 0;
+local $SIG{__WARN__} = sub { warn "@_"; $exit_status = 1; };
+
+foreach my $path (@ARGV) {
+  local $@ = undef;
+  rmtree ($path);
+}
+
+exit $exit_status;
+
+# vim: ft=perl ts=4 sw=4 et
diff --git a/t/ax/test-lib.sh b/t/ax/test-lib.sh
index a3c16ee..5be0cec 100644
--- a/t/ax/test-lib.sh
+++ b/t/ax/test-lib.sh
@@ -174,10 +174,7 @@ seq_ ()
 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 "$@"
+  $PERL "$am_testaux_srcdir"/deltree.pl "$@"
 }
 
 commented_sed_unindent_prog='
-- 
1.8.3.rc2




reply via email to

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