git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/7] Add support functions for tests in core.autocrlf=true

From
DSDon Slutz <don.slutz@sierraatlantic.com>
Date
May 13, 2009, 19:35 UTC
Message-ID
<1242243348-6690-3-git-send-email-Don.Slutz@SierraAtlantic.com>
In-Reply-To
<1242243348-6690-2-git-send-email-Don.Slutz@SierraAtlantic.com>
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
Previous: Don SlutzNext: Don Slutz
Message 17 of 24 in “Add core.autocrlf=true on cygwin by default during tests”
  1. 0/6 Add core.autocrlf=true on cygwin by default during testsDon Slutz, May 11, 2009
  2. 1/6 Add core.autocrlf=true on cygwin by default during testsDon Slutz, May 11, 2009
  3. 2/6 Fix tests to work with core.autocrlf=trueDon Slutz, May 11, 2009
  4. 3/6 Fix tests to work with core.autocrlf=trueDon Slutz, May 11, 2009
  5. 4/6 Fix tests to work with core.autocrlf=trueDon Slutz, May 11, 2009
  6. 5/6 Fix tests to work with core.autocrlf=trueDon Slutz, May 11, 2009
  7. 6/6 Add 'make test-text'Don Slutz, May 11, 2009
  8. Charles BaileyMay 11, 2009
  9. Don SlutzMay 14, 2009
  10. Eric BlakeMay 11, 2009
  11. Junio C HamanoMay 12, 2009
  12. Junio C HamanoMay 13, 2009
  13. Johannes SchindelinMay 11, 2009
  14. Don SlutzMay 12, 2009
  15. 0/7 Add GIT_TEST_AUTO_CRLF environment variable to set core.autocrlf on initDon Slutz, May 13, 2009
  16. 1/7 Add GIT_TEST_AUTO_CRLF environment variable to set core.autocrlf on initDon Slutz, May 13, 2009
  17. 2/7 Add support functions for tests in core.autocrlf=trueDon Slutz, May 13, 2009
  18. 3/7 Fix tests to work with core.autocrlf=true -- new functionsDon Slutz, May 13, 2009
  19. 4/7 Fix tests to work with core.autocrlf=true -- force falseDon Slutz, May 13, 2009
  20. 5/7 Fix tests to work with core.autocrlf=true -- cmp to test_cmpDon Slutz, May 13, 2009
  21. 6/7 Fix tests to work with core.autocrlf=true -- test_cmp to cmpDon Slutz, May 13, 2009
  22. 7/7 Add 'make test-text' core.autocrlf=trueDon Slutz, May 13, 2009
  23. Charles BaileyMay 14, 2009
  24. Don SlutzMay 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.