[PATCH] test: fix die() in test-lib.sh and test-lib-common.sh

Tomi Ollila tomi.ollila at iki.fi
Fri Apr 15 05:17:33 PDT 2016


Restoring fd was forgotten in die() implemented in test-lib.sh
(so far it did not matter as the only place die was called the
standard fd redirections were not in effect).

In scripts that include test-lib-common.sh but not test-lib.sh
the die() implementation needs to be a bit different due to
fd redirection differences. test-lib-common.sh implements die()
only if it was not implemented already.
---
 test/test-lib-common.sh | 6 ++++++
 test/test-lib.sh        | 1 +
 2 files changed, 7 insertions(+)

diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh
index 4e17b78..f3b00d8 100644
--- a/test/test-lib-common.sh
+++ b/test/test-lib-common.sh
@@ -17,6 +17,12 @@
 # This file contains common code to be used by both the regular
 # (correctness) tests and the performance tests.
 
+# test-lib.sh defines die() which echoes to nonstandard fd where
+# output was redirected earlier in that file. If test-lib.sh is not
+# loaded, neither this redirection nor die() function were defined.
+#
+type die >/dev/null 2>&1 || die () { echo "$@" >&2; exit 1; }
+
 find_notmuch_path ()
 {
     dir="$1"
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 2951a8f..b000232 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -252,6 +252,7 @@ die_signal () {
 
 die () {
 	_die_common
+	exec >&6
 	say_color error '%-6s' FATAL
 	echo " $*"
 	echo
-- 
2.5.5



More information about the notmuch mailing list