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

[PATCH 06/25] t: use verbose instead of hand-rolled errors

From
Jeff King <peff@peff.net>
Date
Mar 20, 2015, 10:09 UTC
Message-ID
<20150320100900.GF12543@peff.net>
In-Reply-To
<20150320100429.GA17354@peff.net>

Many tests that predate the "verbose" helper function use a pattern like:

  test ... || {
	  echo ...
	  false
  }

to give more verbose output. Using the helper, we can do this with a single line, and avoid a || which interacts badly with &&-chaining (besides fooling --chain-lint, we hit the error block no matter which command in the chain failed, so we may often show useless results).

In most cases, the messages printed by "verbose" are equally good (in some cases better; t6006 accidentally redirects the message to a file!). The exception is t7001, whose output suffers slightly. However, it's still enough to show the user which part failed, given that we will have just printed the test script to stderr.

Signed-off-by: Jeff King <peff@peff.net>
---
 t/t4022-diff-rewrite.sh    |  5 +----
 t/t4202-log.sh             | 30 +++++-------------------------
 t/t6006-rev-list-format.sh |  5 +----
 t/t7001-mv.sh              |  5 +----
 t/t7300-clean.sh           | 10 ++--------
 5 files changed, 10 insertions(+), 45 deletions(-)
diff --git a/t/t4022-diff-rewrite.sh b/t/t4022-diff-rewrite.sh
index 2d030a4..cb51d9f 100755
--- a/t/t4022-diff-rewrite.sh
+++ b/t/t4022-diff-rewrite.sh
@@ -20,10 +20,7 @@ test_expect_success setup '
 test_expect_success 'detect rewrite' '
 
 	actual=$(git diff-files -B --summary test) &&
-	expr "$actual" : " rewrite test ([0-9]*%)$" || {
-		echo "Eh? <<$actual>>"
-		false
-	}
+	verbose expr "$actual" : " rewrite test ([0-9]*%)$"
 
 '
 
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index a22ac7c..85230a8 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -113,11 +113,7 @@ test_expect_success 'diff-filter=M' '
 
 	actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) &&
 	expect=$(echo second) &&
-	test "$actual" = "$expect" || {
-		echo Oops
-		echo "Actual: $actual"
-		false
-	}
+	verbose test "$actual" = "$expect"
 
 '
 
@@ -125,11 +121,7 @@ test_expect_success 'diff-filter=D' '
 
 	actual=$(git log --pretty="format:%s" --diff-filter=D HEAD) &&
 	expect=$(echo sixth ; echo third) &&
-	test "$actual" = "$expect" || {
-		echo Oops
-		echo "Actual: $actual"
-		false
-	}
+	verbose test "$actual" = "$expect"
 
 '
 
@@ -137,11 +129,7 @@ test_expect_success 'diff-filter=R' '
 
 	actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) &&
 	expect=$(echo third) &&
-	test "$actual" = "$expect" || {
-		echo Oops
-		echo "Actual: $actual"
-		false
-	}
+	verbose test "$actual" = "$expect"
 
 '
 
@@ -149,11 +137,7 @@ test_expect_success 'diff-filter=C' '
 
 	actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) &&
 	expect=$(echo fourth) &&
-	test "$actual" = "$expect" || {
-		echo Oops
-		echo "Actual: $actual"
-		false
-	}
+	verbose test "$actual" = "$expect"
 
 '
 
@@ -161,11 +145,7 @@ test_expect_success 'git log --follow' '
 
 	actual=$(git log --follow --pretty="format:%s" ichi) &&
 	expect=$(echo third ; echo second ; echo initial) &&
-	test "$actual" = "$expect" || {
-		echo Oops
-		echo "Actual: $actual"
-		false
-	}
+	verbose test "$actual" = "$expect"
 
 '
 
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index 2b7c0f0..b77d4c9 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -358,10 +358,7 @@ test_expect_success 'empty email' '
 	test_tick &&
 	C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
 	A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
-	test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700" || {
-		echo "Eh? $A" >failure
-		false
-	}
+	verbose test "$A" = "A U Thor,,Thu Apr 7 15:14:13 2005 -0700"
 '
 
 test_expect_success 'del LF before empty (1)' '
diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh
index 69f11bd..7b56081 100755
--- a/t/t7001-mv.sh
+++ b/t/t7001-mv.sh
@@ -161,10 +161,7 @@ test_expect_success "Michael Cassar's test case" '
 	git mv papers/unsorted/Thesis.pdf papers/all-papers/moo-blah.pdf &&
 
 	T=`git write-tree` &&
-	git ls-tree -r $T | grep partA/outline.txt || {
-		git ls-tree -r $T
-		(exit 1)
-	}
+	git ls-tree -r $T | verbose grep partA/outline.txt
 '
 
 rm -fr papers partA path?
diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
index 04118ad..99be5d9 100755
--- a/t/t7300-clean.sh
+++ b/t/t7300-clean.sh
@@ -119,10 +119,7 @@ test_expect_success C_LOCALE_OUTPUT 'git clean with relative prefix' '
 		git clean -n ../src |
 		sed -n -e "s|^Would remove ||p"
 	) &&
-	test "$would_clean" = ../src/part3.c || {
-		echo "OOps <$would_clean>"
-		false
-	}
+	verbose test "$would_clean" = ../src/part3.c
 '
 
 test_expect_success C_LOCALE_OUTPUT 'git clean with absolute path' '
@@ -134,10 +131,7 @@ test_expect_success C_LOCALE_OUTPUT 'git clean with absolute path' '
 		git clean -n "$(pwd)/../src" |
 		sed -n -e "s|^Would remove ||p"
 	) &&
