Skip to content

Commit bfe49b6

Browse files
committed
Merge branch 'ss/t3700-modernize' into seen
* ss/t3700-modernize: t3700: use test_grep helper for better diagnostics t3700: avoid suppressing git's exit code
2 parents aac89bf + 0d6bb8b commit bfe49b6

1 file changed

Lines changed: 31 additions & 18 deletions

File tree

t/t3700-add.sh

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

4040
test_expect_success 'Post-check that foo is in the index' '
41-
git ls-files foo | grep foo
41+
git ls-files foo >actual &&
42+
test_grep foo actual
4243
'
4344

4445
test_expect_success 'Test that "git add -- -q" works' '
@@ -140,7 +141,7 @@ test_expect_success 'error out when attempting to add ignored ones but add other
140141
git ls-files >files &&
141142
sed -n "/\\.ig/p" <files >actual &&
142143
test_must_be_empty actual &&
143-
grep a.if files
144+
test_grep a.if files
144145
'
145146

146147
test_expect_success 'add ignored ones with -f' '
@@ -195,8 +196,9 @@ test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries'
195196
echo new > file &&
196197
echo new > symlink &&
197198
git add file symlink &&
198-
git ls-files --stage | grep "^100755 .* 0 file$" &&
199-
git ls-files --stage | grep "^120000 .* 0 symlink$"
199+
git ls-files --stage >actual &&
200+
test_grep "^100755 .* 0 file$" actual &&
201+
test_grep "^120000 .* 0 symlink$" actual
200202
'
201203

202204
test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over stage 1' '
@@ -212,8 +214,9 @@ test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over st
212214
echo new > file &&
213215
echo new > symlink &&
214216
git add file symlink &&
215-
git ls-files --stage | grep "^100755 .* 0 file$" &&
216-
git ls-files --stage | grep "^120000 .* 0 symlink$"
217+
git ls-files --stage >actual &&
218+
test_grep "^100755 .* 0 file$" actual &&
219+
test_grep "^120000 .* 0 symlink$" actual
217220
'
218221

219222
test_expect_success 'git add --refresh' '
@@ -238,8 +241,8 @@ test_expect_success 'git add --refresh with pathspec' '
238241
test_must_be_empty actual &&
239242
240243
git diff-files --name-only >actual &&
241-
! grep bar actual &&
242-
grep baz actual
244+
test_grep ! bar actual &&
245+
test_grep baz actual
243246
'
244247

245248
test_expect_success 'git add --refresh correctly reports no match error' "
@@ -254,7 +257,8 @@ test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unr
254257
date >foo2 &&
255258
chmod 0 foo2 &&
256259
test_must_fail git add --verbose . &&
257-
! ( git ls-files foo1 | grep foo1 )
260+
git ls-files foo1 >actual &&
261+
test_grep ! foo1 actual
258262
'
259263

260264
rm -f foo2
@@ -265,7 +269,8 @@ test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
265269
date >foo2 &&
266270
chmod 0 foo2 &&
267271
test_must_fail git add --verbose --ignore-errors . &&
268-
git ls-files foo1 | grep foo1
272+
git ls-files foo1 >actual &&
273+
test_grep foo1 actual
269274
'
270275

271276
rm -f foo2
@@ -277,7 +282,8 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
277282
date >foo2 &&
278283
chmod 0 foo2 &&
279284
test_must_fail git add --verbose . &&
280-
git ls-files foo1 | grep foo1
285+
git ls-files foo1 >actual &&
286+
test_grep foo1 actual
281287
'
282288
rm -f foo2
283289

@@ -288,7 +294,8 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
288294
date >foo2 &&
289295
chmod 0 foo2 &&
290296
test_must_fail git add --verbose . &&
291-
! ( git ls-files foo1 | grep foo1 )
297+
git ls-files foo1 >actual &&
298+
test_grep ! foo1 actual
292299
'
293300
rm -f foo2
294301

@@ -299,7 +306,8 @@ test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
299306
date >foo2 &&
300307
chmod 0 foo2 &&
301308
test_must_fail git add --verbose --no-ignore-errors . &&
302-
! ( git ls-files foo1 | grep foo1 ) &&
309+
git ls-files foo1 >actual &&
310+
test_grep ! foo1 actual &&
303311
git config add.ignore-errors 0
304312
'
305313
rm -f foo2
@@ -308,8 +316,10 @@ test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" '
308316
git reset --hard &&
309317
touch fo\[ou\]bar foobar &&
310318
git add '\''fo\[ou\]bar'\'' &&
311-
git ls-files fo\[ou\]bar | grep -F fo\[ou\]bar &&
312-
! ( git ls-files foobar | grep foobar )
319+
git ls-files fo\[ou\]bar >actual &&
320+
test_grep -F fo\[ou\]bar actual &&
321+
git ls-files foobar >actual &&
322+
test_grep ! foobar actual
313323
'
314324

315325
test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
@@ -326,7 +336,8 @@ test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
326336

327337
test_expect_success '"add non-existent" should fail' '
328338
test_must_fail git add non-existent &&
329-
! (git ls-files | grep "non-existent")
339+
git ls-files >actual &&
340+
test_grep ! "non-existent" actual
330341
'
331342

332343
test_expect_success 'git add -A on empty repo does not error out' '
@@ -536,9 +547,11 @@ test_expect_success 'all statuses changed in folder if . is given' '
536547
touch x y z sub/a sub/dir/b &&
537548
git add -A &&
538549
git add --chmod=+x . &&
539-
test $(git ls-files --stage | grep ^100644 | wc -l) -eq 0 &&
550+
git ls-files --stage >actual &&
551+
test_grep ! ^100644 actual &&
540552
git add --chmod=-x . &&
541-
test $(git ls-files --stage | grep ^100755 | wc -l) -eq 0
553+
git ls-files --stage >actual &&
554+
test_grep ! ^100755 actual
542555
)
543556
'
544557

0 commit comments

Comments
 (0)