unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: notmuch@notmuchmail.org
Cc: tomi.ollila@iki.fi
Subject: [PATCH 3/3] test: implement and document NOTMUCH_TEST_QUIET variable usage
Date: Tue, 12 Nov 2013 22:41:08 +0200	[thread overview]
Message-ID: <1384288868-23903-3-git-send-email-tomi.ollila@iki.fi> (raw)
In-Reply-To: <1384288868-23903-1-git-send-email-tomi.ollila@iki.fi>

When NOTMUCH_TEST_QUIET environment variable is set to non-null value
messages when new test script starts and when test PASSes are disabled.
This eases picking the cases when tests FAIL (as those are still printed).
---
 test/README                                      |  8 ++++++++
 test/basic                                       | 12 ++++++++++--
 test/test-lib.sh                                 | 11 ++++++++++-
 test/test.expected-output/test-quiet-verbose-no  | 20 ++++++++++++++++++++
 test/test.expected-output/test-quiet-verbose-yes | 24 ++++++++++++++++++++++++
 5 files changed, 72 insertions(+), 3 deletions(-)
 create mode 100644 test/test.expected-output/test-quiet-verbose-no
 create mode 100644 test/test.expected-output/test-quiet-verbose-yes

diff --git a/test/README b/test/README
index d12cff2..79a9b1b 100644
--- a/test/README
+++ b/test/README
@@ -76,6 +76,14 @@ the tests in one of the following ways.
 	TEST_EMACS=my-special-emacs TEST_EMACSCLIENT=my-emacsclient ./emacs
 	make test TEST_EMACS=my-special-emacs TEST_EMACSCLIENT=my-emacsclient
 
+Quiet Execution
+---------------
+
+Normally, when new script starts and when test PASSes you get a message
+printed on screen. This printing can be disabled by setting the
+NOTMUCH_TEST_QUIET variable to a non-null value. Message on test
+failures and skips are still printed.
+
 Skipping Tests
 --------------
 If, for any reason, you need to skip one or more tests, you can do so
diff --git a/test/basic b/test/basic
index 64eb7d7..3b7668b 100755
--- a/test/basic
+++ b/test/basic
@@ -73,14 +73,22 @@ suppress_diff_date() {
 	-e 's/\(.*\+\+\+ test-verbose\.4\.\output\).*/\1/'
 }
 
+if [ -z "$NOTMUCH_TEST_QUIET" ]
+then
+	test_verbose_no=$EXPECTED/test-verbose-no
+	test_verbose_yes=$EXPECTED/test-verbose-yes
+else
+	test_verbose_no=$EXPECTED/test-quiet-verbose-no
+	test_verbose_yes=$EXPECTED/test-quiet-verbose-yes
+fi
 test_begin_subtest "Ensure that test output is suppressed unless the test fails"
 output=$(cd $TEST_DIRECTORY; ./test-verbose 2>&1 | suppress_diff_date)
-expected=$(cat $EXPECTED/test-verbose-no | suppress_diff_date)
+expected=$(cat ${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_DIRECTORY; ./test-verbose -v 2>&1 | suppress_diff_date)
-expected=$(cat $EXPECTED/test-verbose-yes | suppress_diff_date)
+expected=$(cat ${test_verbose_yes} | suppress_diff_date)
 # Do not include the results of test-verbose in totals
 rm $TEST_DIRECTORY/test-results/test-verbose
 rm -r $TEST_DIRECTORY/tmp.test-verbose
diff --git a/test/test-lib.sh b/test/test-lib.sh
index e022e46..4b342ac 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -195,7 +195,10 @@ print_test_description ()
 	echo
 	echo $this_test: "Testing ${test_description}"
 }
-print_test_description
+if [ -z "$NOTMUCH_TEST_QUIET" ]
+then
+	print_test_description
+fi
 
 exec 5>&1
 
