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 D373040DF1D for ; Sun, 21 Nov 2010 04:08:28 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] autolearn=ham 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 8UQWKIisO9yL for ; Sun, 21 Nov 2010 04:08:18 -0800 (PST) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by olra.theworths.org (Postfix) with ESMTP id 312B440DF1C for ; Sun, 21 Nov 2010 04:08:18 -0800 (PST) Received: from localhost (unknown [192.168.200.4]) by max.feld.cvut.cz (Postfix) with ESMTP id 2344719F3340; Sun, 21 Nov 2010 13:08:17 +0100 (CET) X-Virus-Scanned: IMAP AMAVIS Received: from max.feld.cvut.cz ([192.168.200.1]) by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new, port 10044) with ESMTP id p+QNtAy490Gi; Sun, 21 Nov 2010 13:08:15 +0100 (CET) Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) by max.feld.cvut.cz (Postfix) with ESMTP id E417919F30E1; Sun, 21 Nov 2010 13:08:15 +0100 (CET) Received: from wsheee.2x.cz (unknown [213.29.198.144]) (Authenticated sender: sojkam1) by imap.feld.cvut.cz (Postfix) with ESMTPSA id A395FFA003; Sun, 21 Nov 2010 13:08:14 +0100 (CET) Received: from wsh by wsheee.2x.cz with local (Exim 4.72) (envelope-from ) id 1PK8iM-0004K4-81; Sun, 21 Nov 2010 13:08:14 +0100 From: Michal Sojka To: notmuch@notmuchmail.org Subject: [PATCH] test: Detect when some command unexpectedly fails Date: Sun, 21 Nov 2010 13:08:12 +0100 Message-Id: <1290341292-16589-1-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 1.7.1.90.g94d6d4 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 Nov 2010 12:08:29 -0000 When some command in between test_begin_subtest and test_expect_equal fails, the test suite does not detect it unless the failure leads to difference in the strings compared by test_expect_equal. This patch sets shell -e option which switches on the detection of failed commands (thise with non-zero exit status). If some command fails the test script exits with exit code of 1 and prints the failed command. It might be better to print the line number of the failed command but it seems that inside traps, the BASH_LINENO variable does not contain the wanted information. --- test/raw | 2 +- test/test-lib.sh | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/raw b/test/raw index 4ed237c..87e18b1 100755 --- a/test/raw +++ b/test/raw @@ -10,7 +10,7 @@ output=$(NOTMUCH_NEW) test_expect_equal "$output" "Added 2 new messages to the database." test_begin_subtest "Attempt to show multiple raw messages" -output=$(notmuch show --format=raw "*" 2>&1) +output=$(notmuch show --format=raw "*" 2>&1 || :) test_expect_equal "$output" "Error: search term did not match precisely one message." test_begin_subtest "Show a raw message" diff --git a/test/test-lib.sh b/test/test-lib.sh index 04a4c14..1ad0da6 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -178,7 +178,7 @@ die () { then exit $code else - echo >&5 "FATAL: Unexpected exit with code $code" + echo >&5 "FATAL: Unexpected exit with code $code: $BASH_COMMAND" exit 1 fi } @@ -407,6 +407,7 @@ test_begin_subtest () if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi exec 6>&1 7>&2 >&3 2>&4 inside_subtest=t + set -e } # Pass test if two arguments match @@ -418,6 +419,7 @@ test_begin_subtest () test_expect_equal () { exec 1>&6 2>&7 # Restore stdout and stderr + set +e inside_subtest= test "$#" = 3 && { prereq=$1; shift; } || prereq= test "$#" = 2 || @@ -440,6 +442,7 @@ test_expect_equal () test_expect_equal_failure () { + set +e test "$#" = 3 && { prereq=$1; shift; } || prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_equal" -- 1.7.1.90.g94d6d4