]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t4013: add tests for diff prefix options
authorJeff King <peff@peff.net>
Thu, 9 Mar 2023 06:07:45 +0000 (01:07 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Mar 2023 16:32:19 +0000 (08:32 -0800)
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>
t/t4013-diff-various.sh

index dfcf3a0aaae3e2a72f6f41023b01c639a99c2f44..0bc695798983157827ea29c242d17411c127aba9 100755 (executable)
@@ -616,4 +616,36 @@ test_expect_success 'diff -I<regex>: detect malformed regex' '
        test_i18ngrep "invalid regex given to -I: " error
 '
 
+# check_prefix <patch> <src> <dst>
+# check only lines with paths to avoid dependency on exact oid/contents
+check_prefix () {
+       grep -E '^(diff|---|\+\+\+) ' "$1" >actual.paths &&
+       cat >expect <<-EOF &&
+       diff --git $2 $3
+       --- $2
+       +++ $3
+       EOF
+       test_cmp expect actual.paths
+}
+
+test_expect_success 'diff-files does not respect diff.noprefix' '
+       git -c diff.noprefix diff-files -p >actual &&
+       check_prefix actual a/file0 b/file0
+'
+
+test_expect_success 'diff-files respects --no-prefix' '
+       git diff-files -p --no-prefix >actual &&
+       check_prefix actual file0 file0
+'
+
+test_expect_success 'diff respects diff.noprefix' '
+       git -c diff.noprefix diff >actual &&
+       check_prefix actual file0 file0
+'
+
+test_expect_success 'diff respects diff.mnemonicprefix' '
+       git -c diff.mnemonicprefix diff >actual &&
+       check_prefix actual i/file0 w/file0
+'
+
 test_done