t: use test_grep in t3701 and t4055

As a preparatory clean-up, use the "test_grep" test utility instead of regular "grep" which provides better debug information if tests fail. Signed-off-by: Leon Michalak <leonmichalak6@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Leon Michalak committed Jul 29, 2025 at 07:01 UTC 671b28394d3d3af645752afec3e6a447ee075172
2 files changed +38 -38
t/t3701-add-interactive.sh
+24 -24
@@ -63,7 +63,7 @@ test_expect_success 'setup (initial)' '
63 '
64 test_expect_success 'status works (initial)' '
65 git add -i </dev/null >output &&
66 - grep "+1/-0 *+2/-0 file" output
66 + test_grep "+1/-0 *+2/-0 file" output
67 '
68
69 test_expect_success 'setup expected' '
@@ -86,7 +86,7 @@ test_expect_success 'revert works (initial)' '
86 git add file &&
87 test_write_lines r 1 | git add -i &&
88 git ls-files >output &&
89 - ! grep . output
89 + test_grep ! . output
90 '
91
92 test_expect_success 'add untracked (multiple)' '
@@ -109,7 +109,7 @@ test_expect_success 'setup (commit)' '
109 '
110 test_expect_success 'status works (commit)' '
111 git add -i </dev/null >output &&
112 - grep "+1/-0 *+2/-0 file" output
112 + test_grep "+1/-0 *+2/-0 file" output
113 '
114
115 test_expect_success 'update can stage deletions' '
@@ -141,7 +141,7 @@ test_expect_success 'revert works (commit)' '
141 git add file &&
142 test_write_lines r 1 | git add -i &&
143 git add -i </dev/null >output &&
144 - grep "unchanged *+3/-0 file" output
144 + test_grep "unchanged *+3/-0 file" output
145 '
146
147 test_expect_success 'reject multi-key input' '
@@ -185,7 +185,7 @@ test_expect_success 'setup fake editor' '
185 test_expect_success 'bad edit rejected' '
186 git reset &&
187 test_write_lines e n d | git add -p >output &&
188 - grep "hunk does not apply" output
188 + test_grep "hunk does not apply" output
189 '
190
191 test_expect_success 'setup patch' '
@@ -198,7 +198,7 @@ test_expect_success 'setup patch' '
198 test_expect_success 'garbage edit rejected' '
199 git reset &&
200 test_write_lines e n d | git add -p >output &&
201 - grep "hunk does not apply" output
201 + test_grep "hunk does not apply" output
202 '
203
204 test_expect_success 'setup patch' '
@@ -313,8 +313,8 @@ test_expect_success FILEMODE 'stage mode and hunk' '
313 chmod +x file &&
314 printf "y\\ny\\n" | git add -p &&
315 git diff --cached file >out &&
316 - grep "new mode" out &&
317 - grep "+content" out &&
316 + test_grep "new mode" out &&
317 + test_grep "+content" out &&
318 git diff file >out &&
319 test_must_be_empty out
320 '
@@ -636,7 +636,7 @@ test_expect_success 'split hunk "add -p (edit)"' '
636 printf "%s\n" s e q n q q |
637 EDITOR=: git add -p &&
638 git diff >actual &&
639 - ! grep "^+15" actual
639 + test_grep ! "^+15" actual
640 '
641
642 test_expect_success 'split hunk "add -p (no, yes, edit)"' '
@@ -648,7 +648,7 @@ test_expect_success 'split hunk "add -p (no, yes, edit)"' '
648 EDITOR=: git add -p 2>error &&
649 test_must_be_empty error &&
650 git diff >actual &&
651 - ! grep "^+31" actual
651 + test_grep ! "^+31" actual
652 '
653
654 test_expect_success 'split hunk with incomplete line at end' '
@@ -682,7 +682,7 @@ test_expect_success 'edit, adding lines to the first hunk' '
682 EDITOR=./fake_editor.sh git add -p 2>error &&
683 test_must_be_empty error &&
684 git diff --cached >actual &&
685 - grep "^+22" actual
685 + test_grep "^+22" actual
686 '
687
688 test_expect_success 'patch mode ignores unmerged entries' '
@@ -696,7 +696,7 @@ test_expect_success 'patch mode ignores unmerged entries' '
696 test_must_fail git merge side &&
697 echo changed >non-conflict.t &&
698 echo y | git add -p >output &&
699 - ! grep a/conflict.t output &&
699 + test_grep ! a/conflict.t output &&
700 cat >expected <<-\EOF &&
701 * Unmerged path conflict.t
702 diff --git a/non-conflict.t b/non-conflict.t
@@ -728,7 +728,7 @@ test_expect_success 'diffs can be colorized' '
728
729 # We do not want to depend on the exact coloring scheme
730 # git uses for diffs, so just check that we saw some kind of color.
731 - grep "$(printf "\\033")" output
731 + test_grep "$(printf "\\033")" output
732 '
733
734 test_expect_success 'colors can be overridden' '
@@ -743,7 +743,7 @@ test_expect_success 'colors can be overridden' '
743 -c color.interactive.error=blue \
744 add -i 2>err.raw <input &&
745 test_decode_color <err.raw >err &&
746 - grep "<BLUE>Huh (trigger)?<RESET>" err &&
746 + test_grep "<BLUE>Huh (trigger)?<RESET>" err &&
747
748 test_write_lines help quit >input &&
749 force_color git \
@@ -863,7 +863,7 @@ test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
863 printf y >y &&
864 force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
865 test_decode_color <output.raw >output &&
866 - grep "old<" output
866 + test_grep "old<" output
867 '
868
869 test_expect_success 'diffFilter filters diff' '
@@ -876,7 +876,7 @@ test_expect_success 'diffFilter filters diff' '
876
877 # avoid depending on the exact coloring or content of the prompts,
878 # and just make sure we saw our diff prefixed
879 - grep foo:.*content output
879 + test_grep foo:.*content output
880 '
881
882 test_expect_success 'detect bogus diffFilter output' '
@@ -886,7 +886,7 @@ test_expect_success 'detect bogus diffFilter output' '
886 test_config interactive.diffFilter "sed 6d" &&
887 printf y >y &&
888 force_color test_must_fail git add -p <y >output 2>&1 &&
889 - grep "mismatched output" output
889 + test_grep "mismatched output" output
890 '
891
892 test_expect_success 'handle iffy colored hunk headers' '
@@ -896,7 +896,7 @@ test_expect_success 'handle iffy colored hunk headers' '
896 printf n >n &&
897 force_color git -c interactive.diffFilter="sed s/.*@@.*/XX/" \
898 add -p >output 2>&1 <n &&
899 - grep "^XX$" output
899 + test_grep "^XX$" output
900 '
901
902 test_expect_success 'handle very large filtered diff' '
@@ -1002,7 +1002,7 @@ test_expect_success 'add -p does not expand argument lists' '
1002 # update it, but we want to be sure that our "." pathspec
1003 # was not expanded into the argument list of any command.
1004 # So look only for "not-changed".
1005 - ! grep -E "^trace: (built-in|exec|run_command): .*not-changed" trace.out
1005 + test_grep ! -E "^trace: (built-in|exec|run_command): .*not-changed" trace.out
1006 '
1007
1008 test_expect_success 'hunk-editing handles custom comment char' '
@@ -1072,21 +1072,21 @@ test_expect_success 'setup different kinds of dirty submodules' '
1072
1073 test_expect_success 'status ignores dirty submodules (except HEAD)' '
1074 git -C for-submodules add -i </dev/null >output &&
1075 - grep dirty-head output &&
1076 - grep dirty-both-ways output &&
1077 - ! grep dirty-otherwise output
1075 + test_grep dirty-head output &&
1076 + test_grep dirty-both-ways output &&
1077 + test_grep ! dirty-otherwise output
1078 '
1079
1080 test_expect_success 'handle submodules' '
1081 echo 123 >>for-submodules/dirty-otherwise/initial.t &&
1082
1083 force_color git -C for-submodules add -p dirty-otherwise >output 2>&1 &&
1084 - grep "No changes" output &&
1084 + test_grep "No changes" output &&
1085
1086 force_color git -C for-submodules add -p dirty-head >output 2>&1 <y &&
1087 git -C for-submodules ls-files --stage dirty-head >actual &&
1088 rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" &&
1089 - grep "$rev" actual
1089 + test_grep "$rev" actual
1090 '
1091
1092 test_expect_success 'set up pathological context' '
t/t4055-diff-context.sh
+14 -14
@@ -38,36 +38,36 @@ test_expect_success 'setup' '
38
39 test_expect_success 'the default number of context lines is 3' '
40 git diff >output &&
41 - ! grep "^ d" output &&
42 - grep "^ e" output &&
43 - grep "^ j" output &&
44 - ! grep "^ k" output
41 + test_grep ! "^ d" output &&
42 + test_grep "^ e" output &&
43 + test_grep "^ j" output &&
44 + test_grep ! "^ k" output
45 '
46
47 test_expect_success 'diff.context honored by "log"' '
48 git log -1 -p >output &&
49 - ! grep firstline output &&
49 + test_grep ! firstline output &&
50 git config diff.context 8 &&
51 git log -1 -p >output &&
52 - grep "^ firstline" output
52 + test_grep "^ firstline" output
53 '
54
55 test_expect_success 'The -U option overrides diff.context' '
56 git config diff.context 8 &&
57 git log -U4 -1 >output &&
58 - ! grep "^ firstline" output
58 + test_grep ! "^ firstline" output
59 '
60
61 test_expect_success 'diff.context honored by "diff"' '
62 git config diff.context 8 &&
63 git diff >output &&
64 - grep "^ firstline" output
64 + test_grep "^ firstline" output
65 '
66
67 test_expect_success 'plumbing not affected' '
68 git config diff.context 8 &&
69 git diff-files -p >output &&
70 - ! grep "^ firstline" output
70 + test_grep ! "^ firstline" output
71 '
72
73 test_expect_success 'non-integer config parsing' '
@@ -85,8 +85,8 @@ test_expect_success 'negative integer config parsing' '
85 test_expect_success '-U0 is valid, so is diff.context=0' '
86 git config diff.context 0 &&
87 git diff >output &&
88 - grep "^-ADDED" output &&
89 - grep "^+MODIFIED" output
88 + test_grep "^-ADDED" output &&
89 + test_grep "^+MODIFIED" output
90 '
91
92 test_expect_success '-U2147483647 works' '
@@ -94,9 +94,9 @@ test_expect_success '-U2147483647 works' '
94 test_line_count = 16 x &&
95 git diff -U2147483647 >output &&
96 test_line_count = 22 output &&
97 - grep "^-ADDED" output &&
98 - grep "^+MODIFIED" output &&
99 - grep "^+APPENDED" output
97 + test_grep "^-ADDED" output &&
98 + test_grep "^+MODIFIED" output &&
99 + test_grep "^+APPENDED" output
100 '
101
102 test_done