From: Thomas Rast <trast@inf.ethz.ch>
To: <git@vger.kernel.org>
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
Phil Hord <phil.hord@gmail.com>, Johannes Sixt <j6t@kdbg.org>
Subject: [PATCH v2 3/6] test-lib: verbose mode for only tests matching a pattern
Date: Mon, 17 Jun 2013 11:18:48 +0200 [thread overview]
Message-ID: <8739d3ba5947c60d402030fc35d47115e7a51b0f.1371460265.git.trast@inf.ethz.ch> (raw)
In-Reply-To: <cover.1371460265.git.trast@inf.ethz.ch>
With the new --verbose-only=<pattern> option, one can enable --verbose
at a per-test granularity. The pattern is matched against the test
number, e.g.
./t0000-basic.sh --verbose-only='2[0-2]'
to see only the full output of test 20-22, while showing the rest in the
one-liner format.
As suggested by Jeff King, this takes care to wrap the entire test_expect_*
block, but nothing else, in the verbose toggling. To that end we use
a new pair of hook functions. The placement is a bit weird because we
need to wait until the beginning of test_skip for $test_count to be
incremented.
This is arguably not *too* useful on its own, but makes the next patch
easier to follow.
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
---
t/README | 5 +++++
t/test-lib-functions.sh | 2 ++
t/test-lib.sh | 44 ++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/t/README b/t/README
index 35b3c5c..f4e6299 100644
--- a/t/README
+++ b/t/README
@@ -76,6 +76,11 @@ appropriately before running "make".
command being run and their output if any are also
output.
+--verbose-only=<pattern>::
+ Like --verbose, but the effect is limited to tests with
+ numbers matching <pattern>. The number matched against is
+ simply the running count of the test within the file.
+
--debug::
This may help the person who is developing a new test.
It causes the command defined with test_debug to run.
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 5251009..0eac1dd 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -358,6 +358,7 @@ test_expect_failure () {
fi
fi
echo >&3 ""
+ test_teardown_hook_
}
test_expect_success () {
@@ -376,6 +377,7 @@ test_expect_success () {
fi
fi
echo >&3 ""
+ test_teardown_hook_
}
# test_external runs external test scripts that provide continuous
diff --git a/t/test-lib.sh b/t/test-lib.sh
index d9a74ff..84e5f03 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -184,6 +184,9 @@ do
help=t; shift ;;
-v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
verbose=t; shift ;;
+ --verbose-only=*)
+ verbose_only=$(expr "z$1" : 'z[^=]*=\(.*\)')
+ shift ;;
-q|--q|--qu|--qui|--quie|--quiet)
# Ignore --quiet under a TAP::Harness. Saying how many tests
# passed without the ok/not ok details is always an error.
@@ -342,6 +345,44 @@ match_pattern_list () {
return 1
}
+maybe_teardown_verbose () {
+ test -z "$verbose_only" && return
+ exec 4>/dev/null 3>/dev/null
+ verbose=
+}
+
+last_verbose=t
+maybe_setup_verbose () {
+ test -z "$verbose_only" && return
+ if match_pattern_list $test_count $verbose_only
+ then
+ exec 4>&2 3>&1
+ # Emit a delimiting blank line when going from
+ # non-verbose to verbose. Within verbose mode the
+ # delimiter is printed by test_expect_*. The choice
+ # of the initial $last_verbose is such that before
+ # test 1, we do not print it.
+ test -z "$last_verbose" && echo >&3 ""
+ verbose=t
+ else
+ exec 4>/dev/null 3>/dev/null
+ verbose=
+ fi
+ last_verbose=$verbose
+}
+
+# Called from test_skip after it has incremented $test_count. This
+# means it runs before any test-specific code and output.
+test_setup_hook_ () {
+ maybe_setup_verbose
+}
+
+# Called at the end of test_expect_*. This means it runs after all
+# test-specific code and output.
+test_teardown_hook_ () {
+ maybe_teardown_verbose
+}
+
test_eval_ () {
# This is a separate function because some tests use
# "return" to end a test_expect_success block early.
@@ -358,9 +399,7 @@ test_run_ () {
if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
then
- setup_malloc_check
test_eval_ "$test_cleanup"
- teardown_malloc_check
fi
if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
then
@@ -372,6 +411,7 @@ test_run_ () {
test_skip () {
test_count=$(($test_count+1))
to_skip=
+ test_setup_hook_
if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS
then
to_skip=t
--
1.8.3.1.530.g6f90e57
next prev parent reply other threads:[~2013-06-17 9:19 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-16 20:50 [PATCH 0/6] --valgrind improvements Thomas Rast
2013-05-16 20:50 ` [PATCH 1/6] test-lib: enable MALLOC_* for the actual tests Thomas Rast
2013-05-16 21:28 ` Elia Pinto
2013-05-16 22:43 ` Junio C Hamano
2013-05-16 20:50 ` [PATCH 2/6] test-lib: refactor $GIT_SKIP_TESTS matching Thomas Rast
2013-05-17 5:48 ` Johannes Sixt
2013-05-17 8:04 ` Thomas Rast
2013-05-17 16:48 ` Junio C Hamano
2013-05-17 17:02 ` Thomas Rast
2013-05-17 17:22 ` Junio C Hamano
2013-05-17 21:29 ` Johannes Sixt
2013-05-16 20:50 ` [PATCH 3/6] test-lib: verbose mode for only tests matching a pattern Thomas Rast
2013-05-29 5:00 ` Jeff King
2013-05-29 5:07 ` Jeff King
2013-05-29 17:53 ` Junio C Hamano
2013-05-16 20:50 ` [PATCH 4/6] test-lib: valgrind " Thomas Rast
2013-05-16 20:50 ` [PATCH 5/6] test-lib: allow prefixing a custom string before "ok N" etc Thomas Rast
2013-05-16 22:53 ` Phil Hord
2013-05-17 8:00 ` Thomas Rast
2013-05-17 13:00 ` Phil Hord
2013-05-16 20:50 ` [RFC PATCH 6/6] test-lib: support running tests under valgrind in parallel Thomas Rast
2013-05-29 4:53 ` [PATCH 0/6] --valgrind improvements Jeff King
2013-06-17 9:18 ` [PATCH v2 " Thomas Rast
2013-06-17 9:18 ` [PATCH v2 1/6] test-lib: enable MALLOC_* for the actual tests Thomas Rast
2013-06-17 9:18 ` [PATCH v2 2/6] test-lib: refactor $GIT_SKIP_TESTS matching Thomas Rast
2013-06-18 7:03 ` Johannes Sixt
2013-06-18 8:23 ` Thomas Rast
2013-06-17 9:18 ` Thomas Rast [this message]
2013-06-18 5:37 ` [PATCH v2 3/6] test-lib: verbose mode for only tests matching a pattern Jeff King
2013-06-18 8:45 ` Thomas Rast
2013-06-17 9:18 ` [PATCH v2 4/6] test-lib: valgrind " Thomas Rast
2013-06-17 9:18 ` [PATCH v2 5/6] test-lib: allow prefixing a custom string before "ok N" etc Thomas Rast
2013-06-17 9:18 ` [PATCH v2 6/6] test-lib: support running tests under valgrind in parallel Thomas Rast
2013-06-18 5:46 ` [PATCH v2 0/6] --valgrind improvements Jeff King
2013-06-18 12:25 ` [PATCH v3 0/8] " Thomas Rast
2013-06-18 12:25 ` [PATCH v3 1/8] test-lib: enable MALLOC_* for the actual tests Thomas Rast
2013-06-18 12:25 ` [PATCH v3 2/8] test-lib: refactor $GIT_SKIP_TESTS matching Thomas Rast
2013-06-18 12:25 ` [PATCH v3 3/8] test-lib: rearrange start/end of test_expect_* and test_skip Thomas Rast
2013-06-18 18:21 ` Junio C Hamano
2013-06-18 12:26 ` [PATCH v3 4/8] test-lib: self-test that --verbose works Thomas Rast
2013-06-18 12:26 ` [PATCH v3 5/8] test-lib: verbose mode for only tests matching a pattern Thomas Rast
2013-06-18 12:26 ` [PATCH v3 6/8] test-lib: valgrind " Thomas Rast
2013-06-18 12:26 ` [PATCH v3 7/8] test-lib: allow prefixing a custom string before "ok N" etc Thomas Rast
2013-06-18 12:26 ` [PATCH v3 8/8] test-lib: support running tests under valgrind in parallel Thomas Rast
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8739d3ba5947c60d402030fc35d47115e7a51b0f.1371460265.git.trast@inf.ethz.ch \
--to=trast@inf.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=peff@peff.net \
--cc=phil.hord@gmail.com \
/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.
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 NNTP newsgroup(s).