Skip to content

Commit 0d6bb8b

Browse files
SiddharthShrimaligitster
authored andcommitted
t3700: use test_grep helper for better diagnostics
Replace 'grep' and '! grep' invocations with 'test_grep' and 'test_grep !'. This provides better debugging output if tests fail in the future, as 'test_grep' will automatically print the contents of the file when a check fails. While at it, update any remaining instances of 'grep' to 'test_grep' that were missed in the previous versions to ensure that the entire file is consistent with modern project style. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent fc2ead0 commit 0d6bb8b

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

t/t3700-add.sh

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test_expect_success 'Test with no pathspecs' '
3939

4040
test_expect_success 'Post-check that foo is in the index' '
4141
git ls-files foo >actual &&
42-
grep foo actual
42+
test_grep foo actual
4343
'
4444

4545
test_expect_success 'Test that "git add -- -q" works' '
@@ -141,7 +141,7 @@ test_expect_success 'error out when attempting to add ignored ones but add other
141141
git ls-files >files &&
142142
sed -n "/\\.ig/p" <files >actual &&
143143
test_must_be_empty actual &&
144-
grep a.if files
144+
test_grep a.if files
145145
'
146146

147147
test_expect_success 'add ignored ones with -f' '
@@ -197,8 +197,8 @@ test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries'
197197
echo new > symlink &&
198198
git add file symlink &&
199199
git ls-files --stage >actual &&
200-
grep "^100755 .* 0 file$" actual &&
201-
grep "^120000 .* 0 symlink$" actual
200+
test_grep "^100755 .* 0 file$" actual &&
201+
test_grep "^120000 .* 0 symlink$" actual
202202
'
203203

204204
test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over stage 1' '
@@ -215,8 +215,8 @@ test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over st
215215
echo new > symlink &&
216216
git add file symlink &&
217217
git ls-files --stage >actual &&
218-
grep "^100755 .* 0 file$" actual &&
219-
grep "^120000 .* 0 symlink$" actual
218+
test_grep "^100755 .* 0 file$" actual &&
219+
test_grep "^120000 .* 0 symlink$" actual
220220
'
221221

222222
test_expect_success 'git add --refresh' '
@@ -241,8 +241,8 @@ test_expect_success 'git add --refresh with pathspec' '
241241
test_must_be_empty actual &&
242242
243243
git diff-files --name-only >actual &&
244-
! grep bar actual &&
245-
grep baz actual
244+
test_grep ! bar actual &&
245+
test_grep baz actual
246246
'
247247

248248
test_expect_success 'git add --refresh correctly reports no match error' "
@@ -258,7 +258,7 @@ test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unr
258258
chmod 0 foo2 &&
259259
test_must_fail git add --verbose . &&
260260
git ls-files foo1 >actual &&
261-
! grep foo1 actual
261+
test_grep ! foo1 actual
262262
'
263263

264264
rm -f foo2
@@ -270,7 +270,7 @@ test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
270270
chmod 0 foo2 &&
271271
test_must_fail git add --verbose --ignore-errors . &&
272272
git ls-files foo1 >actual &&
273-
grep foo1 actual
273+
test_grep foo1 actual
274274
'
275275

276276
rm -f foo2
@@ -283,7 +283,7 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
283283
chmod 0 foo2 &&
284284
test_must_fail git add --verbose . &&
285285
git ls-files foo1 >actual &&
286-
grep foo1 actual
286+
test_grep foo1 actual
287287
'
288288
rm -f foo2
289289

@@ -295,7 +295,7 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
295295
chmod 0 foo2 &&
296296
test_must_fail git add --verbose . &&
297297
git ls-files foo1 >actual &&
298-
! grep foo1 actual
298+
test_grep ! foo1 actual
299299
'
300300
rm -f foo2
301301

@@ -307,7 +307,7 @@ test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
307307
chmod 0 foo2 &&
308308
test_must_fail git add --verbose --no-ignore-errors . &&
309309
git ls-files foo1 >actual &&
310-
! grep foo1 actual &&
310+
test_grep ! foo1 actual &&
311311
git config add.ignore-errors 0
312312
'
313313
rm -f foo2
@@ -317,9 +317,9 @@ test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" '
317317
touch fo\[ou\]bar foobar &&
318318
git add '\''fo\[ou\]bar'\'' &&
319319
git ls-files fo\[ou\]bar >actual &&
320-
grep -F fo\[ou\]bar actual &&
320+
test_grep -F fo\[ou\]bar actual &&
321321
git ls-files foobar >actual &&
322-
! grep foobar actual
322+
test_grep ! foobar actual
323323
'
324324

325325
test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
@@ -337,7 +337,7 @@ test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
337337
test_expect_success '"add non-existent" should fail' '
338338
test_must_fail git add non-existent &&
339339
git ls-files >actual &&
340-
! grep "non-existent" actual
340+
test_grep ! "non-existent" actual
341341
'
342342

343343
test_expect_success 'git add -A on empty repo does not error out' '
@@ -548,10 +548,10 @@ test_expect_success 'all statuses changed in folder if . is given' '
548548
git add -A &&
549549
git add --chmod=+x . &&
550550
git ls-files --stage >actual &&
551-
! grep ^100644 actual &&
551+
test_grep ! ^100644 actual &&
552552
git add --chmod=-x . &&
553553
git ls-files --stage >actual &&
554-
! grep ^100755 actual
554+
test_grep ! ^100755 actual
555555
)
556556
'
557557

0 commit comments

Comments
 (0)