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

Re: [PATCH v2 5/6] t: convert grep assertions to test_grep

From
SZEDER Gábor <szeder.dev@gmail.com>
Date
Jun 27, 2026, 07:08 UTC
Message-ID
<aj93BE8MYatQAjoy@szeder.dev>
In-Reply-To
<3a589ef7386303075413f388e61c203c4e325d44.1781323575.git.gitgitgadget@gmail.com>
On Sat, Jun 13, 2026 at 04:06:14AM +0000, Michael Montalbo via GitGitGadget wrote:
Show 13 quoted lines
> From: Michael Montalbo <mmontalbo@gmail.com>
> 
> Replace bare grep with test_grep in test assertions across the
> suite, including sourced test helpers (lib-*.sh, *-tests.sh).
> test_grep prints the contents of the file being searched on
> failure, making debugging easier than a bare grep which fails
> silently.
> 
> Only assertion-style greps are converted: grep used as a filter
> in pipelines, command substitutions, conditionals, or with
> redirected I/O is left as-is with a "# lint-ok" annotation.
> Existing '! test_grep' calls are rewritten to 'test_grep !' so
> that the diagnostic output is preserved on failure.

Thanks for taking the effort for cleaning up all those negated '! grep' and '! test_grep' callsites and turning them into 'test_grep !'.

Show 9 quoted lines
> The conversion was generated using a grep-assertion linter
> (greplint.pl, added in the following commit) to identify bare
> grep calls at command position.  To reproduce:
> 
>     # Step 1: mark bare greps that should not be converted
>     sed -i '/! grep "$m" \.git\/packed-refs/s/$/ # lint-ok: file may not exist (reftable)/' \
>         t/t1400-update-ref.sh
>     sed -i '/! grep dirty file3 &&/{/lint-ok/!s/$/ # lint-ok: file may not exist after --quit/}' \
>         t/t3420-rebase-autostash.sh

I think in this case checking the file3's contents is wrong, because at this point file3 should not exist in the first place. I've sent a patch to fix this long ago, but apparently didn't manage to follow through back then.

  https://lore.kernel.org/git/20211010172809.1472914-1-szeder.dev@gmail.com/
