3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description
='Test custom diff function name patterns'
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success
'setup' '
12 # a non-trivial custom pattern
13 git config diff.custom1.funcname "!static
17 # a custom pattern which matches to end of line
18 git config diff.custom2.funcname "......Beer\$" &&
20 # alternation in pattern
21 git config diff.custom3.funcname "Beer$" &&
22 git config diff.custom3.xfuncname "^[ ]*((public|static).*)$" &&
24 # for regexp compilation tests
29 test_expect_success
'setup: test-tool userdiff' '
30 # Make sure additions to builtin_drivers are sorted
31 test_when_finished "rm builtin-drivers.sorted" &&
32 test-tool userdiff list-builtin-drivers >builtin-drivers &&
33 test_file_not_empty builtin-drivers &&
34 sort <builtin-drivers >builtin-drivers.sorted &&
35 test_cmp builtin-drivers.sorted builtin-drivers &&
37 # Ditto, but "custom" requires the .git directory and config
38 # to be setup and read.
39 test_when_finished "rm custom-drivers.sorted" &&
40 test-tool userdiff list-custom-drivers >custom-drivers &&
41 test_file_not_empty custom-drivers &&
42 sort <custom-drivers >custom-drivers.sorted &&
43 test_cmp custom-drivers.sorted custom-drivers
47 $(cat builtin-drivers)
51 for p
in $diffpatterns
53 test_expect_success
"builtin $p pattern compiles" '
54 echo "*.java diff=$p" >.gitattributes &&
55 test_expect_code 1 git diff --no-index \
56 A.java B.java 2>msg &&
57 test_grep ! fatal msg &&
60 test_expect_success
"builtin $p wordRegex pattern compiles" '
61 echo "*.java diff=$p" >.gitattributes &&
62 test_expect_code 1 git diff --no-index --word-diff \
63 A.java B.java 2>msg &&
64 test_grep ! fatal msg &&
68 test_expect_success
"builtin $p pattern compiles on bare repo with --attr-source" '
69 test_when_finished "rm -rf bare.git" &&
70 git checkout -B master &&
72 echo "*.java diff=notexist" >.gitattributes &&
73 git add .gitattributes &&
74 git commit -am "changing gitattributes" &&
75 git checkout -B branchA &&
76 echo "*.java diff=$p" >.gitattributes &&
77 git add .gitattributes &&
78 git commit -am "changing gitattributes" &&
79 git clone --bare --no-local . bare.git &&
80 git -C bare.git symbolic-ref HEAD refs/heads/master &&
81 test_expect_code 1 git -C bare.git --attr-source=branchA \
82 diff --exit-code HEAD:A.java HEAD:B.java 2>msg &&
83 test_grep ! fatal msg &&
88 test_expect_success
'last regexp must not be negated' '
89 echo "*.java diff=java" >.gitattributes &&
90 test_config diff.java.funcname "!static" &&
91 test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
92 test_grep ": Last expression must not be negated:" msg
95 test_expect_success
'setup hunk header tests' '
96 for i in $diffpatterns
98 echo "$i-* diff=$i" || return 1
99 done > .gitattributes &&
101 # add all test files to the index
103 cd "$TEST_DIRECTORY"/t4018 &&
104 git --git-dir="$TRASH_DIRECTORY/.git" add .
107 # place modified files in the worktree
108 for i in $(git ls-files)
110 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
114 # check each individual file
115 for i
in $
(git ls-files
)
117 test_expect_success
"hunk header: $i" "
118 git diff -U1 $i >actual &&
119 grep '@@ .* @@.*RIGHT' actual