From: Don Slutz <Don.Slutz@SierraAtlantic.com>
To: git@vger.kernel.org
Cc: Don Slutz <Don.Slutz@SierraAtlantic.com>
Subject: [PATCH 2/6] Fix tests to work with core.autocrlf=true
Date: Mon, 11 May 2009 15:28:57 -0400 [thread overview]
Message-ID: <1242070141-2936-3-git-send-email-Don.Slutz@SierraAtlantic.com> (raw)
In-Reply-To: <1242070141-2936-2-git-send-email-Don.Slutz@SierraAtlantic.com>
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 <Don.Slutz@SierraAtlantic.com>
---
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 <directory>
test_create_repo () {
--
1.6.3.15.g49878
next prev parent reply other threads:[~2009-05-11 19:29 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-11 19:28 [PATCH 0/6] Add core.autocrlf=true on cygwin by default during tests Don Slutz
2009-05-11 19:28 ` [PATCH 1/6] " Don Slutz
2009-05-11 19:28 ` Don Slutz [this message]
2009-05-11 19:28 ` [PATCH 3/6] Fix tests to work with core.autocrlf=true Don Slutz
2009-05-11 19:28 ` [PATCH 4/6] " Don Slutz
2009-05-11 19:29 ` [PATCH 5/6] " Don Slutz
2009-05-11 19:29 ` [PATCH 6/6] Add 'make test-text' Don Slutz
2009-05-11 22:20 ` [PATCH 3/6] Fix tests to work with core.autocrlf=true Charles Bailey
2009-05-14 13:49 ` Don Slutz
2009-05-11 20:04 ` [PATCH 0/6] Add core.autocrlf=true on cygwin by default during tests Eric Blake
2009-05-12 23:27 ` Junio C Hamano
2009-05-13 17:41 ` Junio C Hamano
2009-05-11 20:54 ` Johannes Schindelin
2009-05-12 18:16 ` Don Slutz
2009-05-13 19:35 ` [PATCH v2 0/7] Add GIT_TEST_AUTO_CRLF environment variable to set core.autocrlf on init Don Slutz
2009-05-13 19:35 ` [PATCH v2 1/7] " Don Slutz
2009-05-13 19:35 ` [PATCH v2 2/7] Add support functions for tests in core.autocrlf=true Don Slutz
2009-05-13 19:35 ` [PATCH v2 3/7] Fix tests to work with core.autocrlf=true -- new functions Don Slutz
2009-05-13 19:35 ` [PATCH v2 4/7] Fix tests to work with core.autocrlf=true -- force false Don Slutz
2009-05-13 19:35 ` [PATCH v2 5/7] Fix tests to work with core.autocrlf=true -- cmp to test_cmp Don Slutz
2009-05-13 19:35 ` [PATCH v2 6/7] Fix tests to work with core.autocrlf=true -- test_cmp to cmp Don Slutz
2009-05-13 19:35 ` [PATCH v2 7/7] Add 'make test-text' core.autocrlf=true Don Slutz
2009-05-14 7:43 ` [PATCH v2 3/7] Fix tests to work with core.autocrlf=true -- new functions Charles Bailey
2009-05-14 14:39 ` Don Slutz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1242070141-2936-3-git-send-email-Don.Slutz@SierraAtlantic.com \
--to=don.slutz@sierraatlantic.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).