-	test "$would_clean" = ../src/part3.c || {
-		echo "OOps <$would_clean>"
-		false
-	}
+	verbose test "$would_clean" = ../src/part3.c
 '
 
 test_expect_success 'git clean with out of work tree relative path' '
-- 
2.3.3.520.g3cfbb5d
Previous: Jeff KingNext: Jeff King
Message 9 of 68 in “detecting &&-chain breakage”
  1. 0/25 detecting &&-chain breakageJeff King, Mar 20, 2015
  2. 01/25 t/test-lib: introduce --chain-lint optionJeff King, Mar 20, 2015
  3. SZEDER GáborMar 25, 2015
  4. Jeff KingMar 25, 2015
  5. 02/25 t: fix severe &&-chain breakageJeff King, Mar 20, 2015
  6. 03/25 t: fix moderate &&-chain breakageJeff King, Mar 20, 2015
  7. 04/25 t: fix trivial &&-chain breakageJeff King, Mar 20, 2015
  8. 05/25 t: assume test_cmp produces verbose outputJeff King, Mar 20, 2015
  9. 06/25 t: use verbose instead of hand-rolled errorsJeff King, Mar 20, 2015
  10. 07/25 t: use test_must_fail instead of hand-rolled blocksJeff King, Mar 20, 2015
  11. 08/25 t: fix &&-chaining issues around setup which might failJeff King, Mar 20, 2015
  12. 09/25 t: use test_might_fail for diff and grepJeff King, Mar 20, 2015
  13. 10/25 t: use test_expect_code instead of hand-rolled comparisonJeff King, Mar 20, 2015
  14. 11/25 t: wrap complicated expect_code users in a blockJeff King, Mar 20, 2015
  15. 12/25 t: avoid using ":" for commentsJeff King, Mar 20, 2015
  16. 13/25 t3600: fix &&-chain breakage for setup commandsJeff King, Mar 20, 2015
  17. 14/25 t7201: fix &&-chain breakageJeff King, Mar 20, 2015
  18. 15/25 t9502: fix &&-chain breakageJeff King, Mar 20, 2015
  19. Johannes SixtMar 20, 2015
  20. Jeff KingMar 20, 2015
  21. 16/25 t6030: use modern test_* helpersJeff King, Mar 20, 2015
  22. 17/25 t0020: use modern test_* helpersJeff King, Mar 20, 2015
  23. SZEDER GáborMar 25, 2015
  24. Jeff KingMar 25, 2015
  25. 0/8 more &&-chaining test fixupsJeff King, Mar 25, 2015
  26. 1/8 perf-lib: fix ignored exit code inside loopJeff King, Mar 25, 2015
  27. 2/8 t0020: fix ignored exit code inside loopsJeff King, Mar 25, 2015
  28. 3/8 t3305: fix ignored exit code inside loopJeff King, Mar 25, 2015
  29. Johan HerlandMar 25, 2015
  30. 4/8 t7701: fix ignored exit code inside loopJeff King, Mar 25, 2015
  31. 5/8 t: fix some trivial cases of ignored exit codes in loopsJeff King, Mar 25, 2015
  32. 6/8 t: simplify loop exit-code status variablesJeff King, Mar 25, 2015
  33. Junio C HamanoMar 25, 2015
  34. Jeff KingMar 25, 2015
  35. 7/8 t0020: use test_* helpers instead of hand-rolled messagesJeff King, Mar 25, 2015
  36. 8/8 t9001: drop save_confirm helperJeff King, Mar 25, 2015
  37. Junio C HamanoMar 25, 2015
  38. 18/25 t1301: use modern test_* helpersJeff King, Mar 20, 2015
  39. SZEDER GáborMar 24, 2015
  40. Jeff KingMar 25, 2015
  41. 19/25 t6034: use modern test_* helpersJeff King, Mar 20, 2015
  42. SZEDER GáborMar 24, 2015
  43. 20/25 t4117: use modern test_* helpersJeff King, Mar 20, 2015
  44. 21/25 t9001: use test_when_finishedJeff King, Mar 20, 2015
  45. SZEDER GáborMar 25, 2015
  46. Jeff KingMar 25, 2015
  47. 22/25 t0050: appease --chain-lintJeff King, Mar 20, 2015
  48. 23/25 t7004: fix embedded single-quotesJeff King, Mar 20, 2015
  49. 24/25 t0005: fix broken &&-chainsJeff King, Mar 20, 2015
  50. 25/25 t4104: drop hand-rolled error reportingJeff King, Mar 20, 2015
  51. Jeff KingMar 20, 2015
  52. Michael J GruberMar 20, 2015
  53. 26/27 t/*svn*: fix moderate &&-chain breakageMichael J Gruber, Mar 20, 2015
  54. Junio C HamanoMar 20, 2015
  55. Junio C HamanoMar 20, 2015
  56. Jeff KingMar 20, 2015
  57. Jeff KingMar 20, 2015
  58. Michael J GruberMar 23, 2015
  59. 27/27 t9104: fix test for following larger parentsMichael J Gruber, Mar 20, 2015
  60. Jeff KingMar 20, 2015
  61. Junio C HamanoMar 20, 2015
  62. Junio C HamanoMar 20, 2015
  63. Jeff KingMar 20, 2015
  64. Junio C HamanoMar 20, 2015
  65. Eric SunshineMar 20, 2015
  66. Jeff KingMar 21, 2015
  67. Junio C HamanoMar 21, 2015
  68. Jeff KingMar 21, 2015

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.