unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...()
@ 2016-05-28 12:39 Tomi Ollila
  2016-05-28 12:39 ` [PATCH v2 2/3] test: add function die () and have use of it in add_email_corpus () Tomi Ollila
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Tomi Ollila @ 2016-05-28 12:39 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

Now the function names more accurately describes what the functions do.
---

V2 of id:1460525704-15145-1-git-send-email-tomi.ollila@iki.fi

Thanks to David's review this series (or this first patch)
is so much better.

 test/test-lib.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index 201d0ebb94bb..fa9f9beec4f2 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -223,15 +223,15 @@ test_fixed=0
 test_broken=0
 test_success=0
 
-_die_common () {
+_exit_common () {
 	code=$?
 	trap - EXIT
 	set +ex
 	rm -rf "$TEST_TMPDIR"
 }
 
-die () {
-	_die_common
+trap_exit () {
+	_exit_common
 	if test -n "$GIT_EXIT_OK"
 	then
 		exit $code
@@ -245,8 +245,8 @@ die () {
 	fi
 }
 
-die_signal () {
-	_die_common
+trap_signal () {
+	_exit_common
 	echo >&6 "FATAL: $0: interrupted by signal" $((code - 128))
 	exit $code
 }
@@ -254,8 +254,8 @@ die_signal () {
 GIT_EXIT_OK=
 # Note: TEST_TMPDIR *NOT* exported!
 TEST_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/notmuch-test-$$.XXXXXX")
-trap 'die' EXIT
-trap 'die_signal' HUP INT TERM
+trap 'trap_exit' EXIT
+trap 'trap_signal' HUP INT TERM
 
 test_decode_color () {
 	sed	-e 's/.\[1m/<WHITE>/g' \
-- 
2.8.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] test: add function die () and have use of it in add_email_corpus ()
  2016-05-28 12:39 [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...() Tomi Ollila
@ 2016-05-28 12:39 ` Tomi Ollila
  2016-05-28 12:39 ` [PATCH v2 3/3] test: fix die() in test-lib-common.sh Tomi Ollila
  2016-06-11 16:24 ` [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...() David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: Tomi Ollila @ 2016-05-28 12:39 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

Added die() function to test-lib.sh with the following first use of it:

If notmuch new fails during email corpus addition the database is
most probably inexistent or broken and the added corpus would be
unusable while running single tests, giving misleading failures
("only" full 'make test' cleans out old corpus).
---
 test/test-lib.sh | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/test/test-lib.sh b/test/test-lib.sh
index fa9f9beec4f2..ce3780a0426d 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -251,6 +251,16 @@ trap_signal () {
 	exit $code
 }
 
+die () {
+	_exit_common
+	exec >&6
+	say_color error '%-6s' FATAL
+	echo " $*"
+	echo
+	echo "Unexpected exit while executing $0."
+	exit 1
+}
+
 GIT_EXIT_OK=
 # Note: TEST_TMPDIR *NOT* exported!
 TEST_TMPDIR=$(mktemp -d "${TMPDIR:-/tmp}/notmuch-test-$$.XXXXXX")
@@ -544,7 +554,7 @@ add_email_corpus ()
 	cp -a $TEST_DIRECTORY/corpus.mail ${MAIL_DIR}
     else
 	cp -a $TEST_DIRECTORY/corpus ${MAIL_DIR}
-	notmuch new >/dev/null
+	notmuch new >/dev/null || die "'notmuch new' failed while adding email corpus"
 	cp -a ${MAIL_DIR} $TEST_DIRECTORY/corpus.mail
     fi
 }
-- 
2.8.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] test: fix die() in test-lib-common.sh
  2016-05-28 12:39 [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...() Tomi Ollila
  2016-05-28 12:39 ` [PATCH v2 2/3] test: add function die () and have use of it in add_email_corpus () Tomi Ollila
@ 2016-05-28 12:39 ` Tomi Ollila
  2016-06-11 16:24 ` [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...() David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: Tomi Ollila @ 2016-05-28 12:39 UTC (permalink / raw)
  To: notmuch; +Cc: tomi.ollila

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 ++++++
 1 file changed, 6 insertions(+)

diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh
index ba4a8e112084..bc2322162fd5 100644
--- a/test/test-lib-common.sh
+++ b/test/test-lib-common.sh
@@ -18,6 +18,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"
-- 
2.8.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...()
  2016-05-28 12:39 [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...() Tomi Ollila
  2016-05-28 12:39 ` [PATCH v2 2/3] test: add function die () and have use of it in add_email_corpus () Tomi Ollila
  2016-05-28 12:39 ` [PATCH v2 3/3] test: fix die() in test-lib-common.sh Tomi Ollila
@ 2016-06-11 16:24 ` David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2016-06-11 16:24 UTC (permalink / raw)
  To: Tomi Ollila, notmuch; +Cc: tomi.ollila

Tomi Ollila <tomi.ollila@iki.fi> writes:

> Now the function names more accurately describes what the functions do.
> ---
>
> V2 of id:1460525704-15145-1-git-send-email-tomi.ollila@iki.fi
>
> Thanks to David's review this series (or this first patch)
> is so much better.
>

Not sure if sarcastic, but pushed the series anyway.

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-06-11 16:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-28 12:39 [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...() Tomi Ollila
2016-05-28 12:39 ` [PATCH v2 2/3] test: add function die () and have use of it in add_email_corpus () Tomi Ollila
2016-05-28 12:39 ` [PATCH v2 3/3] test: fix die() in test-lib-common.sh Tomi Ollila
2016-06-11 16:24 ` [PATCH v2 1/3] test-lib.sh: renamed die...()s to trap...()s and exit...() David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).