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 <j6t@kdbg.org> Signed-off-by: Jeff King <peff@peff.net>
Johannes Sixt committed
Nov 19, 2015 at 20:09 UTC
93e911f5ae0b262fc63898790ab40f2306fd5395
1 file changed
+16
-20
t/t9300-fast-import.sh
+16
-20
@@ -344,9 +344,9 @@ M 755 0000000000000000000000000000000000000001 zero1
344
345
INPUT_END
346
test_expect_success 'B: fail on invalid blob sha1' '
347
+ test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
348
test_must_fail git fast-import <input
349
'
349
-rm -f .git/objects/pack_* .git/objects/index_*
350
351
cat >input <<INPUT_END
352
commit TEMP_TAG
@@ -359,14 +359,13 @@ from refs/heads/master
359
360
INPUT_END
361
test_expect_success 'B: accept branch name "TEMP_TAG"' '
362
+ test_when_finished "rm -f .git/TEMP_TAG
363
+ git gc
364
+ git prune" &&
365
git fast-import <input &&
366
test -f .git/TEMP_TAG &&
367
test `git rev-parse master` = `git rev-parse TEMP_TAG^`
368
'
366
-rm -f .git/TEMP_TAG
367
-
368
-git gc 2>/dev/null >/dev/null
369
-git prune 2>/dev/null >/dev/null
369
370
cat >input <<INPUT_END
371
commit refs/heads/empty-committer-1
@@ -376,15 +375,14 @@ empty commit
375
COMMIT
376
INPUT_END
377
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" &&
381
git fast-import <input &&
382
out=$(git fsck) &&
383
echo "$out" &&
384
test -z "$out"
385
'
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
386
387
cat >input <<INPUT_END
388
commit refs/heads/empty-committer-2
@@ -394,15 +392,14 @@ empty commit
392
COMMIT
393
INPUT_END
394
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" &&
398
git fast-import <input &&
399
out=$(git fsck) &&
400
echo "$out" &&
401
test -z "$out"
402
'
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
403
404
cat >input <<INPUT_END
405
commit refs/heads/invalid-committer
@@ -412,9 +409,9 @@ empty commit
409
COMMIT
410
INPUT_END
411
test_expect_success 'B: fail on invalid committer (1)' '
412
+ test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
413
test_must_fail git fast-import <input
414
'
417
-git update-ref -d refs/heads/invalid-committer || true
415
416
cat >input <<INPUT_END
417
commit refs/heads/invalid-committer
@@ -424,9 +421,9 @@ empty commit
421
COMMIT
422
INPUT_END
423
test_expect_success 'B: fail on invalid committer (2)' '
424
+ test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
425
test_must_fail git fast-import <input
426
'
429
-git update-ref -d refs/heads/invalid-committer || true
427
428
cat >input <<INPUT_END
429
commit refs/heads/invalid-committer
@@ -436,9 +433,9 @@ empty commit
433
COMMIT
434
INPUT_END
435
test_expect_success 'B: fail on invalid committer (3)' '
436
+ test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
437
test_must_fail git fast-import <input
438
'
441
-git update-ref -d refs/heads/invalid-committer || true
439
440
cat >input <<INPUT_END
441
commit refs/heads/invalid-committer
@@ -448,9 +445,9 @@ empty commit
445
COMMIT
446
INPUT_END
447
test_expect_success 'B: fail on invalid committer (4)' '
448
+ test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
449
test_must_fail git fast-import <input
450
'
453
-git update-ref -d refs/heads/invalid-committer || true
451
452
cat >input <<INPUT_END
453
commit refs/heads/invalid-committer
@@ -460,9 +457,9 @@ empty commit
457
COMMIT
458
INPUT_END
459
test_expect_success 'B: fail on invalid committer (5)' '
460
+ test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
461
test_must_fail git fast-import <input
462
'
465
-git update-ref -d refs/heads/invalid-committer || true
463
464
###
465
### series C
@@ -914,6 +911,7 @@ g/b/h
911
EOF
912
913
test_expect_success 'L: nested tree copy does not corrupt deltas' '
914
+ test_when_finished "git update-ref -d refs/heads/L2" &&
915
git fast-import <input &&
916
git ls-tree L2 g/b/ >tmp &&
917
cat tmp | cut -f 2 >actual &&
@@ -921,8 +919,6 @@ test_expect_success 'L: nested tree copy does not corrupt deltas' '
919
git fsck `git rev-parse L2`
920
'
921
924
-git update-ref -d refs/heads/L2
925
-
922
###
923
### series M
924
###