Show 95 quoted lines
> diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh
> index f0bbc476ff..f6cb3dd72e 100755
> --- a/t/t3420-rebase-autostash.sh
> +++ b/t/t3420-rebase-autostash.sh
> @@ -141,8 +141,8 @@ testrebase () {
>  		git checkout -b rebased-feature-branch feature-branch &&
>  		echo dirty >>file3 &&
>  		git rebase$type unrelated-onto-branch >actual 2>&1 &&
> -		grep unrelated file4 &&
> -		grep dirty file3 &&
> +		test_grep unrelated file4 &&
> +		test_grep dirty file3 &&
>  		git checkout feature-branch
>  	'
>  
> @@ -165,8 +165,8 @@ testrebase () {
>  		echo dirty >>file3 &&
>  		git add file3 &&
>  		git rebase$type unrelated-onto-branch &&
> -		grep unrelated file4 &&
> -		grep dirty file3 &&
> +		test_grep unrelated file4 &&
> +		test_grep dirty file3 &&
>  		git checkout feature-branch
>  	'
>  
> @@ -197,7 +197,7 @@ testrebase () {
>  		git add file2 &&
>  		git rebase --continue &&
>  		test_path_is_missing $dotest/autostash &&
> -		grep dirty file3 &&
> +		test_grep dirty file3 &&
>  		git checkout feature-branch
>  	'
>  
> @@ -212,7 +212,7 @@ testrebase () {
>  		test_path_is_missing file3 &&
>  		git rebase --skip &&
>  		test_path_is_missing $dotest/autostash &&
> -		grep dirty file3 &&
> +		test_grep dirty file3 &&
>  		git checkout feature-branch
>  	'
>  
> @@ -227,7 +227,7 @@ testrebase () {
>  		test_path_is_missing file3 &&
>  		git rebase --abort &&
>  		test_path_is_missing $dotest/autostash &&
> -		grep dirty file3 &&
> +		test_grep dirty file3 &&
>  		git checkout feature-branch
>  	'
>  
> @@ -244,7 +244,7 @@ testrebase () {
>  		git rebase --quit &&
>  		test_when_finished git stash drop &&
>  		test_path_is_missing $dotest/autostash &&
> -		! grep dirty file3 &&
> +		! grep dirty file3 && # lint-ok: file may not exist after --quit
>  		git stash show -p >actual &&
>  		test_cmp expect actual &&
>  		git reset --hard &&
> @@ -260,11 +260,11 @@ testrebase () {
>  		git rebase$type unrelated-onto-branch >actual 2>&1 &&
>  		test_path_is_missing $dotest &&
>  		git reset --hard &&
> -		grep unrelated file4 &&
> -		! grep dirty file4 &&
> +		test_grep unrelated file4 &&
> +		test_grep ! dirty file4 &&
>  		git checkout feature-branch &&
>  		git stash pop &&
> -		grep dirty file4
> +		test_grep dirty file4
>  	'
>  
>  	test_expect_success "rebase$type: check output with conflicting stash" '
> @@ -286,7 +286,7 @@ test_expect_success "rebase: fast-forward rebase" '
>  	test_when_finished git branch -D behind-feature-branch &&
>  	echo dirty >>file1 &&
>  	git rebase feature-branch &&
> -	grep dirty file1 &&
> +	test_grep dirty file1 &&
>  	git checkout feature-branch
>  '
>  
> @@ -297,7 +297,7 @@ test_expect_success "rebase: noop rebase" '
>  	test_when_finished git branch -D same-feature-branch &&
>  	echo dirty >>file1 &&
>  	git rebase feature-branch &&
> -	grep dirty file1 &&
> +	test_grep dirty file1 &&
>  	git checkout feature-branch
>  '
>  
Previous: Michael Montalbo via GitGitGadgetNext: Junio C Hamano
Message 18 of 40 in “t: add lint-style.pl and convert grep to test_grep”
  1. 0/6 t: add lint-style.pl and convert grep to test_grepMichael Montalbo via GitGitGadget, Jun 4, 2026
  2. 1/6 t/README: document test_grep helperMichael Montalbo via GitGitGadget, Jun 4, 2026
  3. 3/6 t: fix Lexer line count for $() inside double-quoted stringsMichael Montalbo via GitGitGadget, Jun 4, 2026
  4. 2/6 t: extract chainlint's parser into shared moduleMichael Montalbo via GitGitGadget, Jun 4, 2026
  5. 4/6 t: add lint-style.pl with test_grep negation ruleMichael Montalbo via GitGitGadget, Jun 4, 2026
  6. D. Ben KnobleJun 4, 2026
  7. Michael MontalboJun 4, 2026
  8. 5/6 t: fix grep assertions missing file argumentsMichael Montalbo via GitGitGadget, Jun 4, 2026
  9. 6/6 t: lint and convert grep assertions to test_grepMichael Montalbo via GitGitGadget, Jun 4, 2026
  10. Junio C HamanoJun 8, 2026
  11. Michael MontalboJun 13, 2026
  12. 0/6 t: add greplint.pl and convert grep to test_grepMichael Montalbo via GitGitGadget, Jun 13, 2026
  13. 1/6 t/README: document test_grep helperMichael Montalbo via GitGitGadget, Jun 13, 2026
  14. 2/6 t: fix grep assertions missing file argumentsMichael Montalbo via GitGitGadget, Jun 13, 2026
  15. 3/6 t: extract chainlint's parser into shared moduleMichael Montalbo via GitGitGadget, Jun 13, 2026
  16. 4/6 t: fix Lexer line count for $() inside double-quoted stringsMichael Montalbo via GitGitGadget, Jun 13, 2026
  17. 5/6 t: convert grep assertions to test_grepMichael Montalbo via GitGitGadget, Jun 13, 2026
  18. SZEDER GáborJun 27, 2026
  19. Junio C HamanoJun 27, 2026
  20. Junio C HamanoJun 28, 2026
  21. Junio C HamanoJun 28, 2026
  22. Junio C HamanoJun 29, 2026
  23. Michael MontalboJul 2, 2026
  24. 6/6 t: add greplint to detect bare grep assertionsMichael Montalbo via GitGitGadget, Jun 13, 2026
  25. 0/6 t: add greplint.pl and convert grep to test_grepMichael Montalbo via GitGitGadget, Jul 3, 2026
  26. 1/6 t/README: document test_grep helperMichael Montalbo via GitGitGadget, Jul 3, 2026
  27. 2/6 t: fix grep assertions missing file argumentsMichael Montalbo via GitGitGadget, Jul 3, 2026
  28. 3/6 t: extract chainlint's parser into shared moduleMichael Montalbo via GitGitGadget, Jul 3, 2026
  29. 4/6 t: fix Lexer line count for $() inside double-quoted stringsMichael Montalbo via GitGitGadget, Jul 3, 2026
  30. 6/6 t: add greplint to detect bare grep assertionsMichael Montalbo via GitGitGadget, Jul 3, 2026
  31. 5/6 t: convert grep assertions to test_grepMichael Montalbo via GitGitGadget, Jul 3, 2026
  32. Junio C HamanoJul 5, 2026
  33. Michael MontalboJul 5, 2026
  34. 0/6 t: add greplint.pl and convert grep to test_grepMichael Montalbo via GitGitGadget, Jul 6, 2026
  35. 1/6 t/README: document test_grep helperMichael Montalbo via GitGitGadget, Jul 6, 2026
  36. 2/6 t: fix grep assertions missing file argumentsMichael Montalbo via GitGitGadget, Jul 6, 2026
  37. 3/6 t: extract chainlint's parser into shared moduleMichael Montalbo via GitGitGadget, Jul 6, 2026
  38. 4/6 t: fix Lexer line count for $() inside double-quoted stringsMichael Montalbo via GitGitGadget, Jul 6, 2026
  39. 6/6 t: add greplint to detect bare grep assertionsMichael Montalbo via GitGitGadget, Jul 6, 2026
  40. 5/6 t: convert grep assertions to test_grepMichael Montalbo via GitGitGadget, Jul 6, 2026

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.