From mboxrd@z Thu Jan 1 00:00:00 1970 From: Don Slutz Subject: (unknown) Date: Mon, 11 May 2009 14:57:12 -0400 Message-ID: <200905111857.n4BIvCnG002317@krl.krl.com> To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Mon May 11 21:25:40 2009 Return-path: Envelope-to: gcvg-git-2@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by lo.gmane.org with esmtp (Exim 4.50) id 1M3b81-0005Ox-Pg for gcvg-git-2@gmane.org; Mon, 11 May 2009 21:25:34 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756907AbZEKTZ3 (ORCPT ); Mon, 11 May 2009 15:25:29 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756162AbZEKTZ1 (ORCPT ); Mon, 11 May 2009 15:25:27 -0400 Received: from krl.krl.com ([192.147.32.3]:42939 "EHLO krl.krl.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757869AbZEKTZV (ORCPT ); Mon, 11 May 2009 15:25:21 -0400 X-Greylist: delayed 1681 seconds by postgrey-1.27 at vger.kernel.org; Mon, 11 May 2009 15:25:15 EDT Received: from krl.krl.com (localhost [127.0.0.1]) by krl.krl.com (8.13.1/8.13.1) with ESMTP id n4BIvD6W002333 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 11 May 2009 14:57:13 -0400 Received: (from slutz@localhost) by krl.krl.com (8.13.1/8.13.1/Submit) id n4BIvCnG002317 for git@vger.kernel.org; Mon, 11 May 2009 14:57:12 -0400 X-Virus-Scanned: ClamAV version 0.94.2, clamav-milter version 0.94.2 on krl X-Virus-Status: Clean Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: >>From 3f0280a44185d1c7f6b653988bc0b46d239cdd17 Mon Sep 17 00:00:00 2001 From: Don Slutz Date: Mon, 11 May 2009 11:48:54 -0400 Subject: [PATCH 2/6] Fix tests to work with core.autocrlf=true test-lib changes. Run the tests via: GIT_TEST_AUTO_CRLF=true make test Change the default value of GIT_TEST_CMP to ignore whitespace changes when core.autocrlf=true Add support functions: test_external_with_only_warning, test_eq_cat, test_cat_eq, and test_ne_cat all of which will ignore CR if it is in the file. Signed-off-by: Don Slutz --- t/test-lib.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 58 insertions(+), 1 deletions(-) diff --git a/t/test-lib.sh b/t/test-lib.sh index 218bd82..84846cd 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -59,7 +59,6 @@ export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR VISUAL -GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} # Protect ourselves from common misconfiguration to export # CDPATH into the environment @@ -129,6 +128,11 @@ case $(uname -s) in *) ;; esac +if test ! -z $GIT_TEST_AUTO_CRLF && test $GIT_TEST_AUTO_CRLF = true; then + GIT_TEST_CMP=${GIT_TEST_CMP:-diff -uw} +else + GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} +fi if test -n "$color"; then say_color () { @@ -459,6 +463,35 @@ test_external_without_stderr () { fi } +# Like test_external, but in addition tests that the command generated +# only "warning: LF will be replaced by CRLF" output on stderr. +test_external_with_only_warning () { + # The temporary file has no (and must have no) security + # implications. + tmp="$TMPDIR"; if [ -z "$tmp" ]; then tmp=/tmp; fi + stderr="$tmp/git-external-stderr.$$.tmp" + test_external "$@" 4> "$stderr" + [ -f "$stderr" ] || error "Internal error: $stderr disappeared." + descr="only warning: $1" + shift + say >&3 "expecting only warnings from previous command" + output=$(grep -v "warning: LF will be replaced by CRLF in" $stderr) + test_debug "echo non-warning: $output" + if [ -z "$output" ]; then + rm "$stderr" + test_ok_ "$descr" + else + if [ "$verbose" = t ]; then + output=`echo; echo Stderr is:; cat "$stderr"` + else + output= + fi + # rm first in case test_failure exits. + rm "$stderr" + test_failure_ "$descr" "$@" "$output" + fi +} + # This is not among top-level (test_expect_success | test_expect_failure) # but is a prefix that can be used in the test script, like: # @@ -493,6 +526,30 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# test_eq_cat is a helper function to compare a 1 word file +# with a string. +# It almost the same as: test foo = $(cat bar) +# for: test_eq_cat foo bar +# +# However it works when core.autocrlf = true. + +test_eq_cat() { + test "$1" = "$(tr '\015' '\012' < "$2")" +} + +# the but not-equal -- may not catch all cases + +test_ne_cat() { + test "$1" != "$(tr '\015' '\012' < "$2")" +} + +# the same as test_eq_cat, but file is 1st. + +test_cat_eq() { + test "$(tr '\015' '\012' < "$1")" = "$2" +} + + # Most tests can use the created repository, but some may need to create more. # Usage: test_create_repo test_create_repo () { -- 1.6.3.15.g49878