@matheusbsbs / matheus-bagliano / commits / f817546652
Fork 0

Add tests for "git diff --check" with core.whitespace options

Make sure that "git diff --check" does the right thing when the core.whitespace options are set. While we are at it, correct many uses of test_expect_failure that ran sequence of commands. Signed-off-by: Wincent Colaiuta <win@wincent.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Wincent Colaiuta committed Dec 13, 2007 at 14:32 UTC f817546652812ad5f20a8ab4a4a7290a9759ac4e
1 file changed +70 -20
t/t4015-diff-whitespace.sh
+70 -20
@@ -133,18 +133,18 @@ test_expect_success 'check with no whitespace errors' '
133
134 '
135
136 -test_expect_failure 'check with trailing whitespace' '
136 +test_expect_success 'check with trailing whitespace' '
137
138 echo "foo(); " > x &&
139 - git diff --check
139 + ! git diff --check
140
141 '
142
143 -test_expect_failure 'check with space before tab in indent' '
143 +test_expect_success 'check with space before tab in indent' '
144
145 # indent has space followed by hard tab
146 echo " foo();" > x &&
147 - git diff --check
147 + ! git diff --check
148
149 '
150
@@ -169,20 +169,20 @@ test_expect_success 'check staged with no whitespace errors' '
169
170 '
171
172 -test_expect_failure 'check staged with trailing whitespace' '
172 +test_expect_success 'check staged with trailing whitespace' '
173
174 echo "foo(); " > x &&
175 git add x &&
176 - git diff --cached --check
176 + ! git diff --cached --check
177
178 '
179
180 -test_expect_failure 'check staged with space before tab in indent' '
180 +test_expect_success 'check staged with space before tab in indent' '
181
182 # indent has space followed by hard tab
183 echo " foo();" > x &&
184 git add x &&
185 - git diff --cached --check
185 + ! git diff --cached --check
186
187 '
188
@@ -194,20 +194,20 @@ test_expect_success 'check with no whitespace errors (diff-index)' '
194
195 '
196
197 -test_expect_failure 'check with trailing whitespace (diff-index)' '
197 +test_expect_success 'check with trailing whitespace (diff-index)' '
198
199 echo "foo(); " > x &&
200 git add x &&
201 - git diff-index --check HEAD
201 + ! git diff-index --check HEAD
202
203 '
204
205 -test_expect_failure 'check with space before tab in indent (diff-index)' '
205 +test_expect_success 'check with space before tab in indent (diff-index)' '
206
207 # indent has space followed by hard tab
208 echo " foo();" > x &&
209 git add x &&
210 - git diff-index --check HEAD
210 + ! git diff-index --check HEAD
211
212 '
213
@@ -219,20 +219,20 @@ test_expect_success 'check staged with no whitespace errors (diff-index)' '
219
220 '
221
222 -test_expect_failure 'check staged with trailing whitespace (diff-index)' '
222 +test_expect_success 'check staged with trailing whitespace (diff-index)' '
223
224 echo "foo(); " > x &&
225 git add x &&
226 - git diff-index --cached --check HEAD
226 + ! git diff-index --cached --check HEAD
227
228 '
229
230 -test_expect_failure 'check staged with space before tab in indent (diff-index)' '
230 +test_expect_success 'check staged with space before tab in indent (diff-index)' '
231
232 # indent has space followed by hard tab
233 echo " foo();" > x &&
234 git add x &&
235 - git diff-index --cached --check HEAD
235 + ! git diff-index --cached --check HEAD
236
237 '
238
@@ -244,20 +244,70 @@ test_expect_success 'check with no whitespace errors (diff-tree)' '
244
245 '
246
247 -test_expect_failure 'check with trailing whitespace (diff-tree)' '
247 +test_expect_success 'check with trailing whitespace (diff-tree)' '
248
249 echo "foo(); " > x &&
250 git commit -m "another commit" x &&
251 - git diff-tree --check HEAD^ HEAD
251 + ! git diff-tree --check HEAD^ HEAD
252
253 '
254
255 -test_expect_failure 'check with space before tab in indent (diff-tree)' '
255 +test_expect_success 'check with space before tab in indent (diff-tree)' '
256
257 # indent has space followed by hard tab
258 echo " foo();" > x &&
259 git commit -m "yet another" x &&
260 - git diff-tree --check HEAD^ HEAD
260 + ! git diff-tree --check HEAD^ HEAD
261 +
262 +'
263 +
264 +test_expect_success 'check trailing whitespace (trailing-space: off)' '
265 +
266 + git config core.whitespace "-trailing-space" &&
267 + echo "foo (); " > x &&
268 + git diff --check
269 +
270 +'
271 +
272 +test_expect_success 'check trailing whitespace (trailing-space: on)' '
273 +
274 + git config core.whitespace "trailing-space" &&
275 + echo "foo (); " > x &&
276 + ! git diff --check
277 +
278 +'
279 +
280 +test_expect_success 'check space before tab in indent (space-before-tab: off)' '
281 +
282 + # indent contains space followed by HT
283 + git config core.whitespace "-space-before-tab" &&
284 + echo " foo ();" > x &&
285 + git diff --check
286 +
287 +'
288 +
289 +test_expect_success 'check space before tab in indent (space-before-tab: on)' '
290 +
291 + # indent contains space followed by HT
292 + git config core.whitespace "space-before-tab" &&
293 + echo " foo (); " > x &&
294 + ! git diff --check
295 +
296 +'
297 +
298 +test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' '
299 +
300 + git config core.whitespace "-indent-with-non-tab"
301 + echo " foo ();" > x &&
302 + git diff --check
303 +
304 +'
305 +
306 +test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' '
307 +
308 + git config core.whitespace "indent-with-non-tab" &&
309 + echo " foo ();" > x &&
310 + ! git diff --check
311
312 '
313