[PATCH v2 2/7] Add support functions for tests in core.autocrlf=true
test_external_with_only_warning() -- Ignore CRLF warnings
test_eq_cat() -- like "test foo = $(cat bar)" but works in any setting of
core.autocrlf
test_ne_cat() -- like "test foo != $(cat bar)"
test_cat_eq() -- like "test $(cat foo) = bar"Signed-off-by: Don Slutz <Don.Slutz@SierraAtlantic.com>
---
t/test-lib.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 6178e8c..2e0fd43 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -453,6 +453,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:
#
@@ -487,6 +516,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