Skip to content

Commit 8c6f58a

Browse files
NinjaInShadegitster
authored andcommitted
test: refactor to use "test_grep"
Refactor to use the modern "test_grep" test utility instead of regular "grep" which provides better debug information if tests fail. This is a prerequisite to the commits that follow which add to both test files. Signed-off-by: Leon Michalak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7a1d2bd commit 8c6f58a

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

t/t3701-add-interactive.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test_expect_success 'setup (initial)' '
6363
'
6464
test_expect_success 'status works (initial)' '
6565
git add -i </dev/null >output &&
66-
grep "+1/-0 *+2/-0 file" output
66+
test_grep "+1/-0 *+2/-0 file" output
6767
'
6868

6969
test_expect_success 'setup expected' '
@@ -86,7 +86,7 @@ test_expect_success 'revert works (initial)' '
8686
git add file &&
8787
test_write_lines r 1 | git add -i &&
8888
git ls-files >output &&
89-
! grep . output
89+
test_grep ! . output
9090
'
9191

9292
test_expect_success 'add untracked (multiple)' '
@@ -109,7 +109,7 @@ test_expect_success 'setup (commit)' '
109109
'
110110
test_expect_success 'status works (commit)' '
111111
git add -i </dev/null >output &&
112-
grep "+1/-0 *+2/-0 file" output
112+
test_grep "+1/-0 *+2/-0 file" output
113113
'
114114

115115
test_expect_success 'update can stage deletions' '
@@ -141,7 +141,7 @@ test_expect_success 'revert works (commit)' '
141141
git add file &&
142142
test_write_lines r 1 | git add -i &&
143143
git add -i </dev/null >output &&
144-
grep "unchanged *+3/-0 file" output
144+
test_grep "unchanged *+3/-0 file" output
145145
'
146146

147147
test_expect_success 'reject multi-key input' '
@@ -185,7 +185,7 @@ test_expect_success 'setup fake editor' '
185185
test_expect_success 'bad edit rejected' '
186186
git reset &&
187187
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
189189
'
190190

191191
test_expect_success 'setup patch' '
@@ -198,7 +198,7 @@ test_expect_success 'setup patch' '
198198
test_expect_success 'garbage edit rejected' '
199199
git reset &&
200200
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
202202
'
203203

204204
test_expect_success 'setup patch' '
@@ -313,8 +313,8 @@ test_expect_success FILEMODE 'stage mode and hunk' '
313313
chmod +x file &&
314314
printf "y\\ny\\n" | git add -p &&
315315
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 &&
318318
git diff file >out &&
319319
test_must_be_empty out
320320
'
@@ -636,7 +636,7 @@ test_expect_success 'split hunk "add -p (edit)"' '
636636
printf "%s\n" s e q n q q |
637637
EDITOR=: git add -p &&
638638
git diff >actual &&
639-
! grep "^+15" actual
639+
test_grep ! "^+15" actual
640640
'
641641

642642
test_expect_success 'split hunk "add -p (no, yes, edit)"' '
@@ -648,7 +648,7 @@ test_expect_success 'split hunk "add -p (no, yes, edit)"' '
648648
EDITOR=: git add -p 2>error &&
649649
test_must_be_empty error &&
650650
git diff >actual &&
651-
! grep "^+31" actual
651+
test_grep ! "^+31" actual
652652
'
653653

654654
test_expect_success 'split hunk with incomplete line at end' '
@@ -682,7 +682,7 @@ test_expect_success 'edit, adding lines to the first hunk' '
682682
EDITOR=./fake_editor.sh git add -p 2>error &&
683683
test_must_be_empty error &&
684684
git diff --cached >actual &&
685-
grep "^+22" actual
685+
test_grep "^+22" actual
686686
'
687687

688688
test_expect_success 'patch mode ignores unmerged entries' '
@@ -696,7 +696,7 @@ test_expect_success 'patch mode ignores unmerged entries' '
696696
test_must_fail git merge side &&
697697
echo changed >non-conflict.t &&
698698
echo y | git add -p >output &&
699-
! grep a/conflict.t output &&
699+
test_grep ! a/conflict.t output &&
700700
cat >expected <<-\EOF &&
701701
* Unmerged path conflict.t
702702
diff --git a/non-conflict.t b/non-conflict.t
@@ -728,7 +728,7 @@ test_expect_success 'diffs can be colorized' '
728728
729729
# We do not want to depend on the exact coloring scheme
730730
# 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
732732
'
733733

734734
test_expect_success 'colors can be overridden' '
@@ -743,7 +743,7 @@ test_expect_success 'colors can be overridden' '
743743
-c color.interactive.error=blue \
744744
add -i 2>err.raw <input &&
745745
test_decode_color <err.raw >err &&
746-
grep "<BLUE>Huh (trigger)?<RESET>" err &&
746+
test_grep "<BLUE>Huh (trigger)?<RESET>" err &&
747747
748748
test_write_lines help quit >input &&
749749
force_color git \
@@ -863,7 +863,7 @@ test_expect_success 'colorized diffs respect diff.wsErrorHighlight' '
863863
printf y >y &&
864864
force_color git -c diff.wsErrorHighlight=all add -p >output.raw 2>&1 <y &&
865865
test_decode_color <output.raw >output &&
866-
grep "old<" output
866+
test_grep "old<" output
867867
'
868868

