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@xxxxxxxxxxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html