Skip to content

Commit 7c03d0d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6799aad commit 7c03d0d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

t/t4013-diff-various.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,36 @@ test_expect_success 'diff -I<regex>: detect malformed regex' '
616616
test_i18ngrep "invalid regex given to -I: " error
617617
'
618618

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+
619651
test_done

0 commit comments

Comments
 (0)