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 9720840DDC9 for ; Sun, 14 Nov 2010 13:54:54 -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 B8M0rVVqMv-0 for ; Sun, 14 Nov 2010 13:54:42 -0800 (PST) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by olra.theworths.org (Postfix) with ESMTP id B81C440DDF7 for ; Sun, 14 Nov 2010 13:54:41 -0800 (PST) Received: from localhost (unknown [192.168.200.4]) by max.feld.cvut.cz (Postfix) with ESMTP id 175533CFE74; Sun, 14 Nov 2010 22:54:41 +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 o6lj5FZRmmI4; Sun, 14 Nov 2010 22:54:39 +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 6FA0F19F331D; Sun, 14 Nov 2010 22:54:39 +0100 (CET) Received: from steelpick.2x.cz (unknown [213.29.198.144]) (Authenticated sender: sojkam1) by imap.feld.cvut.cz (Postfix) with ESMTPSA id 51E4DFA004; Sun, 14 Nov 2010 22:54:39 +0100 (CET) Received: from wsh by steelpick.2x.cz with local (Exim 4.72) (envelope-from ) id 1PHkX0-0002Oy-W7; Sun, 14 Nov 2010 22:54:39 +0100 From: Michal Sojka To: notmuch@notmuchmail.org Subject: [PATCH 1/5] test: Better handling of stdout and stderr Date: Sun, 14 Nov 2010 22:54:28 +0100 Message-Id: <1289771672-9204-1-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <87hbfjr2sr.fsf@steelpick.2x.cz> References: <87hbfjr2sr.fsf@steelpick.2x.cz> 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, 14 Nov 2010 21:54:54 -0000 Git-style tests (test_expect_success etc.) suppress stdout and stderr unless -v is given. Notmuch-style tests (created by test_begin_subtest and test_expect_equal) do not have this behavior so implement it the same. Additionally, for both test styles, the test-lib.sh is changed so that the content of suppressed stdout and stderr is shown in case of failed test. Finally a test for this functionality is added to basic tests. --- test/basic | 21 ++++++++++++++++++++- test/test-lib.sh | 21 +++++++++++++++------ test/test-verbose | 27 +++++++++++++++++++++++++++ test/test.expected-output/test-verbose-no | 20 ++++++++++++++++++++ test/test.expected-output/test-verbose-yes | 24 ++++++++++++++++++++++++ 5 files changed, 106 insertions(+), 7 deletions(-) create mode 100755 test/test-verbose create mode 100644 test/test.expected-output/test-verbose-no create mode 100644 test/test.expected-output/test-verbose-yes diff --git a/test/basic b/test/basic index 725c753..309779c 100755 --- a/test/basic +++ b/test/basic @@ -52,9 +52,28 @@ test_expect_code 2 'failure to clean up causes the test to fail' ' # Ensure that all tests are being run test_begin_subtest 'Ensure that all available tests will be run by notmuch-test' tests_in_suite=$(grep TESTS= ../notmuch-test | sed -e "s/TESTS=\"\(.*\)\"/\1/" | tr " " "\n" | sort) -available=$(ls -1 ../ | grep -v -E "^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test|README|test-lib.sh|test-results|tmp.*|valgrind|corpus*|emacs.expected-output|smtp-dummy|smtp-dummy.c)" | sort) +available=$(ls -1 ../ | grep -v -E "^(aggregate-results.sh|Makefile|Makefile.local|notmuch-test|README|test-lib.sh|test-results|tmp.*|valgrind|corpus*|emacs.expected-output|smtp-dummy|smtp-dummy.c|test-verbose|test.expected-output)" | sort) test_expect_equal "$tests_in_suite" "$available" +EXPECTED=../test.expected-output +suppress_diff_date() { + sed -e 's/\(.*\-\-\- test-verbose\.4\.\expected\).*/\1/' \ + -e 's/\(.*\+\+\+ test-verbose\.4\.\output\).*/\1/' +} + +test_begin_subtest "Ensure that test output is suppressed unless the test fails" +output=$(cd ..; ./test-verbose 2>&1 | suppress_diff_date) +expected=$(cat $EXPECTED/test-verbose-no | suppress_diff_date) +test_expect_equal "$output" "$expected" + +test_begin_subtest "Ensure that -v does not suppress test output" +output=$(cd ..; ./test-verbose -v 2>&1 | suppress_diff_date) +expected=$(cat $EXPECTED/test-verbose-yes | suppress_diff_date) +# Do not include the results of test-verbose in totals +rm $TEST_DIRECTORY/test-results/test-verbose-* +test_expect_equal "$output" "$expected" + + ################################################################ # Test mail store prepared in test-lib.sh diff --git a/test/test-lib.sh b/test/test-lib.sh index 418eaa7..68c9cf8 100644 --- a/test/test-lib.sh +++ b/test/test-lib.sh @@ -165,12 +165,6 @@ fi echo $(basename "$0"): "Testing ${test_description}" exec 5>&1 -if test "$verbose" = "t" -then - exec 4>&2 3>&1 -else - exec 4>/dev/null 3>/dev/null -fi test_failure=0 test_count=0 @@ -403,6 +397,11 @@ add_email_corpus () test_begin_subtest () { test_subtest_name="$1" + # Remember stdout and stderr file descriptios and redirect test + # output to the previously prepared file descriptors 3 and 4 (see + # bellow) + if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi + exec 6>&1 7>&2 >&3 2>&4 } # Pass test if two arguments match @@ -413,6 +412,7 @@ test_begin_subtest () # name. test_expect_equal () { + exec 1>&6 2>&7 # Restore stdout and stderr test "$#" = 3 && { prereq=$1; shift; } || prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test_expect_equal" @@ -508,6 +508,7 @@ test_failure_ () { echo " $1" shift echo "$@" | sed -e 's/^/ /' + if test "$verbose" != "t"; then cat test.output; fi test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; } } @@ -529,6 +530,7 @@ test_debug () { test_run_ () { test_cleanup=: + if test "$verbose" != "t"; then exec 4>test.output 3>&4; fi eval >&3 2>&4 "$1" eval_ret=$? eval >&3 2>&4 "$test_cleanup" @@ -918,6 +920,13 @@ EOF # in subprocesses like git equals our $PWD (for pathname comparisons). cd -P "$test" || error "Cannot setup test environment" +if test "$verbose" = "t" +then + exec 4>&2 3>&1 +else + exec 4>test.output 3>&4 +fi + this_test=${0##*/} for skp in $NOTMUCH_SKIP_TESTS do diff --git a/test/test-verbose b/test/test-verbose new file mode 100755 index 0000000..f29a9c7 --- /dev/null +++ b/test/test-verbose @@ -0,0 +1,27 @@ +#!/bin/bash + +test_description='the verbosity options of the test framework itself.' + +. ./test-lib.sh + +test_expect_success 'print something in test_expect_success and pass' ' + echo "hello stdout" && + echo "hello stderr" >&2 && + true +' +test_expect_success 'print something in test_expect_success and fail' ' + echo "hello stdout" && + echo "hello stderr" >&2 && + false +' +test_begin_subtest 'print something between test_begin_subtest and test_expect_equal and pass' +echo "hello stdout" +echo "hello stderr" >&2 +test_expect_equal "a" "a" + +test_begin_subtest 'print something test_begin_subtest and test_expect_equal and fail' +echo "hello stdout" +echo "hello stderr" >&2 +test_expect_equal "a" "b" + +test_done diff --git a/test/test.expected-output/test-verbose-no b/test/test.expected-output/test-verbose-no new file mode 100644 index 0000000..0bca754 --- /dev/null +++ b/test/test.expected-output/test-verbose-no @@ -0,0 +1,20 @@ +test-verbose: Testing the verbosity options of the test framework itself. + PASS print something in test_expect_success and pass + FAIL print something in test_expect_success and fail + + echo "hello stdout" && + echo "hello stderr" >&2 && + false + +hello stdout +hello stderr + PASS print something between test_begin_subtest and test_expect_equal and pass + FAIL print something test_begin_subtest and test_expect_equal and fail + --- test-verbose.4.expected 2010-11-14 21:41:12.738189710 +0000 + +++ test-verbose.4.output 2010-11-14 21:41:12.738189710 +0000 + @@ -1 +1 @@ + -b + +a +hello stdout +hello stderr + diff --git a/test/test.expected-output/test-verbose-yes b/test/test.expected-output/test-verbose-yes new file mode 100644 index 0000000..ebe5187 --- /dev/null +++ b/test/test.expected-output/test-verbose-yes @@ -0,0 +1,24 @@ +test-verbose: Testing the verbosity options of the test framework itself. +hello stdout +hello stderr + PASS print something in test_expect_success and pass +hello stdout +hello stderr + FAIL print something in test_expect_success and fail + + echo "hello stdout" && + echo "hello stderr" >&2 && + false + +hello stdout +hello stderr + PASS print something between test_begin_subtest and test_expect_equal and pass +hello stdout +hello stderr + FAIL print something test_begin_subtest and test_expect_equal and fail + --- test-verbose.4.expected 2010-11-14 21:41:06.650023289 +0000 + +++ test-verbose.4.output 2010-11-14 21:41:06.650023289 +0000 + @@ -1 +1 @@ + -b + +a + -- 1.7.2.3