t0020: use modern test_* helpers
This test contains a lot of hand-rolled messages to show when the test fails. We can omit most of these by using "verbose" and "test_must_fail". A few of them are for update-index, but we can assume it produces reasonable error messages when it fails. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Mar 20, 2015 at 06:13 UTC
9157c5cb0968f1d97bf4a79b8622a9601387a368
1 file changed
+28
-116
t/t0020-crlf.sh
+28
-116
@@ -104,18 +104,12 @@ test_expect_success 'update with autocrlf=input' '
104
for f in one dir/two
105
do
106
append_cr <$f >tmp && mv -f tmp $f &&
107
- git update-index -- $f || {
108
- echo Oops
109
- false
110
- break
111
- }
107
+ git update-index -- $f ||
108
+ break
109
done &&
110
111
differs=$(git diff-index --cached HEAD) &&
115
- test -z "$differs" || {
116
- echo Oops "$differs"
117
- false
118
- }
112
+ verbose test -z "$differs"
113
114
'
115
@@ -128,18 +122,12 @@ test_expect_success 'update with autocrlf=true' '
122
for f in one dir/two
123
do
124
append_cr <$f >tmp && mv -f tmp $f &&
131
- git update-index -- $f || {
132
- echo "Oops $f"
133
- false
134
- break
135
- }
125
+ git update-index -- $f ||
126
+ break
127
done &&
128
129
differs=$(git diff-index --cached HEAD) &&
139
- test -z "$differs" || {
140
- echo Oops "$differs"
141
- false
142
- }
130
+ verbose test -z "$differs"
131
132
'
133
@@ -152,19 +140,13 @@ test_expect_success 'checkout with autocrlf=true' '
140
for f in one dir/two
141
do
142
remove_cr <"$f" >tmp && mv -f tmp $f &&
155
- git update-index -- $f || {
156
- echo "Eh? $f"
157
- false
158
- break
159
- }
143
+ verbose git update-index -- $f ||
144
+ break
145
done &&
146
test "$one" = $(git hash-object --stdin <one) &&
147
test "$two" = $(git hash-object --stdin <dir/two) &&
148
differs=$(git diff-index --cached HEAD) &&
164
- test -z "$differs" || {
165
- echo Oops "$differs"
166
- false
167
- }
149
+ verbose test -z "$differs"
150
'
151
152
test_expect_success 'checkout with autocrlf=input' '
@@ -187,10 +169,7 @@ test_expect_success 'checkout with autocrlf=input' '
169
test "$one" = $(git hash-object --stdin <one) &&
170
test "$two" = $(git hash-object --stdin <dir/two) &&
171
differs=$(git diff-index --cached HEAD) &&
190
- test -z "$differs" || {
191
- echo Oops "$differs"
192
- false
193
- }
172
+ verbose test -z "$differs"
173
'
174
175
test_expect_success 'apply patch (autocrlf=input)' '
@@ -200,10 +179,7 @@ test_expect_success 'apply patch (autocrlf=input)' '
179
git read-tree --reset -u HEAD &&
180
181
git apply patch.file &&
203
- test "$patched" = "$(git hash-object --stdin <one)" || {
204
- echo "Eh? apply without index"
205
- false
206
- }
182
+ verbose test "$patched" = "$(git hash-object --stdin <one)"
183
'
184
185
test_expect_success 'apply patch --cached (autocrlf=input)' '
@@ -213,10 +189,7 @@ test_expect_success 'apply patch --cached (autocrlf=input)' '
189
git read-tree --reset -u HEAD &&
190
191
git apply --cached patch.file &&
216
- test "$patched" = $(git rev-parse :one) || {
217
- echo "Eh? apply with --cached"
218
- false
219
- }
192
+ verbose test "$patched" = $(git rev-parse :one)
193
'
194
195
test_expect_success 'apply patch --index (autocrlf=input)' '
@@ -226,11 +199,8 @@ test_expect_success 'apply patch --index (autocrlf=input)' '
199
git read-tree --reset -u HEAD &&
200
201
git apply --index patch.file &&
229
- test "$patched" = $(git rev-parse :one) &&
230
- test "$patched" = $(git hash-object --stdin <one) || {
231
- echo "Eh? apply with --index"
232
- false
233
- }
202
+ verbose test "$patched" = $(git rev-parse :one) &&
203
+ verbose test "$patched" = $(git hash-object --stdin <one)
204
'
205
206
test_expect_success 'apply patch (autocrlf=true)' '
@@ -240,10 +210,7 @@ test_expect_success 'apply patch (autocrlf=true)' '
210
git read-tree --reset -u HEAD &&
211
212
git apply patch.file &&
243
- test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || {
244
- echo "Eh? apply without index"
245
- false
246
- }
213
+ verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
214
'
215
216
test_expect_success 'apply patch --cached (autocrlf=true)' '
@@ -253,10 +220,7 @@ test_expect_success 'apply patch --cached (autocrlf=true)' '
220
git read-tree --reset -u HEAD &&
221
222
git apply --cached patch.file &&
256
- test "$patched" = $(git rev-parse :one) || {
257
- echo "Eh? apply without index"
258
- false
259
- }
223
+ verbose test "$patched" = $(git rev-parse :one)
224
'
225
226
test_expect_success 'apply patch --index (autocrlf=true)' '
@@ -266,11 +230,8 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
230
git read-tree --reset -u HEAD &&
231
232
git apply --index patch.file &&
269
- test "$patched" = $(git rev-parse :one) &&
270
- test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || {
271
- echo "Eh? apply with --index"
272
- false
273
- }
233
+ verbose test "$patched" = $(git rev-parse :one) &&
234
+ verbose test "$patched" = "$(remove_cr <one | git hash-object --stdin)"
235
'
236
237
test_expect_success '.gitattributes says two is binary' '
@@ -326,21 +287,8 @@ test_expect_success '.gitattributes says two and three are text' '
287
echo "t* crlf" >.gitattributes &&
288
git read-tree --reset -u HEAD &&
289
329
- if has_cr dir/two
330
- then
331
- : happy
332
- else
333
- echo "Huh?"
334
- false
335
- fi &&
336
-
337
- if has_cr three
338
- then
339
- : happy
340
- else
341
- echo "Huh?"
342
- false
343
- fi
290
+ verbose has_cr dir/two &&
291
+ verbose has_cr three
292
'
293
294
test_expect_success 'in-tree .gitattributes (1)' '
@@ -352,17 +300,8 @@ test_expect_success 'in-tree .gitattributes (1)' '
300
rm -rf tmp one dir .gitattributes patch.file three &&
301
git read-tree --reset -u HEAD &&
302
355
- if has_cr one
356
- then
357
- echo "Eh? one should not have CRLF"
358
- false
359
- else
360
- : happy
361
- fi &&
362
- has_cr three || {
363
- echo "Eh? three should still have CRLF"
364
- false
365
- }
303
+ test_must_fail has_cr one &&
304
+ verbose has_cr three
305
'
306
307
test_expect_success 'in-tree .gitattributes (2)' '
@@ -371,17 +310,8 @@ test_expect_success 'in-tree .gitattributes (2)' '
310
git read-tree --reset HEAD &&
311
git checkout-index -f -q -u -a &&
312
374
- if has_cr one
375
- then
376
- echo "Eh? one should not have CRLF"
377
- false
378
- else
379
- : happy
380
- fi &&
381
- has_cr three || {
382
- echo "Eh? three should still have CRLF"
383
- false
384
- }
313
+ test_must_fail has_cr one &&
314
+ verbose has_cr three
315
'
316
317
test_expect_success 'in-tree .gitattributes (3)' '
@@ -391,17 +321,8 @@ test_expect_success 'in-tree .gitattributes (3)' '
321
git checkout-index -u .gitattributes &&
322
git checkout-index -u one dir/two three &&
323
394
- if has_cr one
395
- then
396
- echo "Eh? one should not have CRLF"
397
- false
398
- else
399
- : happy
400
- fi &&
401
- has_cr three || {
402
- echo "Eh? three should still have CRLF"
403
- false
404
- }
324
+ test_must_fail has_cr one &&
325
+ verbose has_cr three
326
'
327
328
test_expect_success 'in-tree .gitattributes (4)' '
@@ -411,17 +332,8 @@ test_expect_success 'in-tree .gitattributes (4)' '
332
git checkout-index -u one dir/two three &&
333
git checkout-index -u .gitattributes &&
334
414
- if has_cr one
415
- then
416
- echo "Eh? one should not have CRLF"
417
- false
418
- else
419
- : happy
420
- fi &&
421
- has_cr three || {
422
- echo "Eh? three should still have CRLF"
423
- false
424
- }
335
+ test_must_fail has_cr one &&
336
+ verbose has_cr three
337
'
338
339
test_expect_success 'checkout with existing .gitattributes' '