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

Re: [PATCH] t9001: set TERM=dumb to prevent ANSI output

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 7, 2008, 06:16 UTC
Message-ID
<7vskz33vow.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<7v7igf5cpk.fsf@gitster.siamese.dyndns.org>
Junio C Hamano <gitster@pobox.com> writes:
Show 13 quoted lines
> Christian Couder <chriscool@tuxfamily.org> writes:
> ...
>> This may not work well with colored output.
>> In test-lib.sh line 62 there is :
>>
>> [ "x$TERM" != "xdumb" ] &&
>> 	[ -t 1 ] &&
>> 	tput bold >/dev/null 2>&1 &&
>> 	tput setaf 1 >/dev/null 2>&1 &&
>> 	tput sgr0 >/dev/null 2>&1 &&
>> 	color=t
>
> Ahh.  Sorry about that.
Ahem, third time lucky.

-- >8 -- [PATCH] test-lib: fix TERM to dumb for test repeatability

Dscho noticed that Term::ReadLine (used by send-email) colorized its output for his TERM settings, inside t9001 tests.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/test-lib.sh |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index c0c5e21..44f5776 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -3,12 +3,16 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
+# Keep the original TERM for say_color
+ORIGINAL_TERM=$TERM
+
 # For repeatability, reset the environment to known value.
 LANG=C
 LC_ALL=C
 PAGER=cat
 TZ=UTC
-export LANG LC_ALL PAGER TZ
+TERM=dumb
+export LANG LC_ALL PAGER TERM TZ
 EDITOR=:
 VISUAL=:
 unset GIT_EDITOR
@@ -58,12 +62,14 @@ esac
 # This test checks if command xyzzy does the right thing...
 # '
 # . ./test-lib.sh
-
-[ "x$TERM" != "xdumb" ] &&
-	[ -t 1 ] &&
-	tput bold >/dev/null 2>&1 &&
-	tput setaf 1 >/dev/null 2>&1 &&
-	tput sgr0 >/dev/null 2>&1 &&
+[ "x$ORIGINAL_TERM" != "xdumb" ] && (
+		TERM=$ORIGINAL_TERM &&
+		export TERM &&
+		[ -t 1 ] &&
+		tput bold >/dev/null 2>&1 &&
+		tput setaf 1 >/dev/null 2>&1 &&
+		tput sgr0 >/dev/null 2>&1
+	) &&
 	color=t
 
 while test "$#" -ne 0
@@ -91,6 +97,9 @@ done
 
 if test -n "$color"; then
 	say_color () {
+		(
+		TERM=$ORIGINAL_TERM
+		export TERM
 		case "$1" in
 			error) tput bold; tput setaf 1;; # bold red
 			skip)  tput bold; tput setaf 2;; # bold green
@@ -101,6 +110,7 @@ if test -n "$color"; then
 		shift
 		echo "* $*"
 		tput sgr0
+		)
 	}
 else
 	say_color() {
-- 
1.5.4.3.587.g0bdd73
Previous: Junio C HamanoNext: Johannes Schindelin
Message 6 of 9 in “t9001: set TERM=dumb to prevent ANSI output”
  1. t9001: set TERM=dumb to prevent ANSI outputJohannes Schindelin, Mar 6, 2008
  2. Junio C HamanoMar 6, 2008
  3. Johannes SchindelinMar 7, 2008
  4. Christian CouderMar 7, 2008
  5. Junio C HamanoMar 7, 2008
  6. Junio C HamanoMar 7, 2008
  7. Johannes SchindelinMar 7, 2008
  8. Junio C HamanoMar 7, 2008
  9. Johannes SchindelinMar 7, 2008

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.