869869
test_expect_success 'diffFilter filters diff' '
@@ -876,7 +876,7 @@ test_expect_success 'diffFilter filters diff' '
876876
877877
# avoid depending on the exact coloring or content of the prompts,
878878
# and just make sure we saw our diff prefixed
879-
grep foo:.*content output
879+
test_grep foo:.*content output
880880
'
881881

882882
test_expect_success 'detect bogus diffFilter output' '
@@ -886,7 +886,7 @@ test_expect_success 'detect bogus diffFilter output' '
886886
test_config interactive.diffFilter "sed 6d" &&
887887
printf y >y &&
888888
force_color test_must_fail git add -p <y >output 2>&1 &&
889-
grep "mismatched output" output
889+
test_grep "mismatched output" output
890890
'
891891

892892
test_expect_success 'handle iffy colored hunk headers' '
@@ -896,7 +896,7 @@ test_expect_success 'handle iffy colored hunk headers' '
896896
printf n >n &&
897897
force_color git -c interactive.diffFilter="sed s/.*@@.*/XX/" \
898898
add -p >output 2>&1 <n &&
899-
grep "^XX$" output
899+
test_grep "^XX$" output
900900
'
901901

902902
test_expect_success 'handle very large filtered diff' '
@@ -1002,7 +1002,7 @@ test_expect_success 'add -p does not expand argument lists' '
10021002
# update it, but we want to be sure that our "." pathspec
10031003
# was not expanded into the argument list of any command.
10041004
# 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
10061006
'
10071007

10081008
test_expect_success 'hunk-editing handles custom comment char' '
@@ -1072,21 +1072,21 @@ test_expect_success 'setup different kinds of dirty submodules' '
10721072

10731073
test_expect_success 'status ignores dirty submodules (except HEAD)' '
10741074
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
10781078
'
10791079

10801080
test_expect_success 'handle submodules' '
10811081
echo 123 >>for-submodules/dirty-otherwise/initial.t &&
10821082
10831083
force_color git -C for-submodules add -p dirty-otherwise >output 2>&1 &&
1084-
grep "No changes" output &&
1084+
test_grep "No changes" output &&
10851085
10861086
force_color git -C for-submodules add -p dirty-head >output 2>&1 <y &&
10871087
git -C for-submodules ls-files --stage dirty-head >actual &&
10881088
rev="$(git -C for-submodules/dirty-head rev-parse HEAD)" &&
1089-
grep "$rev" actual
1089+
test_grep "$rev" actual
10901090
'
10911091

10921092
test_expect_success 'set up pathological context' '

t/t4055-diff-context.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,36 @@ test_expect_success 'setup' '
3838

3939
test_expect_success 'the default number of context lines is 3' '
4040
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
4545
'
4646

4747
test_expect_success 'diff.context honored by "log"' '
4848
git log -1 -p >output &&
49-
! grep firstline output &&
49+
test_grep ! firstline output &&
5050
git config diff.context 8 &&
5151
git log -1 -p >output &&
52-
grep "^ firstline" output
52+
test_grep "^ firstline" output
5353
'
5454

5555
test_expect_success 'The -U option overrides diff.context' '
5656
git config diff.context 8 &&
5757
git log -U4 -1 >output &&
58-
! grep "^ firstline" output
58+
test_grep ! "^ firstline" output
5959
'
6060

6161
test_expect_success 'diff.context honored by "diff"' '
6262
git config diff.context 8 &&
6363
git diff >output &&
64-
grep "^ firstline" output
64+
test_grep "^ firstline" output
6565
'
6666

6767
test_expect_success 'plumbing not affected' '
6868
git config diff.context 8 &&
6969
git diff-files -p >output &&
70-
! grep "^ firstline" output
70+
test_grep ! "^ firstline" output
7171
'
7272

7373
test_expect_success 'non-integer config parsing' '
@@ -85,18 +85,18 @@ test_expect_success 'negative integer config parsing' '
8585
test_expect_success '-U0 is valid, so is diff.context=0' '
8686
git config diff.context 0 &&
8787
git diff >output &&
88-
grep "^-ADDED" output &&
89-
grep "^+MODIFIED" output
88+
test_grep "^-ADDED" output &&
89+
test_grep "^+MODIFIED" output
9090
'
9191

9292
test_expect_success '-U2147483647 works' '
9393
echo APPENDED >>x &&
9494
test_line_count = 16 x &&
9595
git diff -U2147483647 >output &&
9696
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
100100
'
101101

102102
test_done

0 commit comments

Comments
 (0)