--- /dev/null
+Return-Path: <too@guru-group.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 5129D431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 20 Jan 2013 19:02:03 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id XUsXVkNrAHZ9 for <notmuch@notmuchmail.org>;\r
+ Sun, 20 Jan 2013 19:02:01 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 4E70A431FAF\r
+ for <notmuch@notmuchmail.org>; Sun, 20 Jan 2013 19:02:01 -0800 (PST)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id EF1E7100093; Mon, 21 Jan 2013 05:01:47 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] test/test-lib.sh: use $test_subtest_name in all tests\r
+Date: Mon, 21 Jan 2013 05:01:45 +0200\r
+Message-Id: <1358737306-21744-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 1.8.0\r
+In-Reply-To: <id:1358717493-11231-1-git-send-email-tomi.ollila@iki.fi>\r
+References: <id:1358717493-11231-1-git-send-email-tomi.ollila@iki.fi>\r
+Cc: tomi.ollila@iki.fi\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 21 Jan 2013 03:02:03 -0000\r
+\r
+Set the variable '$test_subtest_name' in all functions which starts\r
+a new test and use that variable in all functions that output\r
+test results.\r
+\r
+Additionally output the latest '$test_subtest_name' in case of\r
+abnormal exit, to avoid confusion.\r
+---\r
+\r
+This obsoletes id:1358717806-11376-1-git-send-email-tomi.ollila@iki.fi\r
+which had fd:s in function 'die' wrong order in 'exec [1]>&5' line.\r
+I did plenty of (ad hoc) hand-testing for this but failed to notice that\r
+messages weren't always as verbose as those should have been. The wip\r
+patch set mentioned below has it right but this was hand-rewritten as\r
+this is somewhat different here...\r
+\r
+The main reason to do this change is to get latest '$test_subtest_name'\r
+printed in case of abnormal exit. I cherry-picked this change from a\r
+larger work-in-progress patch set that adds 'set -e -o pipefail' support...\r
+\r
+I am pretty sure I got all the cases covered. If not, we'll notice\r
+it later when some test fail in a way I could not anticipate.\r
+Anyway, tests success & fail as they used to be.\r
+\r
+ test/test-lib.sh | 52 +++++++++++++++++++++++++++++-----------------------\r
+ 1 file changed, 29 insertions(+), 23 deletions(-)\r
+\r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index 6ce3b31..0098bfd 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -197,7 +197,11 @@ die () {\r
+ then\r
+ exit $code\r
+ else\r
+- echo >&5 "FATAL: Unexpected exit with code $code"\r
++ exec >&5\r
++ say_color error '%-6s' FATAL\r
++ echo " $test_subtest_name"\r
++ echo\r
++ echo "Unexpected exit while executing $0. Exit code $code."\r
+ exit 1\r
+ fi\r
+ }\r
+@@ -494,12 +498,12 @@ test_expect_equal ()\r
+ if ! test_skip "$test_subtest_name"\r
+ then\r
+ if [ "$output" = "$expected" ]; then\r
+- test_ok_ "$test_subtest_name"\r
++ test_ok_\r
+ else\r
+ testname=$this_test.$test_count\r
+ echo "$expected" > $testname.expected\r
+ echo "$output" > $testname.output\r
+- test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)"\r
++ test_failure_ "$(diff -u $testname.expected $testname.output)"\r
+ fi\r
+ fi\r
+ }\r
+@@ -520,12 +524,12 @@ test_expect_equal_file ()\r
+ if ! test_skip "$test_subtest_name"\r
+ then\r
+ if diff -q "$file1" "$file2" >/dev/null ; then\r
+- test_ok_ "$test_subtest_name"\r
++ test_ok_\r
+ else\r
+ testname=$this_test.$test_count\r
+ cp "$file1" "$testname.$basename1"\r
+ cp "$file2" "$testname.$basename2"\r
+- test_failure_ "$test_subtest_name" "$(diff -u "$testname.$basename1" "$testname.$basename2")"\r
++ test_failure_ "$(diff -u "$testname.$basename1" "$testname.$basename2")"\r
+ fi\r
+ fi\r
+ }\r
+@@ -563,9 +567,9 @@ test_emacs_expect_t () {\r
+ result=$(cat OUTPUT)\r
+ if [ "$result" = t ]\r
+ then\r
+- test_ok_ "$test_subtest_name"\r
++ test_ok_\r
+ else\r
+- test_failure_ "$test_subtest_name" "${result}"\r
++ test_failure_ "${result}"\r
+ fi\r
+ else\r
+ # Restore state after the (non) test.\r
+@@ -666,12 +670,12 @@ test_require_external_prereq () {\r
+ \r
+ test_ok_ () {\r
+ if test "$test_subtest_known_broken_" = "t"; then\r
+- test_known_broken_ok_ "$@"\r
++ test_known_broken_ok_\r
+ return\r
+ fi\r
+ test_success=$(($test_success + 1))\r
+ say_color pass "%-6s" "PASS"\r
+- echo " $@"\r
++ echo " $test_subtest_name"\r
+ }\r
+ \r
+ test_failure_ () {\r
+@@ -680,7 +684,7 @@ test_failure_ () {\r
+ return\r
+ fi\r
+ test_failure=$(($test_failure + 1))\r
+- test_failure_message_ "FAIL" "$@"\r
++ test_failure_message_ "FAIL" "$test_subtest_name" "$@"\r
+ test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }\r
+ return 1\r
+ }\r
+@@ -697,13 +701,13 @@ test_known_broken_ok_ () {\r
+ test_reset_state_\r
+ test_fixed=$(($test_fixed+1))\r
+ say_color pass "%-6s" "FIXED"\r
+- echo " $@"\r
++ echo " $test_subtest_name"\r
+ }\r
+ \r
+ test_known_broken_failure_ () {\r
+ test_reset_state_\r
+ test_broken=$(($test_broken+1))\r
+- test_failure_message_ "BROKEN" "$@"\r
++ test_failure_message_ "BROKEN" "$test_subtest_name" "$@"\r
+ return 1\r
+ }\r
+ \r
+@@ -771,6 +775,7 @@ test_expect_success () {\r
+ test "$#" = 3 && { prereq=$1; shift; } || prereq=\r
+ test "$#" = 2 ||\r
+ error "bug in the test script: not 2 or 3 parameters to test-expect-success"\r
++ test_subtest_name="$1"\r
+ test_reset_state_\r
+ if ! test_skip "$@"\r
+ then\r
+@@ -780,9 +785,9 @@ test_expect_success () {\r
+ test_check_missing_external_prereqs_ "$@" ||\r
+ if [ "$run_ret" = 0 -a "$eval_ret" = 0 ]\r
+ then\r
+- test_ok_ "$1"\r
++ test_ok_\r
+ else\r
+- test_failure_ "$@"\r
++ test_failure_ "$2"\r
+ fi\r
+ fi\r
+ }\r
+@@ -791,6 +796,7 @@ test_expect_code () {\r
+ test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
+ test "$#" = 3 ||\r
+ error "bug in the test script: not 3 or 4 parameters to test-expect-code"\r
++ test_subtest_name="$2"\r
+ test_reset_state_\r
+ if ! test_skip "$@"\r
+ then\r
+@@ -800,9 +806,9 @@ test_expect_code () {\r
+ test_check_missing_external_prereqs_ "$@" ||\r
+ if [ "$run_ret" = 0 -a "$eval_ret" = "$1" ]\r
+ then\r
+- test_ok_ "$2"\r
++ test_ok_\r
+ else\r
+- test_failure_ "$@"\r
++ test_failure_ "exit code $eval_ret, expected $1" "$3"\r
+ fi\r
+ fi\r
+ }\r
+@@ -819,10 +825,10 @@ test_external () {\r
+ test "$#" = 4 && { prereq=$1; shift; } || prereq=\r
+ test "$#" = 3 ||\r
+ error >&5 "bug in the test script: not 3 or 4 parameters to test_external"\r
+- descr="$1"\r
++ test_subtest_name="$1"\r
+ shift\r
+ test_reset_state_\r
+- if ! test_skip "$descr" "$@"\r
++ if ! test_skip "$test_subtest_name" "$@"\r
+ then\r
+ # Announce the script to reduce confusion about the\r
+ # test output that follows.\r
+@@ -833,9 +839,9 @@ test_external () {\r
+ "$@" 2>&4\r
+ if [ "$?" = 0 ]\r
+ then\r
+- test_ok_ "$descr"\r
++ test_ok_\r
+ else\r
+- test_failure_ "$descr" "$@"\r
++ test_failure_ "$@"\r
+ fi\r
+ fi\r
+ }\r
+@@ -849,11 +855,11 @@ test_external_without_stderr () {\r
+ stderr="$tmp/git-external-stderr.$$.tmp"\r
+ test_external "$@" 4> "$stderr"\r
+ [ -f "$stderr" ] || error "Internal error: $stderr disappeared."\r
+- descr="no stderr: $1"\r
++ test_subtest_name="no stderr: $1"\r
+ shift\r
+ if [ ! -s "$stderr" ]; then\r
+ rm "$stderr"\r
+- test_ok_ "$descr"\r
++ test_ok_\r
+ else\r
+ if [ "$verbose" = t ]; then\r
+ output=`echo; echo Stderr is:; cat "$stderr"`\r
+@@ -862,7 +868,7 @@ test_external_without_stderr () {\r
+ fi\r
+ # rm first in case test_failure exits.\r
+ rm "$stderr"\r
+- test_failure_ "$descr" "$@" "$output"\r
++ test_failure_ "$@" "$output"\r
+ fi\r
+ }\r
+ \r
+-- \r
+1.8.0\r
+\r