@@ -703,6 +706,9 @@ test_ok_ () {
 		return
 	fi
 	test_success=$(($test_success + 1))
+	if test -n "$NOTMUCH_TEST_QUIET"; then
+		return 0
+	fi
 	say_color pass "%-6s" "PASS"
 	echo " $test_subtest_name"
 }
@@ -713,6 +719,9 @@ test_failure_ () {
 		return
 	fi
 	test_failure=$(($test_failure + 1))
+	if test -n "$NOTMUCH_TEST_QUIET"; then
+		print_test_description
+	fi
 	test_failure_message_ "FAIL" "$test_subtest_name" "$@"
 	test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
 	return 1
diff --git a/test/test.expected-output/test-quiet-verbose-no b/test/test.expected-output/test-quiet-verbose-no
new file mode 100644
index 0000000..74840b9
--- /dev/null
+++ b/test/test.expected-output/test-quiet-verbose-no
@@ -0,0 +1,20 @@
+
+test-verbose: Testing the verbosity options of the test framework itself.
+ FAIL   print something in test_expect_success and fail
+	
+	  echo "hello stdout" &&
+	  echo "hello stderr" >&2 &&
+	  false
+	
+hello stdout
+hello stderr
+
+test-verbose: Testing the verbosity options of the test framework itself.
+ FAIL   print something test_begin_subtest and test_expect_equal and fail
+	--- test-verbose.4.expected
+	+++ test-verbose.4.output
+	@@ -1 +1 @@
+	-b
+	+a
+hello stdout
+hello stderr
diff --git a/test/test.expected-output/test-quiet-verbose-yes b/test/test.expected-output/test-quiet-verbose-yes
new file mode 100644
index 0000000..51e759d
--- /dev/null
+++ b/test/test.expected-output/test-quiet-verbose-yes
@@ -0,0 +1,24 @@
+hello stdout
+hello stderr
+hello stdout
+hello stderr
+
+test-verbose: Testing the verbosity options of the test framework itself.
+ FAIL   print something in test_expect_success and fail
+	
+	  echo "hello stdout" &&
+	  echo "hello stderr" >&2 &&
+	  false
+	
+hello stdout
+hello stderr
+hello stdout
+hello stderr
+
+test-verbose: Testing the verbosity options of the test framework itself.
+ FAIL   print something test_begin_subtest and test_expect_equal and fail
+	--- test-verbose.4.expected
+	+++ test-verbose.4.output
+	@@ -1 +1 @@
+	-b
+	+a
-- 
1.8.3.1

  parent reply	other threads:[~2013-11-12 20:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 20:41 [PATCH 1/3] test: resolve `basename "$0" .sh` once for all in test-lib.sh Tomi Ollila
2013-11-12 20:41 ` [PATCH 2/3] test: print empty line at the beginning of test script, not at end Tomi Ollila
2013-11-12 20:41 ` Tomi Ollila [this message]
2013-11-12 23:02   ` [PATCH 3/3] test: implement and document NOTMUCH_TEST_QUIET variable usage Austin Clements
2013-11-13  8:36     ` Tomi Ollila
2013-11-25 17:08 ` [PATCH 1/3] test: resolve `basename "$0" .sh` once for all in test-lib.sh Tomi Ollila
2013-11-25 17:08   ` [PATCH 2/3] test: print empty line at the beginning of test script, not at end Tomi Ollila
2013-11-25 17:08   ` [PATCH 3/3] test: implement and document NOTMUCH_TEST_QUIET variable usage Tomi Ollila
2013-12-04 16:18     ` Austin Clements
2013-12-04 20:15       ` Austin Clements
2013-12-05 12:46   ` [PATCH v3 part " Tomi Ollila
2013-12-09  0:33     ` Austin Clements
2013-12-09 20:24     ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1384288868-23903-3-git-send-email-tomi.ollila@iki.fi \
    --to=tomi.ollila@iki.fi \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).