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