Skip to content

Commit 9157c5c

Browse files
peffgitster
authored andcommitted
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>
1 parent e4e6e8b commit 9157c5c

1 file changed

Lines changed: 28 additions & 116 deletions

File tree

t/t0020-crlf.sh

Lines changed: 28 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,12 @@ test_expect_success 'update with autocrlf=input' '
104104
for f in one dir/two
105105
do
106106
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
112109
done &&
113110
114111
differs=$(git diff-index --cached HEAD) &&
115-
test -z "$differs" || {
116-
echo Oops "$differs"
117-
false
118-
}
112+
verbose test -z "$differs"
119113
120114
'
121115

@@ -128,18 +122,12 @@ test_expect_success 'update with autocrlf=true' '
128122
for f in one dir/two
129123
do
130124
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
136127
done &&
137128
138129
differs=$(git diff-index --cached HEAD) &&
139-
test -z "$differs" || {
140-
echo Oops "$differs"
141-
false
142-
}
130+
verbose test -z "$differs"
143131
144132
'
145133

@@ -152,19 +140,13 @@ test_expect_success 'checkout with autocrlf=true' '
152140
for f in one dir/two
153141
do
154142
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
160145
done &&
161146
test "$one" = $(git hash-object --stdin <one) &&
162147
test "$two" = $(git hash-object --stdin <dir/two) &&
163148
differs=$(git diff-index --cached HEAD) &&
164-
test -z "$differs" || {
165-
echo Oops "$differs"
166-
false
167-
}
149+
verbose test -z "$differs"
168150
'
169151

170152
test_expect_success 'checkout with autocrlf=input' '
@@ -187,10 +169,7 @@ test_expect_success 'checkout with autocrlf=input' '
187169
test "$one" = $(git hash-object --stdin <one) &&
188170
test "$two" = $(git hash-object --stdin <dir/two) &&
189171
differs=$(git diff-index --cached HEAD) &&
190-
test -z "$differs" || {
191-
echo Oops "$differs"
192-
false
193-
}
172+
verbose test -z "$differs"
194173
'
195174

196175
test_expect_success 'apply patch (autocrlf=input)' '
@@ -200,10 +179,7 @@ test_expect_success 'apply patch (autocrlf=input)' '
200179
git read-tree --reset -u HEAD &&
201180
202181
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)"
207183
'
208184

209185
test_expect_success 'apply patch --cached (autocrlf=input)' '
@@ -213,10 +189,7 @@ test_expect_success 'apply patch --cached (autocrlf=input)' '
213189
git read-tree --reset -u HEAD &&
214190
215191
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)
220193
'
221194

222195
test_expect_success 'apply patch --index (autocrlf=input)' '
@@ -226,11 +199,8 @@ test_expect_success 'apply patch --index (autocrlf=input)' '
226199
git read-tree --reset -u HEAD &&
227200
228201
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)
234204
'
235205

236206
test_expect_success 'apply patch (autocrlf=true)' '
@@ -240,10 +210,7 @@ test_expect_success 'apply patch (autocrlf=true)' '
240210
git read-tree --reset -u HEAD &&
241211
242212
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)"
247214
'
248215

249216
test_expect_success 'apply patch --cached (autocrlf=true)' '
@@ -253,10 +220,7 @@ test_expect_success 'apply patch --cached (autocrlf=true)' '
253220
git read-tree --reset -u HEAD &&
254221
255222
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)
260224
'
261225

262226
test_expect_success 'apply patch --index (autocrlf=true)' '
@@ -266,11 +230,8 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
266230
git read-tree --reset -u HEAD &&
267231
268232
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)"
274235
'
275236

276237
test_expect_success '.gitattributes says two is binary' '
@@ -326,21 +287,8 @@ test_expect_success '.gitattributes says two and three are text' '
326287
echo "t* crlf" >.gitattributes &&
327288
git read-tree --reset -u HEAD &&
328289
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
344292
'
345293

346294
test_expect_success 'in-tree .gitattributes (1)' '
@@ -352,17 +300,8 @@ test_expect_success 'in-tree .gitattributes (1)' '
352300
rm -rf tmp one dir .gitattributes patch.file three &&
353301
git read-tree --reset -u HEAD &&
354302
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
366305
'
367306

368307
test_expect_success 'in-tree .gitattributes (2)' '
@@ -371,17 +310,8 @@ test_expect_success 'in-tree .gitattributes (2)' '
371310
git read-tree --reset HEAD &&
372311
git checkout-index -f -q -u -a &&
373312
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
385315
'
386316

387317
test_expect_success 'in-tree .gitattributes (3)' '
@@ -391,17 +321,8 @@ test_expect_success 'in-tree .gitattributes (3)' '
391321
git checkout-index -u .gitattributes &&
392322
git checkout-index -u one dir/two three &&
393323
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
405326
'
406327

407328
test_expect_success 'in-tree .gitattributes (4)' '
@@ -411,17 +332,8 @@ test_expect_success 'in-tree .gitattributes (4)' '
411332
git checkout-index -u one dir/two three &&
412333
git checkout-index -u .gitattributes &&
413334
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
425337
'
426338

427339
test_expect_success 'checkout with existing .gitattributes' '

0 commit comments

Comments
 (0)