Discussion:
init.sh: add option to preserve temporary files
(too old to reply)
Bruno Haible
2016-12-15 21:24:53 UTC
Permalink
Raw Message
Hi,

init.sh is used in the GNU gettext test suite, and I frequently have the need
to inspect temporary files after a test failure (or even after an unexpected
test pass). Therefore here's a proposed patch that introduces an option to do
this.


2016-12-15 Bruno Haible <***@clisp.org>

init.sh: Add possibility to not delete temporary files.
* tests/init.sh (remove_tmp_): If the environment variable KEEP is set to yes,
don't erase the temporary directory.

diff --git a/tests/init.sh b/tests/init.sh
index da743c2..d780110 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -45,6 +45,9 @@
# Running a single test, with verbose output:
# $ make check TESTS=test-foo.sh VERBOSE=yes
#
+# Running a single test, keeping the temporary directory:
+# $ make check TESTS=test-foo.sh KEEP=yes
+#
# Running a single test, with single-stepping:
# 1. Go into a sub-shell:
# $ bash
@@ -349,11 +352,15 @@ remove_tmp_ ()
{
__st=$?
cleanup_
- # cd out of the directory we're about to remove
- cd "$initial_cwd_" || cd / || cd /tmp
- chmod -R u+rwx "$test_dir_"
- # If removal fails and exit status was to be 0, then change it to 1.
- rm -rf "$test_dir_" || { test $__st = 0 && __st=1; }
+ if test "$KEEP" = yes; then
+ echo "Not removing temporary directory $test_dir_"
+ else
+ # cd out of the directory we're about to remove
+ cd "$initial_cwd_" || cd / || cd /tmp
+ chmod -R u+rwx "$test_dir_"
+ # If removal fails and exit status was to be 0, then change it to 1.
+ rm -rf "$test_dir_" || { test $__st = 0 && __st=1; }
+ fi
exit $__st
}
Paul Eggert
2016-12-16 18:06:24 UTC
Permalink
Raw Message
Looks good to me.

Ordinarily I would just install innocuous changes like that...
Bruno Haible
2016-12-16 18:26:20 UTC
Permalink
Raw Message
Post by Paul Eggert
Looks good to me.
OK, pushed.
Post by Paul Eggert
Ordinarily I would just install innocuous changes like that...
Well, I learned to believe in code review. And especially when I feel too
self-confident, I make the biggest blunders.

Bruno

Loading...