Skip to content

Commit 6caa96c

Browse files
committed
t3206: test_when_finished before dirtying operations, not after
Many existing tests in this script perform operation(s) and then use test_when_finished to define how to undo the effect of the operation(s). This is backwards. When your operation(s) fail before you manage to successfully call test_when_finished (remember, that these commands must be all &&-chained, so a failure of an earlier operation mean your test_when_finished may not be executed at all). You must establish how to clean up your mess with test_when_finished before you create the mess to be cleaned up. Also make sure that the body of test_when_finished deals with case where the cruft it wants to remove failed to be created, by using "rm -f" (instead of "rm") to remove potential cruft files, and having "|| :" after "git notes remove" to remove potential cruft notes---both of these by default fail when asked to remove something that does not exist, instead of being silently idempotent no-ops. Helped-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 406f326 commit 6caa96c

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

t/t3206-range-diff.sh

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,9 @@ test_expect_success 'dual-coloring' '
533533
for prev in topic main..topic
534534
do
535535
test_expect_success "format-patch --range-diff=$prev" '
536+
test_when_finished "rm -f 000?-*" &&
536537
git format-patch --cover-letter --range-diff=$prev \
537538
main..unmodified >actual &&
538-
test_when_finished "rm 000?-*" &&
539539
test_line_count = 5 actual &&
540540
test_grep "^Range-diff:$" 0000-* &&
541541
grep "= 1: .* s/5/A" 0000-* &&
@@ -560,32 +560,32 @@ test_expect_success "explicit --no-cover-letter defeats implied --cover-letter"
560560
'
561561

562562
test_expect_success 'format-patch --range-diff as commentary' '
563+
test_when_finished "rm -f 0001-*" &&
563564
git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
564-
test_when_finished "rm 0001-*" &&
565565
test_line_count = 1 actual &&
566566
test_grep "^Range-diff:$" 0001-* &&
567567
grep "> 1: .* new message" 0001-*
568568
'
569569

570570
test_expect_success 'format-patch --range-diff reroll-count with a non-integer' '
571+
test_when_finished "rm -f v2.9-0001-*" &&
571572
git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&
572-
test_when_finished "rm v2.9-0001-*" &&
573573
test_line_count = 1 actual &&
574574
test_grep "^Range-diff:$" v2.9-0001-* &&
575575
grep "> 1: .* new message" v2.9-0001-*
576576
'
577577

578578
test_expect_success 'format-patch --range-diff reroll-count with a integer' '
579+
test_when_finished "rm -f v2-0001-*" &&
579580
git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&
580-
test_when_finished "rm v2-0001-*" &&
581581
test_line_count = 1 actual &&
582582
test_grep "^Range-diff ..* v1:$" v2-0001-* &&
583583
grep "> 1: .* new message" v2-0001-*
584584
'
585585

586586
test_expect_success 'format-patch --range-diff with v0' '
587+
test_when_finished "rm -f v0-0001-*" &&
587588
git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&
588-
test_when_finished "rm v0-0001-*" &&
589589
test_line_count = 1 actual &&
590590
test_grep "^Range-diff:$" v0-0001-* &&
591591
grep "> 1: .* new message" v0-0001-*
@@ -606,9 +606,9 @@ test_expect_success 'basic with modified format.pretty without "commit "' '
606606
'
607607

608608
test_expect_success 'range-diff compares notes by default' '
609+
test_when_finished "git notes remove topic unmodified || :" &&
609610
git notes add -m "topic note" topic &&
610611
git notes add -m "unmodified note" unmodified &&
611-
test_when_finished git notes remove topic unmodified &&
612612
git range-diff --no-color main..topic main..unmodified \
613613
>actual &&
614614
sed s/Z/\ /g >expect <<-EOF &&
@@ -630,9 +630,9 @@ test_expect_success 'range-diff compares notes by default' '
630630
'
631631

632632
test_expect_success 'range-diff with --no-notes' '
633+
test_when_finished "git notes remove topic unmodified || :" &&
633634
git notes add -m "topic note" topic &&
634635
git notes add -m "unmodified note" unmodified &&
635-
test_when_finished git notes remove topic unmodified &&
636636
git range-diff --no-color --no-notes main..topic main..unmodified \
637637
>actual &&
638638
cat >expect <<-EOF &&
@@ -645,12 +645,12 @@ test_expect_success 'range-diff with --no-notes' '
645645
'
646646

647647
test_expect_success 'range-diff with multiple --notes' '
648+
test_when_finished "git notes --ref=note1 remove topic unmodified || :" &&
648649
git notes --ref=note1 add -m "topic note1" topic &&
649650
git notes --ref=note1 add -m "unmodified note1" unmodified &&
650-
test_when_finished git notes --ref=note1 remove topic unmodified &&
651+
test_when_finished "git notes --ref=note2 remove topic unmodified || :" &&
651652
git notes --ref=note2 add -m "topic note2" topic &&
652653
git notes --ref=note2 add -m "unmodified note2" unmodified &&
653-
test_when_finished git notes --ref=note2 remove topic unmodified &&
654654
git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \
655655
>actual &&
656656
sed s/Z/\ /g >expect <<-EOF &&
@@ -678,25 +678,25 @@ test_expect_success 'range-diff with multiple --notes' '
678678

