Skip to content

Commit

Permalink
tests: consolidate CR removal/addition functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Stephen Boyd authored and Junio C Hamano committed Jan 26, 2010
1 parent 2d7f98b commit c4f3f55
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 58 deletions.
55 changes: 21 additions & 34 deletions t/t0020-crlf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,8 @@ test_description='CRLF conversion'

. ./test-lib.sh

q_to_nul () {
perl -pe 'y/Q/\000/'
}

q_to_cr () {
tr Q '\015'
}

append_cr () {
sed -e 's/$/Q/' | tr Q '\015'
}

remove_cr () {
tr '\015' Q <"$1" | grep Q >/dev/null &&
tr '\015' Q <"$1" | sed -ne 's/Q$//p'
has_cr() {
tr '\015' Q <"$1" | grep Q >/dev/null
}

test_expect_success setup '
Expand Down Expand Up @@ -156,7 +143,7 @@ test_expect_success 'checkout with autocrlf=true' '
for f in one dir/two
do
remove_cr "$f" >tmp && mv -f tmp $f &&
remove_cr <"$f" >tmp && mv -f tmp $f &&
git update-index -- $f || {
echo "Eh? $f"
false
Expand All @@ -180,7 +167,7 @@ test_expect_success 'checkout with autocrlf=input' '
for f in one dir/two
do
if remove_cr "$f" >/dev/null
if has_cr "$f"
then
echo "Eh? $f"
false
Expand Down Expand Up @@ -245,7 +232,7 @@ test_expect_success 'apply patch (autocrlf=true)' '
git read-tree --reset -u HEAD &&
git apply patch.file &&
test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
echo "Eh? apply without index"
false
}
Expand All @@ -272,7 +259,7 @@ test_expect_success 'apply patch --index (autocrlf=true)' '
git apply --index patch.file &&
test "$patched" = `git rev-parse :one` &&
test "$patched" = "`remove_cr one | git hash-object --stdin`" || {
test "$patched" = "`remove_cr <one | git hash-object --stdin`" || {
echo "Eh? apply with --index"
false
}
Expand All @@ -285,23 +272,23 @@ test_expect_success '.gitattributes says two is binary' '
git config core.autocrlf true &&
git read-tree --reset -u HEAD &&
if remove_cr dir/two >/dev/null
if has_cr dir/two
then
echo "Huh?"
false
else
: happy
fi &&
if remove_cr one >/dev/null
if has_cr one
then
: happy
else
echo "Huh?"
false
fi &&
if remove_cr three >/dev/null
if has_cr three
then
echo "Huh?"
false
Expand All @@ -316,7 +303,7 @@ test_expect_success '.gitattributes says two is input' '
echo "two crlf=input" >.gitattributes &&
git read-tree --reset -u HEAD &&
if remove_cr dir/two >/dev/null
if has_cr dir/two
then
echo "Huh?"
false
Expand All @@ -331,15 +318,15 @@ test_expect_success '.gitattributes says two and three are text' '
echo "t* crlf" >.gitattributes &&
git read-tree --reset -u HEAD &&
if remove_cr dir/two >/dev/null
if has_cr dir/two
then
: happy
else
echo "Huh?"
false
fi &&
if remove_cr three >/dev/null
if has_cr three
then
: happy
else
Expand All @@ -357,14 +344,14 @@ test_expect_success 'in-tree .gitattributes (1)' '
rm -rf tmp one dir .gitattributes patch.file three &&
git read-tree --reset -u HEAD &&
if remove_cr one >/dev/null
if has_cr one
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
false
}
Expand All @@ -376,14 +363,14 @@ test_expect_success 'in-tree .gitattributes (2)' '
git read-tree --reset HEAD &&
git checkout-index -f -q -u -a &&
if remove_cr one >/dev/null
if has_cr one
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
false
}
Expand All @@ -396,14 +383,14 @@ test_expect_success 'in-tree .gitattributes (3)' '
git checkout-index -u .gitattributes &&
git checkout-index -u one dir/two three &&
if remove_cr one >/dev/null
if has_cr one
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
false
}
Expand All @@ -416,14 +403,14 @@ test_expect_success 'in-tree .gitattributes (4)' '
git checkout-index -u one dir/two three &&
git checkout-index -u .gitattributes &&
if remove_cr one >/dev/null
if has_cr one
then
echo "Eh? one should not have CRLF"
false
else
: happy
fi &&
remove_cr three >/dev/null || {
has_cr three || {
echo "Eh? three should still have CRLF"
false
}
Expand Down Expand Up @@ -456,7 +443,7 @@ test_expect_success 'checkout when deleting .gitattributes' '
git checkout master~1 &&
git checkout master &&
remove_cr .file2 >/dev/null
has_cr .file2
'

Expand Down
4 changes: 0 additions & 4 deletions t/t3400-rebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,6 @@ test_expect_success 'rebase -q is quiet' '
test ! -s output.out
'

q_to_cr () {
tr Q '\015'
}

test_expect_success 'Rebase a commit that sprinkles CRs in' '
(
echo "One"
Expand Down
4 changes: 0 additions & 4 deletions t/t4012-diff-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ test_expect_success 'apply binary patch' \
tree1=`git write-tree` &&
test "$tree1" = "$tree0"'

q_to_nul() {
perl -pe 'y/Q/\000/'
}

nul_to_q() {
perl -pe 'y/\000/Q/'
}
Expand Down
8 changes: 0 additions & 8 deletions t/t6033-merge-crlf.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
#!/bin/sh

append_cr () {
sed -e 's/$/Q/' | tr Q '\015'
}

remove_cr () {
tr '\015' Q | sed -e 's/Q$//'
}

test_description='merge conflict in crlf repo
b---M
Expand Down
8 changes: 0 additions & 8 deletions t/t9401-git-cvsserver-crlf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ repository using cvs CLI client via git-cvsserver server'

. ./test-lib.sh

q_to_nul () {
perl -pe 'y/Q/\000/'
}

q_to_cr () {
tr Q '\015'
}

marked_as () {
foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
if [ x"$foundEntry" = x"" ] ; then
Expand Down
16 changes: 16 additions & 0 deletions t/test-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ test_decode_color () {
-e 's/.\[m/<RESET>/g'
}

q_to_nul () {
perl -pe 'y/Q/\000/'
}

q_to_cr () {
tr Q '\015'
}

append_cr () {
sed -e 's/$/Q/' | tr Q '\015'
}

remove_cr () {
tr '\015' Q | sed -e 's/Q$//'
}

test_tick () {
if test -z "${test_tick+set}"
then
Expand Down

0 comments on commit c4f3f55

Please sign in to comment.