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