679679
# `range-diff` should act like `log` with regards to notes
680680
test_expect_success 'range-diff with --notes=custom does not show default notes' '
681+
test_when_finished "git notes remove topic unmodified || :" &&
681682
git notes add -m "topic note" topic &&
682683
git notes add -m "unmodified note" unmodified &&
684+
test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
683685
git notes --ref=custom add -m "topic note" topic &&
684686
git notes --ref=custom add -m "unmodified note" unmodified &&
685-
test_when_finished git notes remove topic unmodified &&
686-
test_when_finished git notes --ref=custom remove topic unmodified &&
687687
git range-diff --notes=custom main..topic main..unmodified \
688688
>actual &&
689689
! grep "## Notes ##" actual &&
690690
grep "## Notes (custom) ##" actual
691691
'
692692

693693
test_expect_success 'format-patch --range-diff does not compare notes by default' '
694+
test_when_finished "git notes remove topic unmodified || :" &&
694695
git notes add -m "topic note" topic &&
695696
git notes add -m "unmodified note" unmodified &&
696-
test_when_finished git notes remove topic unmodified &&
697+
test_when_finished "rm -f 000?-*" &&
697698
git format-patch --cover-letter --range-diff=$prev \
698699
main..unmodified >actual &&
699-
test_when_finished "rm 000?-*" &&
700700
test_line_count = 5 actual &&
701701
test_grep "^Range-diff:$" 0000-* &&
702702
grep "= 1: .* s/5/A" 0000-* &&
@@ -708,26 +708,26 @@ test_expect_success 'format-patch --range-diff does not compare notes by default
708708
'
709709

710710
test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '
711+
test_when_finished "git notes remove topic unmodified || :" &&
711712
git notes add -m "topic note" topic &&
712-
git notes --ref=custom add -m "topic note (custom)" topic &&
713713
git notes add -m "unmodified note" unmodified &&
714+
test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
715+
git notes --ref=custom add -m "topic note (custom)" topic &&
714716
git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
715-
test_when_finished git notes remove topic unmodified &&
716-
test_when_finished git notes --ref=custom remove topic unmodified &&
717+
test_when_finished "rm -f 000?-*" &&
717718
git format-patch --notes=custom --cover-letter --range-diff=$prev \
718719
main..unmodified >actual &&
719-
test_when_finished "rm 000?-*" &&
720720
grep "## Notes (custom) ##" 0000-* &&
721721
! grep "## Notes ##" 0000-*
722722
'
723723

724724
test_expect_success 'format-patch --range-diff with --no-notes' '
725+
test_when_finished "git notes remove topic unmodified || :" &&
725726
git notes add -m "topic note" topic &&
726727
git notes add -m "unmodified note" unmodified &&
727-
test_when_finished git notes remove topic unmodified &&
728+
test_when_finished "rm -f 000?-*" &&
728729
git format-patch --no-notes --cover-letter --range-diff=$prev \
729730
main..unmodified >actual &&
730-
test_when_finished "rm 000?-*" &&
731731
test_line_count = 5 actual &&
732732
test_grep "^Range-diff:$" 0000-* &&
733733
grep "= 1: .* s/5/A" 0000-* &&
@@ -739,12 +739,12 @@ test_expect_success 'format-patch --range-diff with --no-notes' '
739739
'
740740

741741
test_expect_success 'format-patch --range-diff with --notes' '
742+
test_when_finished "git notes remove topic unmodified || :" &&
742743
git notes add -m "topic note" topic &&
743744
git notes add -m "unmodified note" unmodified &&
744-
test_when_finished git notes remove topic unmodified &&
745+
test_when_finished "rm -f 000?-*" &&
745746
git format-patch --notes --cover-letter --range-diff=$prev \
746747
main..unmodified >actual &&
747-
test_when_finished "rm 000?-*" &&
748748
test_line_count = 5 actual &&
749749
test_grep "^Range-diff:$" 0000-* &&
750750
grep "= 1: .* s/5/A" 0000-* &&
@@ -767,13 +767,13 @@ test_expect_success 'format-patch --range-diff with --notes' '
767767
'
768768

769769
test_expect_success 'format-patch --range-diff with format.notes config' '
770+
test_when_finished "git notes remove topic unmodified || :" &&
770771
git notes add -m "topic note" topic &&
771772
git notes add -m "unmodified note" unmodified &&
772-
test_when_finished git notes remove topic unmodified &&
773773
test_config format.notes true &&
774+
test_when_finished "rm -f 000?-*" &&
774775
git format-patch --cover-letter --range-diff=$prev \
775776
main..unmodified >actual &&
776-
test_when_finished "rm 000?-*" &&
777777
test_line_count = 5 actual &&
778778
test_grep "^Range-diff:$" 0000-* &&
779779
grep "= 1: .* s/5/A" 0000-* &&
@@ -796,15 +796,15 @@ test_expect_success 'format-patch --range-diff with format.notes config' '
796796
'
797797

798798
test_expect_success 'format-patch --range-diff with multiple notes' '
799+
test_when_finished "git notes --ref=note1 remove topic unmodified || :" &&
799800
git notes --ref=note1 add -m "topic note1" topic &&
800801
git notes --ref=note1 add -m "unmodified note1" unmodified &&
801-
test_when_finished git notes --ref=note1 remove topic unmodified &&
802+
test_when_finished "git notes --ref=note2 remove topic unmodified || :" &&
802803
git notes --ref=note2 add -m "topic note2" topic &&
803804
git notes --ref=note2 add -m "unmodified note2" unmodified &&
804-
test_when_finished git notes --ref=note2 remove topic unmodified &&
805+
test_when_finished "rm -f 000?-*" &&
805806
git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
806807
main..unmodified >actual &&
807-
test_when_finished "rm 000?-*" &&
808808
test_line_count = 5 actual &&
809809
test_grep "^Range-diff:$" 0000-* &&
810810
grep "= 1: .* s/5/A" 0000-* &&

0 commit comments

Comments
 (0)