Skip to content

Commit 93e911f

Browse files
j6tpeff
authored andcommitted
modernize t9300: use test_when_finished for clean-up
A number of clean-ups of test cases are performed outside of test_expect_success. Replace these cases by using test_when_finished. Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent ec2c10b commit 93e911f

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

t/t9300-fast-import.sh

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ M 755 0000000000000000000000000000000000000001 zero1
344344
345345
INPUT_END
346346
test_expect_success 'B: fail on invalid blob sha1' '
347+
test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
347348
test_must_fail git fast-import <input
348349
'
349-
rm -f .git/objects/pack_* .git/objects/index_*
350350

351351
cat >input <<INPUT_END
352352
commit TEMP_TAG
@@ -359,14 +359,13 @@ from refs/heads/master
359359
360360
INPUT_END
361361
test_expect_success 'B: accept branch name "TEMP_TAG"' '
362+
test_when_finished "rm -f .git/TEMP_TAG
363+
git gc
364+
git prune" &&
362365
git fast-import <input &&
363366
test -f .git/TEMP_TAG &&
364367
test `git rev-parse master` = `git rev-parse TEMP_TAG^`
365368
'
366-
rm -f .git/TEMP_TAG
367-
368-
git gc 2>/dev/null >/dev/null
369-
git prune 2>/dev/null >/dev/null
370369

371370
cat >input <<INPUT_END
372371
commit refs/heads/empty-committer-1
@@ -376,15 +375,14 @@ empty commit
376375
COMMIT
377376
INPUT_END
378377
test_expect_success 'B: accept empty committer' '
378+
test_when_finished "git update-ref -d refs/heads/empty-committer-1
379+
git gc
380+
git prune" &&
379381
git fast-import <input &&
380382
out=$(git fsck) &&
381383
echo "$out" &&
382384
test -z "$out"
383385
'
384-
git update-ref -d refs/heads/empty-committer-1 || true
385-
386-
git gc 2>/dev/null >/dev/null
387-
git prune 2>/dev/null >/dev/null
388386

389387
cat >input <<INPUT_END
390388
commit refs/heads/empty-committer-2
@@ -394,15 +392,14 @@ empty commit
394392
COMMIT
395393
INPUT_END
396394
test_expect_success 'B: accept and fixup committer with no name' '
395+
test_when_finished "git update-ref -d refs/heads/empty-committer-2
396+
git gc
397+
git prune" &&
397398
git fast-import <input &&
398399
out=$(git fsck) &&
399400
echo "$out" &&
400401
test -z "$out"
401402
'
402-
git update-ref -d refs/heads/empty-committer-2 || true
403-
404-
git gc 2>/dev/null >/dev/null
405-
git prune 2>/dev/null >/dev/null
406403

407404
cat >input <<INPUT_END
408405
commit refs/heads/invalid-committer
@@ -412,9 +409,9 @@ empty commit
412409
COMMIT
413410
INPUT_END
414411
test_expect_success 'B: fail on invalid committer (1)' '
412+
test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
415413
test_must_fail git fast-import <input
416414
'
417-
git update-ref -d refs/heads/invalid-committer || true
418415

419416
cat >input <<INPUT_END
420417
commit refs/heads/invalid-committer
@@ -424,9 +421,9 @@ empty commit
424421
COMMIT
425422
INPUT_END
426423
test_expect_success 'B: fail on invalid committer (2)' '
424+
test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
427425
test_must_fail git fast-import <input
428426
'
429-
git update-ref -d refs/heads/invalid-committer || true
430427

431428
cat >input <<INPUT_END
432429
commit refs/heads/invalid-committer
@@ -436,9 +433,9 @@ empty commit
436433
COMMIT
437434
INPUT_END
438435
test_expect_success 'B: fail on invalid committer (3)' '
436+
test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
439437
test_must_fail git fast-import <input
440438
'
441-
git update-ref -d refs/heads/invalid-committer || true
442439

443440
cat >input <<INPUT_END
444441
commit refs/heads/invalid-committer
@@ -448,9 +445,9 @@ empty commit
448445
COMMIT
449446
INPUT_END
450447
test_expect_success 'B: fail on invalid committer (4)' '
448+
test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
451449
test_must_fail git fast-import <input
452450
'
453-
git update-ref -d refs/heads/invalid-committer || true
454451

455452
cat >input <<INPUT_END
456453
commit refs/heads/invalid-committer
@@ -460,9 +457,9 @@ empty commit
460457
COMMIT
461458
INPUT_END
462459
test_expect_success 'B: fail on invalid committer (5)' '
460+
test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
463461
test_must_fail git fast-import <input
464462
'
465-
git update-ref -d refs/heads/invalid-committer || true
466463

467464
###
468465
### series C
@@ -914,15 +911,14 @@ g/b/h
914911
EOF
915912

916913
test_expect_success 'L: nested tree copy does not corrupt deltas' '
914+
test_when_finished "git update-ref -d refs/heads/L2" &&
917915
git fast-import <input &&
918916
git ls-tree L2 g/b/ >tmp &&
919917
cat tmp | cut -f 2 >actual &&
920918
test_cmp expect actual &&
921919
git fsck `git rev-parse L2`
922920
'
923921

924-
git update-ref -d refs/heads/L2
925-
926922
###
927923
### series M
928924
###

0 commit comments

Comments
 (0)