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

tests: consolidate CR removal/addition functions

append_cr(), remove_cr(), q_to_nul() and q_to_cr() are defined in multiple tests. Consolidate them into test-lib.sh so we can stop redefining them. The use of remove_cr() in t0020 to test for a CR is replaced with a new function has_cr() to accurately reflect what is intended (the output of remove_cr() was being thrown away). Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stephen Boyd committed Jan 25, 2010 at 16:33 UTC c4f3f551a61e138f8ace9523d6b16aff37b30302
6 files changed +37 -58
t/t0020-crlf.sh
+21 -34
@@ -4,21 +4,8 @@ test_description='CRLF conversion'
4
5 . ./test-lib.sh
6
7 -q_to_nul () {
8 - perl -pe 'y/Q/\000/'
9 -}
10 -
11 -q_to_cr () {
12 - tr Q '\015'
13 -}
14 -
15 -append_cr () {
16 - sed -e 's/$/Q/' | tr Q '\015'
17 -}
18 -
19 -remove_cr () {
20 - tr '\015' Q <"$1" | grep Q >/dev/null &&
21 - tr '\015' Q <"$1" | sed -ne 's/Q$//p'
7 +has_cr() {
8 + tr '\015' Q <"$1" | grep Q >/dev/null
9 }
10
11 test_expect_success setup '
@@ -156,7 +143,7 @@ test_expect_success 'checkout with autocrlf=true' '
143
144 for f in one dir/two
145 do
159 - remove_cr "$f" >tmp && mv -f tmp $f &&
146 + remove_cr <"$f" >tmp && mv -f tmp $f &&
147 git update-index -- $f || {
148 echo "Eh? $f"
149 false
@@ -180,7 +167,7 @@ test_expect_success 'checkout with autocrlf=input' '
167
168 for f in one dir/two
169 do
183 - if remove_cr "$f" >/dev/null
170 + if has_cr "$f"
171 then
172 echo "Eh? $f"
173 false
@@ -245,7 +232,7 @@ test_expect_success 'apply patch (autocrlf=true)' '
232 git read-tree --reset -u HEAD &&
233
234 git apply patch.file &&
248 - test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
235 + test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
236 echo "Eh? apply without index"
237 false
238 }
@@ -272,7 +259,7 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
259
260 git apply --index patch.file &&
261 test "$patched" = `git rev-parse :one` &&
275 - test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
262 + test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
263 echo "Eh? apply with --index"
264 false
265 }
@@ -285,7 +272,7 @@ test_expect_success '.gitattributes says two is binary' '
272 git config core.autocrlf true &&
273 git read-tree --reset -u HEAD &&
274
288 - if remove_cr dir/two >/dev/null
275 + if has_cr dir/two
276 then
277 echo "Huh?"
278 false
@@ -293,7 +280,7 @@ test_expect_success '.gitattributes says two is binary' '
280 : happy
281 fi &&
282
296 - if remove_cr one >/dev/null
283 + if has_cr one
284 then
285 : happy
286 else
@@ -301,7 +288,7 @@ test_expect_success '.gitattributes says two is binary' '
288 false
289 fi &&
290
304 - if remove_cr three >/dev/null
291 + if has_cr three
292 then
293 echo "Huh?"
294 false
@@ -316,7 +303,7 @@ test_expect_success '.gitattributes says two is input' '
303 echo "two crlf=input" >.gitattributes &&
304 git read-tree --reset -u HEAD &&
305
319 - if remove_cr dir/two >/dev/null
306 + if has_cr dir/two
307 then
308 echo "Huh?"
309 false
@@ -331,7 +318,7 @@ test_expect_success '.gitattributes says two and three are text' '
318 echo "t* crlf" >.gitattributes &&
319 git read-tree --reset -u HEAD &&
320
334 - if remove_cr dir/two >/dev/null
321 + if has_cr dir/two
322 then
323 : happy
324 else
@@ -339,7 +326,7 @@ test_expect_success '.gitattributes says two and three are text' '
326 false
327 fi &&
328
342 - if remove_cr three >/dev/null
329 + if has_cr three
330 then
331 : happy
332 else
@@ -357,14 +344,14 @@ test_expect_success 'in-tree .gitattributes (1)' '
344 rm -rf tmp one dir .gitattributes patch.file three &&
345 git read-tree --reset -u HEAD &&
346
360 - if remove_cr one >/dev/null
347 + if has_cr one
348 then
349 echo "Eh? one should not have CRLF"
350 false
351 else
352 : happy
353 fi &&
367 - remove_cr three >/dev/null || {
354 + has_cr three || {
355 echo "Eh? three should still have CRLF"
356 false
357 }
@@ -376,14 +363,14 @@ test_expect_success 'in-tree .gitattributes (2)' '
363 git read-tree --reset HEAD &&
364 git checkout-index -f -q -u -a &&
365
379 - if remove_cr one >/dev/null
366 + if has_cr one
367 then
368 echo "Eh? one should not have CRLF"
369 false
370 else
371 : happy
372 fi &&
386 - remove_cr three >/dev/null || {
373 + has_cr three || {
374 echo "Eh? three should still have CRLF"
375 false
376 }
@@ -396,14 +383,14 @@ test_expect_success 'in-tree .gitattributes (3)' '
383 git checkout-index -u .gitattributes &&
384 git checkout-index -u one dir/two three &&
385
399 - if remove_cr one >/dev/null
386 + if has_cr one
387 then
388 echo "Eh? one should not have CRLF"
389 false
390 else
391 : happy
392 fi &&
406 - remove_cr three >/dev/null || {
393 + has_cr three || {
394 echo "Eh? three should still have CRLF"
395 false
396 }
@@ -416,14 +403,14 @@ test_expect_success 'in-tree .gitattributes (4)' '
403 git checkout-index -u one dir/two three &&
404 git checkout-index -u .gitattributes &&
405
419 - if remove_cr one >/dev/null
406 + if has_cr one
407 then
408 echo "Eh? one should not have CRLF"
409 false
410 else
411 : happy
412 fi &&
426 - remove_cr three >/dev/null || {
413 + has_cr three || {
414 echo "Eh? three should still have CRLF"
415 false
416 }
@@ -456,7 +443,7 @@ test_expect_success 'checkout when deleting .gitattributes' '
443
444 git checkout master~1 &&
445 git checkout master &&
459 - remove_cr .file2 >/dev/null
446 + has_cr .file2
447
448 '
449
t/t3400-rebase.sh
-4
@@ -134,10 +134,6 @@ test_expect_success 'rebase -q is quiet' '
134 test ! -s output.out
135 '
136
137 -q_to_cr () {
138 - tr Q '\015'
139 -}
140 -
137 test_expect_success 'Rebase a commit that sprinkles CRs in' '
138 (
139 echo "One"
t/t4012-diff-binary.sh
-4
@@ -77,10 +77,6 @@ test_expect_success 'apply binary patch' \
77 tree1=`git write-tree` &&
78 test "$tree1" = "$tree0"'
79
80 -q_to_nul() {
81 - perl -pe 'y/Q/\000/'
82 -}
83 -
80 nul_to_q() {
81 perl -pe 'y/\000/Q/'
82 }
t/t6033-merge-crlf.sh
-8
@@ -1,13 +1,5 @@
1 #!/bin/sh
2
3 -append_cr () {
4 - sed -e 's/$/Q/' | tr Q '\015'
5 -}
6 -
7 -remove_cr () {
8 - tr '\015' Q | sed -e 's/Q$//'
9 -}
10 -
3 test_description='merge conflict in crlf repo
4
5 b---M
t/t9401-git-cvsserver-crlf.sh
-8
@@ -11,14 +11,6 @@ repository using cvs CLI client via git-cvsserver server'
11
12 . ./test-lib.sh
13
14 -q_to_nul () {
15 - perl -pe 'y/Q/\000/'
16 -}
17 -
18 -q_to_cr () {
19 - tr Q '\015'
20 -}
21 -
14 marked_as () {
15 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
16 if [ x"$foundEntry" = x"" ] ; then
t/test-lib.sh
+16
@@ -230,6 +230,22 @@ test_decode_color () {
230 -e 's/.\[m/<RESET>/g'
231 }
232
233 +q_to_nul () {
234 + perl -pe 'y/Q/\000/'
235 +}
236 +
237 +q_to_cr () {
238 + tr Q '\015'
239 +}
240 +
241 +append_cr () {
242 + sed -e 's/$/Q/' | tr Q '\015'
243 +}
244 +
245 +remove_cr () {
246 + tr '\015' Q | sed -e 's/Q$//'
247 +}
248 +
249 test_tick () {
250 if test -z "${test_tick+set}"
251 then