git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] test-lib: verbose mode for only tests matching a pattern

From
Thomas Rast <trast@inf.ethz.ch>
Date
May 16, 2013, 20:50 UTC
Message-ID
<10e5eacece7fc9657c312b5c51747d23ae9ef40b.1368736093.git.trast@inf.ethz.ch>
In-Reply-To
<cover.1368736093.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.

This is arguably not *too* useful on its own, but makes the next patch easier to follow.

Signed-off-by: Thomas Rast <trast@inf.ethz.ch>
---
 t/README      |  5 +++++
 t/test-lib.sh | 29 +++++++++++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/t/README b/t/README
index e669bb3..9c8f9b1 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.sh b/t/test-lib.sh
index c5a80d1..01e7445 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,24 @@ match_pattern_list () {
 	return 1
 }
 
+toggle_verbose () {
+	test -z "$verbose_only" && return
+	if match_pattern_list $test_count $verbose_only
+	then
+		exec 4>&2 3>&1
+	else
+		exec 4>/dev/null 3>/dev/null
+	fi
+}
+
+setup_test_eval () {
+	setup_malloc_check
+	toggle_verbose
+}
+teardown_test_eval () {
+	teardown_malloc_check
+}
+
 test_eval_ () {
 	# This is a separate function because some tests use
 	# "return" to end a test_expect_success block early.
@@ -351,16 +372,16 @@ test_eval_ () {
 test_run_ () {
 	test_cleanup=:
 	expecting_failure=$2
-	setup_malloc_check
+	setup_test_eval
 	test_eval_ "$1"
 	eval_ret=$?
-	teardown_malloc_check
+	teardown_test_eval
 
 	if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure"
 	then
-		setup_malloc_check
+		setup_test_eval
 		test_eval_ "$test_cleanup"
-		teardown_malloc_check
+		teardown_test_eval
 	fi
 	if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
 	then
-- 
1.8.3.rc2.393.g8636c0b
Previous: Johannes SixtNext: Jeff King
Message 12 of 44 in “--valgrind improvements”
  1. 0/6 --valgrind improvementsThomas Rast, May 16, 2013
  2. 1/6 test-lib: enable MALLOC_* for the actual testsThomas Rast, May 16, 2013
  3. Elia PintoMay 16, 2013
  4. Junio C HamanoMay 16, 2013
  5. 2/6 test-lib: refactor $GIT_SKIP_TESTS matchingThomas Rast, May 16, 2013
  6. Johannes SixtMay 17, 2013
  7. Thomas RastMay 17, 2013
  8. Junio C HamanoMay 17, 2013
  9. Thomas RastMay 17, 2013
  10. Junio C HamanoMay 17, 2013
  11. Johannes SixtMay 17, 2013
  12. 3/6 test-lib: verbose mode for only tests matching a patternThomas Rast, May 16, 2013
  13. Jeff KingMay 29, 2013
  14. Jeff KingMay 29, 2013
  15. Junio C HamanoMay 29, 2013
  16. 4/6 test-lib: valgrind for only tests matching a patternThomas Rast, May 16, 2013
  17. 5/6 test-lib: allow prefixing a custom string before "ok N" etc.Thomas Rast, May 16, 2013
  18. Phil HordMay 16, 2013
  19. Thomas RastMay 17, 2013
  20. Phil HordMay 17, 2013
  21. 6/6 test-lib: support running tests under valgrind in parallelThomas Rast, May 16, 2013
  22. Jeff KingMay 29, 2013
  23. 0/6 --valgrind improvementsThomas Rast, Jun 17, 2013
  24. 1/6 test-lib: enable MALLOC_* for the actual testsThomas Rast, Jun 17, 2013
  25. 2/6 test-lib: refactor $GIT_SKIP_TESTS matchingThomas Rast, Jun 17, 2013
  26. Johannes SixtJun 18, 2013
  27. Thomas RastJun 18, 2013
  28. 3/6 test-lib: verbose mode for only tests matching a patternThomas Rast, Jun 17, 2013
  29. Jeff KingJun 18, 2013
  30. Thomas RastJun 18, 2013
  31. 4/6 test-lib: valgrind for only tests matching a patternThomas Rast, Jun 17, 2013
  32. 5/6 test-lib: allow prefixing a custom string before "ok N" etc.Thomas Rast, Jun 17, 2013
  33. 6/6 test-lib: support running tests under valgrind in parallelThomas Rast, Jun 17, 2013
  34. Jeff KingJun 18, 2013
  35. 0/8 --valgrind improvementsThomas Rast, Jun 18, 2013
  36. 1/8 test-lib: enable MALLOC_* for the actual testsThomas Rast, Jun 18, 2013
  37. 2/8 test-lib: refactor $GIT_SKIP_TESTS matchingThomas Rast, Jun 18, 2013
  38. 3/8 test-lib: rearrange start/end of test_expect_* and test_skipThomas Rast, Jun 18, 2013
  39. Junio C HamanoJun 18, 2013
  40. 4/8 test-lib: self-test that --verbose worksThomas Rast, Jun 18, 2013
  41. 5/8 test-lib: verbose mode for only tests matching a patternThomas Rast, Jun 18, 2013
  42. 6/8 test-lib: valgrind for only tests matching a patternThomas Rast, Jun 18, 2013
  43. 7/8 test-lib: allow prefixing a custom string before "ok N" etc.Thomas Rast, Jun 18, 2013
  44. 8/8 test-lib: support running tests under valgrind in parallelThomas Rast, Jun 18, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.