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>
Siddharth Shrimali committed
Mar 4, 2026 at 02:10 UTC
0d6bb8b541b0bd049599c29711e2c75ca5f17b07
1 file changed
+18
-18
t/t3700-add.sh
+18
-18
@@ -39,7 +39,7 @@ test_expect_success 'Test with no pathspecs' '
39
40
test_expect_success 'Post-check that foo is in the index' '
41
git ls-files foo >actual &&
42
- grep foo actual
42
+ test_grep foo actual
43
'
44
45
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
141
git ls-files >files &&
142
sed -n "/\\.ig/p" <files >actual &&
143
test_must_be_empty actual &&
144
- grep a.if files
144
+ test_grep a.if files
145
'
146
147
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'
197
echo new > symlink &&
198
git add file symlink &&
199
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
202
'
203
204
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
215
echo new > symlink &&
216
git add file symlink &&
217
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
220
'
221
222
test_expect_success 'git add --refresh' '
@@ -241,8 +241,8 @@ test_expect_success 'git add --refresh with pathspec' '
241
test_must_be_empty actual &&
242
243
git diff-files --name-only >actual &&
244
- ! grep bar actual &&
245
- grep baz actual
244
+ test_grep ! bar actual &&
245
+ test_grep baz actual
246
'
247
248
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
258
chmod 0 foo2 &&
259
test_must_fail git add --verbose . &&
260
git ls-files foo1 >actual &&
261
- ! grep foo1 actual
261
+ test_grep ! foo1 actual
262
'
263
264
rm -f foo2
@@ -270,7 +270,7 @@ test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
270
chmod 0 foo2 &&
271
test_must_fail git add --verbose --ignore-errors . &&
272
git ls-files foo1 >actual &&
273
- grep foo1 actual
273
+ test_grep foo1 actual
274
'
275
276
rm -f foo2
@@ -283,7 +283,7 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
283
chmod 0 foo2 &&
284
test_must_fail git add --verbose . &&
285
git ls-files foo1 >actual &&
286
- grep foo1 actual
286
+ test_grep foo1 actual
287
'
288
rm -f foo2
289
@@ -295,7 +295,7 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
295
chmod 0 foo2 &&
296
test_must_fail git add --verbose . &&
297
git ls-files foo1 >actual &&
298
- ! grep foo1 actual
298
+ test_grep ! foo1 actual
299
'
300
rm -f foo2
301
@@ -307,7 +307,7 @@ test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
307
chmod 0 foo2 &&
308
test_must_fail git add --verbose --no-ignore-errors . &&
309
git ls-files foo1 >actual &&
310
- ! grep foo1 actual &&
310
+ test_grep ! foo1 actual &&
311
git config add.ignore-errors 0
312
'
313
rm -f foo2
@@ -317,9 +317,9 @@ test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" '
317
touch fo\[ou\]bar foobar &&
318
git add '\''fo\[ou\]bar'\'' &&
319
git ls-files fo\[ou\]bar >actual &&
320
- grep -F fo\[ou\]bar actual &&
320
+ test_grep -F fo\[ou\]bar actual &&
321
git ls-files foobar >actual &&
322
- ! grep foobar actual
322
+ test_grep ! foobar actual
323
'
324
325
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' '
337
test_expect_success '"add non-existent" should fail' '
338
test_must_fail git add non-existent &&
339
git ls-files >actual &&
340
- ! grep "non-existent" actual
340
+ test_grep ! "non-existent" actual
341
'
342
343
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' '
548
git add -A &&
549
git add --chmod=+x . &&
550
git ls-files --stage >actual &&
551
- ! grep ^100644 actual &&
551
+ test_grep ! ^100644 actual &&
552
git add --chmod=-x . &&
553
git ls-files --stage >actual &&
554
- ! grep ^100755 actual
554
+ test_grep ! ^100755 actual
555
)
556
'
557