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 C38C7429E48 for ; Wed, 25 May 2011 18:01:36 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.921 X-Spam-Level: X-Spam-Status: No, score=-1.921 tagged_above=-999 required=5 tests=[NO_DNS_FOR_FROM=0.379, RCVD_IN_DNSWL_MED=-2.3] 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 4gAXbaVRWJTJ for ; Wed, 25 May 2011 18:01:36 -0700 (PDT) Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu [131.215.239.19]) by olra.theworths.org (Postfix) with ESMTP id 3F176429E30 for ; Wed, 25 May 2011 18:01:34 -0700 (PDT) Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1]) by fire-doxen-postvirus (Postfix) with ESMTP id DEEB53282D2; Wed, 25 May 2011 17:55:18 -0700 (PDT) X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new Received: from servo.finestructure.net (gwave-104.ligo.caltech.edu [131.215.114.104]) (Authenticated sender: jrollins) by fire-doxen-submit (Postfix) with ESMTP id 2721F3282C8; Wed, 25 May 2011 17:55:13 -0700 (PDT) Received: by servo.finestructure.net (Postfix, from userid 1000) id 78AFE7C5; Wed, 25 May 2011 18:01:26 -0700 (PDT) From: Jameson Graef Rollins To: notmuch@notmuchmail.org Subject: [PATCH 05/11] test: new test-lib function to test for equality between files Date: Wed, 25 May 2011 18:01:14 -0700 Message-Id: <1306371680-19441-6-git-send-email-jrollins@finestructure.net> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1306371680-19441-1-git-send-email-jrollins@finestructure.net> References: <1306371680-19441-1-git-send-email-jrollins@finestructure.net> 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: Thu, 26 May 2011 01:01:37 -0000 We need to be able to test for the presence of a newline at the end of output. There's no good way to capture trailing newlines in bash, so redirecting output to a file is the next best thing. This new function should be used when testing for output that is expected to have trailing newlines. The next commit will demonstrate the use of this. --- test/test-lib.sh | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/test/test-lib.sh b/test/test-lib.sh index f536172..9e2e0b5 100755 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -441,6 +441,29 @@ test_expect_equal () fi } +test_expect_equal_file () +{ + exec 1>&6 2>&7 # Restore stdout and stderr + inside_subtest= + test "$#" = 3 && { prereq=$1; shift; } || prereq= + test "$#" = 2 || + error "bug in the test script: not 2 or 3 parameters to test_expect_equal" + + output="$1" + expected="$2" + if ! test_skip "$@" + then + if diff -q "$expected" "$output" >/dev/null ; then + test_ok_ "$test_subtest_name" + else + testname=$this_test.$test_count + mv "$output" $testname.output + mv "$expected" $testname.expected + test_failure_ "$test_subtest_name" "$(diff -u $testname.expected $testname.output)" + fi + fi +} + test_expect_equal_failure () { exec 1>&6 2>&7 # Restore stdout and stderr -- 1.7.4.4