]>
Commit | Line | Data |
---|---|---|
f258475a JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Johannes E. Schindelin | |
4 | # | |
5 | ||
6 | test_description='Test custom diff function name patterns' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
f1b75fba JS |
10 | test_expect_success 'setup' ' |
11 | # a non-trivial custom pattern | |
12 | git config diff.custom1.funcname "!static | |
13 | !String | |
14 | [^ ].*s.*" && | |
15 | ||
16 | # a custom pattern which matches to end of line | |
17 | git config diff.custom2.funcname "......Beer\$" && | |
18 | ||
19 | # alternation in pattern | |
20 | git config diff.custom3.funcname "Beer$" && | |
ad5070fb JS |
21 | git config diff.custom3.xfuncname "^[ ]*((public|static).*)$" && |
22 | ||
23 | # for regexp compilation tests | |
24 | echo A >A.java && | |
25 | echo B >B.java | |
f1b75fba | 26 | ' |
d64d6cdc | 27 | |
bfa7d014 JS |
28 | diffpatterns=" |
29 | ada | |
30 | bibtex | |
31 | cpp | |
32 | csharp | |
0719f3ee | 33 | css |
bfa7d014 | 34 | fortran |
69f9c87d | 35 | fountain |
bfa7d014 JS |
36 | html |
37 | java | |
38 | matlab | |
39 | objc | |
40 | pascal | |
41 | perl | |
42 | php | |
43 | python | |
44 | ruby | |
45 | tex | |
f1b75fba JS |
46 | custom1 |
47 | custom2 | |
48 | custom3 | |
bfa7d014 JS |
49 | " |
50 | ||
51 | for p in $diffpatterns | |
e3bf5e43 BC |
52 | do |
53 | test_expect_success "builtin $p pattern compiles" ' | |
5b5e4594 | 54 | echo "*.java diff=$p" >.gitattributes && |
d64d6cdc | 55 | test_expect_code 1 git diff --no-index \ |
ad5070fb | 56 | A.java B.java 2>msg && |
41ca19b6 JS |
57 | test_i18ngrep ! fatal msg && |
58 | test_i18ngrep ! error msg | |
e3bf5e43 | 59 | ' |
bff42061 | 60 | test_expect_success "builtin $p wordRegex pattern compiles" ' |
5b5e4594 | 61 | echo "*.java diff=$p" >.gitattributes && |
d64d6cdc | 62 | test_expect_code 1 git diff --no-index --word-diff \ |
ad5070fb | 63 | A.java B.java 2>msg && |
41ca19b6 JS |
64 | test_i18ngrep ! fatal msg && |
65 | test_i18ngrep ! error msg | |
bff42061 | 66 | ' |
e3bf5e43 BC |
67 | done |
68 | ||
f258475a | 69 | test_expect_success 'last regexp must not be negated' ' |
ad5070fb | 70 | echo "*.java diff=java" >.gitattributes && |
f792a0b8 | 71 | test_config diff.java.funcname "!static" && |
ad5070fb JS |
72 | test_expect_code 128 git diff --no-index A.java B.java 2>msg && |
73 | test_i18ngrep ": Last expression must not be negated:" msg | |
f258475a JH |
74 | ' |
75 | ||
bfa7d014 JS |
76 | test_expect_success 'setup hunk header tests' ' |
77 | for i in $diffpatterns | |
78 | do | |
79 | echo "$i-* diff=$i" | |
80 | done > .gitattributes && | |
81 | ||
82 | # add all test files to the index | |
83 | ( | |
84 | cd "$TEST_DIRECTORY"/t4018 && | |
85 | git --git-dir="$TRASH_DIRECTORY/.git" add . | |
86 | ) && | |
87 | ||
88 | # place modified files in the worktree | |
89 | for i in $(git ls-files) | |
90 | do | |
91 | sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1 | |
92 | done | |
93 | ' | |
94 | ||
95 | # check each individual file | |
96 | for i in $(git ls-files) | |
97 | do | |
98 | if grep broken "$i" >/dev/null 2>&1 | |
99 | then | |
100 | result=failure | |
101 | else | |
102 | result=success | |
103 | fi | |
104 | test_expect_$result "hunk header: $i" " | |
105 | test_when_finished 'cat actual' && # for debugging only | |
106 | git diff -U1 $i >actual && | |
107 | grep '@@ .* @@.*RIGHT' actual | |
108 | " | |
109 | done | |
110 | ||
f258475a | 111 | test_done |