t4013: add tests for diff prefix options
We don't have any specific test coverage of diff's various prefix options. We do incidentally invoke them in a few places, but it's worth having a more thorough set of tests that covers all of the effects we expect to see, and that the options kick in at the appropriate times. This will be especially useful as the next patch adds more options. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Mar 9, 2023 at 01:07 UTC
7c03d0db8807d303540297432455adfa1c45b05e
1 file changed
+32
t/t4013-diff-various.sh
+32
@@ -616,4 +616,36 @@ test_expect_success 'diff -I<regex>: detect malformed regex' '
616
test_i18ngrep "invalid regex given to -I: " error
617
'
618
619
+# check_prefix <patch> <src> <dst>
620
+# check only lines with paths to avoid dependency on exact oid/contents
621
+check_prefix () {
622
+ grep -E '^(diff|---|\+\+\+) ' "$1" >actual.paths &&
623
+ cat >expect <<-EOF &&
624
+ diff --git $2 $3
625
+ --- $2
626
+ +++ $3
627
+ EOF
628
+ test_cmp expect actual.paths
629
+}
630
+
631
+test_expect_success 'diff-files does not respect diff.noprefix' '
632
+ git -c diff.noprefix diff-files -p >actual &&
633
+ check_prefix actual a/file0 b/file0
634
+'
635
+
636
+test_expect_success 'diff-files respects --no-prefix' '
637
+ git diff-files -p --no-prefix >actual &&
638
+ check_prefix actual file0 file0
639
+'
640
+
641
+test_expect_success 'diff respects diff.noprefix' '
642
+ git -c diff.noprefix diff >actual &&
643
+ check_prefix actual file0 file0
644
+'
645
+
646
+test_expect_success 'diff respects diff.mnemonicprefix' '
647
+ git -c diff.mnemonicprefix diff >actual &&
648
+ check_prefix actual i/file0 w/file0
649
+'
650
+
651
test_done