]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4019-diff-wserror.sh
t4202 (log): Replace '<git-command> || :' with test_might_fail
[thirdparty/git.git] / t / t4019-diff-wserror.sh
CommitLineData
49e703af
JH
1#!/bin/sh
2
3test_description='diff whitespace error detection'
4
5. ./test-lib.sh
6
7test_expect_success setup '
8
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 &&
b2979ff5 15 echo "Carriage ReturnQ" | tr Q "\015" >>F &&
04c6e9e9
JH
16 echo "No problem" >>F &&
17 echo >>F
49e703af
JH
18
19'
20
21blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
22
eca4460e
JH
23printf "\033[%s" "$blue_grep" >check-grep
24if (grep "$blue_grep" <check-grep | grep "$blue_grep") >/dev/null 2>&1
25then
26 grep_a=grep
27elif (grep -a "$blue_grep" <check-grep | grep -a "$blue_grep") >/dev/null 2>&1
28then
29 grep_a='grep -a'
30else
31 grep_a=grep ;# expected to fail...
32fi
33rm -f check-grep
34
35prepare_output () {
36 git diff --color >output
37 $grep_a "$blue_grep" output >error
38 $grep_a -v "$blue_grep" output >normal
39}
40
49e703af
JH
41test_expect_success default '
42
eca4460e 43 prepare_output
49e703af
JH
44
45 grep Eight normal >/dev/null &&
46 grep HT error >/dev/null &&
47 grep With error >/dev/null &&
b2979ff5 48 grep Return error >/dev/null &&
49e703af
JH
49 grep No normal >/dev/null
50
51'
52
53test_expect_success 'without -trail' '
54
55 git config core.whitespace -trail
eca4460e 56 prepare_output
49e703af
JH
57
58 grep Eight normal >/dev/null &&
59 grep HT error >/dev/null &&
60 grep With normal >/dev/null &&
b2979ff5 61 grep Return normal >/dev/null &&
49e703af
JH
62 grep No normal >/dev/null
63
64'
65
cf1b7869
JH
66test_expect_success 'without -trail (attribute)' '
67
68 git config --unset core.whitespace
69 echo "F whitespace=-trail" >.gitattributes
eca4460e 70 prepare_output
cf1b7869
JH
71
72 grep Eight normal >/dev/null &&
73 grep HT error >/dev/null &&
74 grep With normal >/dev/null &&
b2979ff5 75 grep Return normal >/dev/null &&
cf1b7869
JH
76 grep No normal >/dev/null
77
78'
79
49e703af
JH
80test_expect_success 'without -space' '
81
cf1b7869 82 rm -f .gitattributes
49e703af 83 git config core.whitespace -space
eca4460e 84 prepare_output
49e703af
JH
85
86 grep Eight normal >/dev/null &&
87 grep HT normal >/dev/null &&
88 grep With error >/dev/null &&
b2979ff5 89 grep Return error >/dev/null &&
49e703af
JH
90 grep No normal >/dev/null
91
92'
93
cf1b7869
JH
94test_expect_success 'without -space (attribute)' '
95
96 git config --unset core.whitespace
97 echo "F whitespace=-space" >.gitattributes
eca4460e 98 prepare_output
cf1b7869
JH
99
100 grep Eight normal >/dev/null &&
101 grep HT normal >/dev/null &&
102 grep With error >/dev/null &&
b2979ff5 103 grep Return error >/dev/null &&
cf1b7869
JH
104 grep No normal >/dev/null
105
106'
107
49e703af
JH
108test_expect_success 'with indent-non-tab only' '
109
cf1b7869 110 rm -f .gitattributes
49e703af 111 git config core.whitespace indent,-trailing,-space
eca4460e 112 prepare_output
49e703af
JH
113
114 grep Eight error >/dev/null &&
115 grep HT normal >/dev/null &&
116 grep With normal >/dev/null &&
b2979ff5 117 grep Return normal >/dev/null &&
49e703af
JH
118 grep No normal >/dev/null
119
120'
121
cf1b7869
JH
122test_expect_success 'with indent-non-tab only (attribute)' '
123
124 git config --unset core.whitespace
125 echo "F whitespace=indent,-trailing,-space" >.gitattributes
eca4460e 126 prepare_output
cf1b7869
JH
127
128 grep Eight error >/dev/null &&
129 grep HT normal >/dev/null &&
130 grep With normal >/dev/null &&
b2979ff5
JH
131 grep Return normal >/dev/null &&
132 grep No normal >/dev/null
133
134'
135
136test_expect_success 'with cr-at-eol' '
137
138 rm -f .gitattributes
139 git config core.whitespace cr-at-eol
eca4460e 140 prepare_output
b2979ff5
JH
141
142 grep Eight normal >/dev/null &&
143 grep HT error >/dev/null &&
144 grep With error >/dev/null &&
145 grep Return normal >/dev/null &&
146 grep No normal >/dev/null
147
148'
149
150test_expect_success 'with cr-at-eol (attribute)' '
151
152 git config --unset core.whitespace
153 echo "F whitespace=trailing,cr-at-eol" >.gitattributes
eca4460e 154 prepare_output
b2979ff5
JH
155
156 grep Eight normal >/dev/null &&
157 grep HT error >/dev/null &&
158 grep With error >/dev/null &&
159 grep Return normal >/dev/null &&
cf1b7869
JH
160 grep No normal >/dev/null
161
162'
163
04c6e9e9
JH
164test_expect_success 'trailing empty lines (1)' '
165
166 rm -f .gitattributes &&
167 test_must_fail git diff --check >output &&
5b5061ef 168 grep "new blank line at" output &&
04c6e9e9
JH
169 grep "trailing whitespace" output
170
171'
172
173test_expect_success 'trailing empty lines (2)' '
174
175 echo "F -whitespace" >.gitattributes &&
176 git diff --check >output &&
177 ! test -s output
178
179'
180
39280970
JH
181test_expect_success 'do not color trailing cr in context' '
182 git config --unset core.whitespace
183 rm -f .gitattributes &&
184 echo AAAQ | tr Q "\015" >G &&
185 git add G &&
186 echo BBBQ | tr Q "\015" >>G
187 git diff --color G | tr "\015" Q >output &&
188 grep "BBB.*${blue_grep}Q" output &&
189 grep "AAA.*\[mQ" output
190
191'
192
690ed843
JH
193test_expect_success 'color new trailing blank lines' '
194 { echo a; echo b; echo; echo; } >x &&
195 git add x &&
d68fe26f 196 { echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
690ed843 197 git diff --color x >output &&
eca4460e 198 cnt=$($grep_a "${blue_grep}" output | wc -l) &&
690ed843
JH
199 test $cnt = 2
200'
201
49e703af 202test_done