--- /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 F3DE9431FB6\r
+ for <notmuch@notmuchmail.org>; Sun, 21 Sep 2014 11:06:51 -0700 (PDT)\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 n0cDvN-HYJ84 for <notmuch@notmuchmail.org>;\r
+ Sun, 21 Sep 2014 11:06:45 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id A1A26431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 21 Sep 2014 11:06:45 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id 9B5FD1000C0; Sun, 21 Sep 2014 21:06:25 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] test: prepare test-lib.sh for possible test system debug\r
+ session\r
+Date: Sun, 21 Sep 2014 21:06:20 +0300\r
+Message-Id: <1411322780-11374-1-git-send-email-tomi.ollila@iki.fi>\r
+X-Mailer: git-send-email 2.0.0\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: Sun, 21 Sep 2014 18:06:52 -0000\r
+\r
+When something in tests fails one possibility to test is to run\r
+the test script as `bash -x TXXX-testname.sh`. As stderr (fd 2) was\r
+redirected to separate file during test execution also this set -x\r
+(xtrace) output would also go there.\r
+test-lib.sh saves the stderr to fd 7 from where it can be restored,\r
+and bash has BASH_XTRACEFD variable, which is now given the same value\r
+7, making bash to output all xtrade information (consistently) there.\r
+\r
+This lib file used to save fd's 1 & 2 to 6 & 7 (respectively) in\r
+test_begin_subtest(), but as those needs to be set *before* XTRACEFD\r
+variable is set those are now saved at the beginning of the lib (once).\r
+This is safe and simple thing to do.\r
+To make xtrace output more verbose PS4 variable was set to contain the\r
+source file, line number and if execution is in function, that function\r
+name. Setting this variable has no effect when not xtracing.\r
+\r
+As it is known that fd 6 is redirected stdout, printing status can now\r
+use that fd, instead of saving stdout to fd 5 and use it.\r
+---\r
+ test/test-lib-common.sh | 2 +-\r
+ test/test-lib.sh | 21 ++++++++++++---------\r
+ 2 files changed, 13 insertions(+), 10 deletions(-)\r
+\r
+diff --git a/test/test-lib-common.sh b/test/test-lib-common.sh\r
+index 4903038dd9ce..f99ed11162ad 100644\r
+--- a/test/test-lib-common.sh\r
++++ b/test/test-lib-common.sh\r
+@@ -122,7 +122,7 @@ esac\r
+ test ! -z "$debug" || remove_tmp=$TMP_DIRECTORY\r
+ rm -fr "$test" || {\r
+ GIT_EXIT_OK=t\r
+- echo >&5 "FATAL: Cannot prepare test area"\r
++ echo >&6 "FATAL: Cannot prepare test area"\r
+ exit 1\r
+ }\r
+ \r
+diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+index b9b8fe8ca6ad..4c76fbb52c24 100644\r
+--- a/test/test-lib.sh\r
++++ b/test/test-lib.sh\r
+@@ -45,6 +45,12 @@ done,*)\r
+ ;;\r
+ esac\r
+ \r
++# Save STDOUT to fd 6 and STDERR to fd 7.\r
++exec 6>&1 7>&2\r
++# Make xtrace debugging (when used) use redirected STDERR, with verbose lead:\r
++BASH_XTRACEFD=7\r
++export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'\r
++\r
+ # Keep the original TERM for say_color and test_emacs\r
+ ORIGINAL_TERM=$TERM\r
+ \r
+@@ -204,8 +210,6 @@ then\r
+ print_test_description\r
+ fi\r
+ \r
+-exec 5>&1\r
+-\r
+ test_failure=0\r
+ test_count=0\r
+ test_fixed=0\r
+@@ -225,7 +229,7 @@ die () {\r
+ then\r
+ exit $code\r
+ else\r
+- exec >&5\r
++ exec >&6\r
+ say_color error '%-6s' FATAL\r
+ echo " $test_subtest_name"\r
+ echo\r
+@@ -236,7 +240,7 @@ die () {\r
+ \r
+ die_signal () {\r
+ _die_common\r
+- echo >&5 "FATAL: $0: interrupted by signal" $((code - 128))\r
++ echo >&6 "FATAL: $0: interrupted by signal" $((code - 128))\r
+ exit $code\r
+ }\r
+ \r
+@@ -544,11 +548,10 @@ test_begin_subtest ()\r
+ fi\r
+ test_subtest_name="$1"\r
+ test_reset_state_\r
+- # Remember stdout and stderr file descriptors and redirect test\r
+- # output to the previously prepared file descriptors 3 and 4 (see\r
+- # below)\r
++ # Redirect test output to the previously prepared file descriptors\r
++ # 3 and 4 (see below)\r
+ if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi\r
+- exec 6>&1 7>&2 >&3 2>&4\r
++ exec >&3 2>&4\r
+ inside_subtest=t\r
+ }\r
+ \r
+@@ -938,7 +941,7 @@ test_expect_code () {\r
+ 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
++ error >&6 "bug in the test script: not 3 or 4 parameters to test_external"\r
+ test_subtest_name="$1"\r
+ shift\r
+ test_reset_state_\r
+-- \r
+2.0.0\r
+\r