From 8d0429ca41de08ee9196afc41bcc41bf1ecc5db6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 19 Apr 2012 18:21:29 -0500 Subject: [PATCH] Introduce and use test_cmp_text On Windows, we suffer from frequently leaked DOS line endings. Let's ignore them. Signed-off-by: Johannes Schindelin --- t/lib-credential.sh | 6 +----- t/t9001-send-email.sh | 30 +++++++++++++++--------------- t/test-lib.sh | 14 +++++++++++++- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/t/lib-credential.sh b/t/lib-credential.sh index 0c5ff70e19..9d78da223f 100755 --- a/t/lib-credential.sh +++ b/t/lib-credential.sh @@ -19,11 +19,7 @@ check() { false fi && test_cmp expect-stdout stdout && - if test_have_prereq MINGW - then - dos2unix stderr - fi && - test_cmp expect-stderr stderr + test_cmp_text expect-stderr stderr } read_chunk() { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 3119c8c523..d680aa6313 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -96,7 +96,7 @@ EOF test_expect_success $PREREQ \ 'Verify commandline' \ - 'test_cmp expected commandline1' + 'test_cmp_text expected commandline1' test_expect_success $PREREQ 'Send patches with --envelope-sender' ' clean_fake_sendmail && @@ -116,7 +116,7 @@ EOF test_expect_success $PREREQ \ 'Verify commandline' \ - 'test_cmp expected commandline1' + 'test_cmp_text expected commandline1' test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' ' clean_fake_sendmail && @@ -136,7 +136,7 @@ EOF test_expect_success $PREREQ \ 'Verify commandline' \ - 'test_cmp expected commandline1' + 'test_cmp_text expected commandline1' test_expect_success $PREREQ 'setup expect' " cat >expected-show-all-headers <<\EOF @@ -260,7 +260,7 @@ test_expect_success $PREREQ 'Show all headers' ' -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ >actual-show-all-headers && - test_cmp expected-show-all-headers actual-show-all-headers + test_cmp_text expected-show-all-headers actual-show-all-headers ' test_expect_success $PREREQ 'Prompting works' ' @@ -428,13 +428,13 @@ test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' 2>errors && # The first message is a reply to --in-reply-to sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && - test_cmp expect actual && + test_cmp_text expect actual && # Second and subsequent messages are replies to the first one sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && - test_cmp expect actual && + test_cmp_text expect actual && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && - test_cmp expect actual + test_cmp_text expect actual ' test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' @@ -449,13 +449,13 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' $patches $patches $patches \ 2>errors && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && - test_cmp expect actual && + test_cmp_text expect actual && sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && - test_cmp expect actual && + test_cmp_text expect actual && sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect && sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && - test_cmp expect actual + test_cmp_text expect actual ' test_expect_success $PREREQ 'setup fake editor' ' @@ -527,7 +527,7 @@ test_suppression () { -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ >actual-suppress-$1${2+"-$2"} && - test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} + test_cmp_text expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} } test_expect_success $PREREQ 'sendemail.cc set' ' @@ -1243,7 +1243,7 @@ test_expect_success $PREREQ 'asks about and fixes 8bit encodings' ' grep email-using-8bit stdout && grep "Which 8bit encoding" stdout && egrep "Content|MIME" msgtxt1 >actual && - test_cmp actual content-type-decl + test_cmp_text actual content-type-decl ' test_expect_success $PREREQ 'sendemail.8bitEncoding works' ' @@ -1254,7 +1254,7 @@ test_expect_success $PREREQ 'sendemail.8bitEncoding works' ' --smtp-server="$(pwd)/fake.sendmail" \ email-using-8bit >stdout && egrep "Content|MIME" msgtxt1 >actual && - test_cmp actual content-type-decl + test_cmp_text actual content-type-decl ' test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' ' @@ -1266,7 +1266,7 @@ test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' ' --8bit-encoding=UTF-8 \ email-using-8bit >stdout && egrep "Content|MIME" msgtxt1 >actual && - test_cmp actual content-type-decl + test_cmp_text actual content-type-decl ' test_expect_success $PREREQ 'setup expect' ' @@ -1295,7 +1295,7 @@ test_expect_success $PREREQ '--8bit-encoding also treats subject' ' --8bit-encoding=UTF-8 \ email-using-8bit >stdout && grep "Subject" msgtxt1 >actual && - test_cmp expected actual + test_cmp_text expected actual ' # Note that the patches in this test are deliberately out of order; we diff --git a/t/test-lib.sh b/t/test-lib.sh index 599b1ff2d9..d5abf0f4fd 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -791,12 +791,24 @@ else test_set_prereq C_LOCALE_OUTPUT fi +# Use this instead of test_cmp to compare files that are expected to contain +# text (and therefore it should not matter whether the line ends in an LF or +# a CR/LF). +test_cmp_text () { + if test_have_prereq MINGW + then + dos2unix "$1" && + dos2unix "$2" + fi && + test_cmp "$@" +} + # Use this instead of test_cmp to compare files that contain expected and # actual output from git commands that can be translated. When running # under GETTEXT_POISON this pretends that the command produced expected # results. test_i18ncmp () { - test -n "$GETTEXT_POISON" || test_cmp "$@" + test -n "$GETTEXT_POISON" || test_cmp_text "$@" } # Use this instead of "grep expected-string actual" to see if the