Merge branch 'mm/phrase-remote-tracking'
[git/kirr.git] / t / t4019-diff-wserror.sh
blobf7c85ec604df5e037990065ab9d3d82d86587076
1 #!/bin/sh
3 test_description='diff whitespace error detection'
5 . ./test-lib.sh
7 test_expect_success setup '
9 git config diff.color.whitespace "blue reverse" &&
10 >F &&
11 git add F &&
12 echo " Eight SP indent" >>F &&
13 echo " HT and SP indent" >>F &&
14 echo "With trailing SP " >>F &&
15 echo "Carriage ReturnQ" | tr Q "\015" >>F &&
16 echo "No problem" >>F &&
17 echo >>F
21 blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
23 printf "\033[%s" "$blue_grep" >check-grep
24 if (grep "$blue_grep" <check-grep | grep "$blue_grep") >/dev/null 2>&1
25 then
26 grep_a=grep
27 elif (grep -a "$blue_grep" <check-grep | grep -a "$blue_grep") >/dev/null 2>&1
28 then
29 grep_a='grep -a'
30 else
31 grep_a=grep ;# expected to fail...
33 rm -f check-grep
35 prepare_output () {
36 git diff --color >output
37 $grep_a "$blue_grep" output >error
38 $grep_a -v "$blue_grep" output >normal
39 return 0
42 test_expect_success default '
44 prepare_output &&
46 grep Eight normal >/dev/null &&
47 grep HT error >/dev/null &&
48 grep With error >/dev/null &&
49 grep Return error >/dev/null &&
50 grep No normal >/dev/null
54 test_expect_success 'without -trail' '
56 git config core.whitespace -trail &&
57 prepare_output &&
59 grep Eight normal >/dev/null &&
60 grep HT error >/dev/null &&
61 grep With normal >/dev/null &&
62 grep Return normal >/dev/null &&
63 grep No normal >/dev/null
67 test_expect_success 'without -trail (attribute)' '
69 test_might_fail git config --unset core.whitespace &&
70 echo "F whitespace=-trail" >.gitattributes &&
71 prepare_output &&
73 grep Eight normal >/dev/null &&
74 grep HT error >/dev/null &&
75 grep With normal >/dev/null &&
76 grep Return normal >/dev/null &&
77 grep No normal >/dev/null
81 test_expect_success 'without -space' '
83 rm -f .gitattributes &&
84 git config core.whitespace -space &&
85 prepare_output &&
87 grep Eight normal >/dev/null &&
88 grep HT normal >/dev/null &&
89 grep With error >/dev/null &&
90 grep Return error >/dev/null &&
91 grep No normal >/dev/null
95 test_expect_success 'without -space (attribute)' '
97 test_might_fail git config --unset core.whitespace &&
98 echo "F whitespace=-space" >.gitattributes &&
99 prepare_output &&
101 grep Eight normal >/dev/null &&
102 grep HT normal >/dev/null &&
103 grep With error >/dev/null &&
104 grep Return error >/dev/null &&
105 grep No normal >/dev/null
109 test_expect_success 'with indent-non-tab only' '
111 rm -f .gitattributes &&
112 git config core.whitespace indent,-trailing,-space &&
113 prepare_output &&
115 grep Eight error >/dev/null &&
116 grep HT normal >/dev/null &&
117 grep With normal >/dev/null &&
118 grep Return normal >/dev/null &&
119 grep No normal >/dev/null
123 test_expect_success 'with indent-non-tab only (attribute)' '
125 test_might_fail git config --unset core.whitespace &&
126 echo "F whitespace=indent,-trailing,-space" >.gitattributes &&
127 prepare_output &&
129 grep Eight error >/dev/null &&
130 grep HT normal >/dev/null &&
131 grep With normal >/dev/null &&
132 grep Return normal >/dev/null &&
133 grep No normal >/dev/null
137 test_expect_success 'with cr-at-eol' '
139 rm -f .gitattributes &&
140 git config core.whitespace cr-at-eol &&
141 prepare_output &&
143 grep Eight normal >/dev/null &&
144 grep HT error >/dev/null &&
145 grep With error >/dev/null &&
146 grep Return normal >/dev/null &&
147 grep No normal >/dev/null
151 test_expect_success 'with cr-at-eol (attribute)' '
153 test_might_fail git config --unset core.whitespace &&
154 echo "F whitespace=trailing,cr-at-eol" >.gitattributes &&
155 prepare_output &&
157 grep Eight normal >/dev/null &&
158 grep HT error >/dev/null &&
159 grep With error >/dev/null &&
160 grep Return normal >/dev/null &&
161 grep No normal >/dev/null
165 test_expect_success 'trailing empty lines (1)' '
167 rm -f .gitattributes &&
168 test_must_fail git diff --check >output &&
169 grep "new blank line at" output &&
170 grep "trailing whitespace" output
174 test_expect_success 'trailing empty lines (2)' '
176 echo "F -whitespace" >.gitattributes &&
177 git diff --check >output &&
178 ! test -s output
182 test_expect_success 'do not color trailing cr in context' '
183 test_might_fail git config --unset core.whitespace &&
184 rm -f .gitattributes &&
185 echo AAAQ | tr Q "\015" >G &&
186 git add G &&
187 echo BBBQ | tr Q "\015" >>G &&
188 git diff --color G | tr "\015" Q >output &&
189 grep "BBB.*${blue_grep}Q" output &&
190 grep "AAA.*\[mQ" output
194 test_expect_success 'color new trailing blank lines' '
195 { echo a; echo b; echo; echo; } >x &&
196 git add x &&
197 { echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
198 git diff --color x >output &&
199 cnt=$($grep_a "${blue_grep}" output | wc -l) &&
200 test $cnt = 2
203 test_done