Merge branch 'js/mingw-spawn-with-spaces-in-path'
[git] / t / t4018-diff-funcname.sh
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
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$" &&
21         git config diff.custom3.xfuncname "^[   ]*((public|static).*)$" &&
22
23         # for regexp compilation tests
24         echo A >A.java &&
25         echo B >B.java
26 '
27
28 diffpatterns="
29         ada
30         bibtex
31         cpp
32         csharp
33         css
34         dts
35         fortran
36         fountain
37         golang
38         html
39         java
40         matlab
41         objc
42         pascal
43         perl
44         php
45         python
46         ruby
47         rust
48         tex
49         custom1
50         custom2
51         custom3
52 "
53
54 for p in $diffpatterns
55 do
56         test_expect_success "builtin $p pattern compiles" '
57                 echo "*.java diff=$p" >.gitattributes &&
58                 test_expect_code 1 git diff --no-index \
59                         A.java B.java 2>msg &&
60                 test_i18ngrep ! fatal msg &&
61                 test_i18ngrep ! error msg
62         '
63         test_expect_success "builtin $p wordRegex pattern compiles" '
64                 echo "*.java diff=$p" >.gitattributes &&
65                 test_expect_code 1 git diff --no-index --word-diff \
66                         A.java B.java 2>msg &&
67                 test_i18ngrep ! fatal msg &&
68                 test_i18ngrep ! error msg
69         '
70 done
71
72 test_expect_success 'last regexp must not be negated' '
73         echo "*.java diff=java" >.gitattributes &&
74         test_config diff.java.funcname "!static" &&
75         test_expect_code 128 git diff --no-index A.java B.java 2>msg &&
76         test_i18ngrep ": Last expression must not be negated:" msg
77 '
78
79 test_expect_success 'setup hunk header tests' '
80         for i in $diffpatterns
81         do
82                 echo "$i-* diff=$i"
83         done > .gitattributes &&
84
85         # add all test files to the index
86         (
87                 cd "$TEST_DIRECTORY"/t4018 &&
88                 git --git-dir="$TRASH_DIRECTORY/.git" add .
89         ) &&
90
91         # place modified files in the worktree
92         for i in $(git ls-files)
93         do
94                 sed -e "s/ChangeMe/IWasChanged/" <"$TEST_DIRECTORY/t4018/$i" >"$i" || return 1
95         done
96 '
97
98 # check each individual file
99 for i in $(git ls-files)
100 do
101         if grep broken "$i" >/dev/null 2>&1
102         then
103                 result=failure
104         else
105                 result=success
106         fi
107         test_expect_$result "hunk header: $i" "
108                 test_when_finished 'cat actual' &&      # for debugging only
109                 git diff -U1 $i >actual &&
110                 grep '@@ .* @@.*RIGHT' actual
111         "
112 done
113
114 test_done