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

Re: [PATCH v3 1/9] t5520: fixup file contents comparisons

From
Junio C Hamano <gitster@pobox.com>
Date
May 15, 2015, 19:22 UTC
Message-ID
<xmqqzj55fxyf.fsf@gitster.dls.corp.google.com>
In-Reply-To
<xmqq7fs9hekc.fsf@gitster.dls.corp.google.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 9 quoted lines
> You might have noticed, while adding them, there were something
> common that we currently do with a bare 'test' only because we
> haven't identified common needs....
> ...
> in t/test-lib-functions.sh and convert them to say
>
> 	test_file_contents file expected_string
>
> That would be an improvement (and that is the remaining 2/3 ;-).

I haven't made up my mind on this other example, but since I started writing it...

It may be that counting the number of lines in output, "cmd | wc -l", is a common pattern. We already have test_line_count to check the number of lines in a file, but having test_output_count may help.

 t/test-lib-functions.sh | 11 +++++++++++
 t/t0000-basic.sh        |  3 +--
 t/t0030-stripspace.sh   | 11 +++++------
 3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 0d93e33..624a8c5 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -538,6 +538,17 @@ test_line_count () {
 	fi
 }
 
+test_output_count () {
+	if test $# != 3
+	then
+		error "bug in the test script: not 3 parameters to test_output_count"
+	elif ! test $(eval "$2" | wc -l) "$1" "$3"
+	then
+		echo "test_output_count: line count for output from '$2' !$1 $3"
+		return 1
+	fi
+}
+
 # This is not among top-level (test_expect_success | test_expect_failure)
 # but is a prefix that can be used in the test script, like:
 #

diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index f10ba4a..bd5930d 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -1039,8 +1039,7 @@ test_expect_success 'update-index D/F conflict' '
 	mv path2 path0 &&
 	mv tmp path2 &&
 	git update-index --add --replace path2 path0/file2 &&
-	numpath0=$(git ls-files path0 | wc -l) &&
-	test $numpath0 = 1
+	test_output_count = "git ls-files path0" 1
 '
 
 test_expect_success 'very long name in the index handled sanely' '
diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
index 0333dd9..9502938 100755
--- a/t/t0030-stripspace.sh
+++ b/t/t0030-stripspace.sh
@@ -223,12 +223,11 @@ test_expect_success \
     test_cmp expect actual
 '
 
-test_expect_success \
-    'text without newline at end should end with newline' '
-    test $(printf "$ttt" | git stripspace | wc -l) -gt 0 &&
-    test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
-    test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
-    test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
+test_expect_success 'text without newline at end should end with newline' '
+	test_output_count -gt '\''printf "$ttt" | git stripspace'\'' 0 &&
+	test_output_count -gt '\''printf "$ttt$ttt" | git stripspace'\'' 0 &&
+	test_output_count -gt '\''printf "$ttt$ttt$ttt" | git stripspace'\'' 0 &&
+	test_output_count -gt '\''printf "$ttt$ttt$ttt$ttt" | git stripspace'\'' 0
 '
 
 # text plus spaces at the end:
Previous: Junio C HamanoNext: Paul Tan
Message 9 of 25 in “Improve git-pull test coverage”
  1. 0/9 Improve git-pull test coveragePaul Tan, May 13, 2015
  2. 1/9 t5520: fixup file contents comparisonsPaul Tan, May 13, 2015
  3. Junio C HamanoMay 13, 2015
  4. Junio C HamanoMay 13, 2015
  5. Michael BlumeMay 14, 2015
  6. Junio C HamanoMay 14, 2015
  7. Paul TanMay 15, 2015
  8. Junio C HamanoMay 15, 2015
  9. Junio C HamanoMay 15, 2015
  10. Paul TanMay 16, 2015
  11. Junio C HamanoMay 16, 2015
  12. Junio C HamanoMay 16, 2015
  13. Paul TanMay 17, 2015
  14. 2/9 t5520: ensure origin refs are updatedPaul Tan, May 13, 2015
  15. Junio C HamanoMay 13, 2015
  16. Paul TanMay 18, 2015
  17. 3/9 t5520: test no merge candidates casesPaul Tan, May 13, 2015
  18. 4/9 t5520: test for failure if index has unresolved entriesPaul Tan, May 13, 2015
  19. Matthieu MoyMay 13, 2015
  20. Paul TanMay 15, 2015
  21. 5/9 t5520: test work tree fast-forward when fetch updates headPaul Tan, May 13, 2015
  22. 6/9 t5520: test --rebase with multiple branchesPaul Tan, May 13, 2015
  23. 7/9 t5520: test --rebase failure on unborn branch with indexPaul Tan, May 13, 2015
  24. 8/9 t5521: test --dry-run does not make any changesPaul Tan, May 13, 2015
  25. 9/9 t5520: check reflog action in fast-forward mergePaul Tan, May 13, 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.