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

[PATCH 01/12] test-terminal: set TERM=vt100

From
Jeff King <peff@peff.net>
Date
Oct 3, 2017, 13:39 UTC
Message-ID
<20171003133934.oo2xkcxvweh36tcs@sigill.intra.peff.net>
In-Reply-To
<20171003133713.ccxv6clrmuuhhc3u@sigill.intra.peff.net>

The point of the test-terminal script is to simulate in the test scripts an environment where output is going to a real terminal.

But since test-lib.sh also sets TERM=dumb, the simulation isn't very realistic. The color code will skip auto-coloring for TERM=dumb, leading to us liberally sprinkling

  test_terminal env TERM=vt100 git ...

through the test suite to convince the tests to actually generate colors. Let's set TERM for programs run under test_terminal, which is one less thing for test-writers to remember.

In most cases the callers can be simplified, but note there is one interesting case in t4202. It uses test_terminal to check the auto-enabling of --decorate, but the expected output _doesn't_ contain colors (because TERM=dumb suppresses them). Using TERM=vt100 is closer to what the real world looks like; adjust the expected output to match.

Signed-off-by: Jeff King <peff@peff.net>
---
Not strictly necessary for this series, but after banging my shins on
this nuisance for the umpteenth time, I decided to finally do something
about it.
 t/t3203-branch-output.sh   | 2 +-
 t/t4202-log.sh             | 2 +-
 t/t6006-rev-list-format.sh | 3 +--
 t/t6300-for-each-ref.sh    | 3 +--
 t/t7004-tag.sh             | 2 +-
 t/t7006-pager.sh           | 6 +++---
 t/test-terminal.perl       | 1 +
 7 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index d2aec0f38b..86286f263d 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -253,7 +253,7 @@ test_expect_success '%(color) omitted without tty' '
 '
 
 test_expect_success TTY '%(color) present with tty' '
-	test_terminal env TERM=vt100 git branch $color_args >actual.raw &&
+	test_terminal git branch $color_args >actual.raw &&
 	test_decode_color <actual.raw >actual &&
 	test_cmp expect.color actual
 '
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 36d120c969..8f155da7a5 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -750,7 +750,7 @@ test_expect_success 'log.decorate config parsing' '
 '
 
 test_expect_success TTY 'log output on a TTY' '
-	git log --oneline --decorate >expect.short &&
+	git log --color --oneline --decorate >expect.short &&
 
 	test_terminal git log --oneline >actual &&
 	test_cmp expect.short actual
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index b326d550f3..98be78b4a2 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -229,8 +229,7 @@ do
 	'
 
 	test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
-		test_terminal env TERM=vt100 \
-			git log --format=$color -1 --color=auto >actual &&
+		test_terminal git log --format=$color -1 --color=auto >actual &&
 		has_color actual
 	'
 
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index 2274a4b733..d6bffe6273 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -425,8 +425,7 @@ test_expect_success 'set up color tests' '
 '
 
 test_expect_success TTY '%(color) shows color with a tty' '
-	test_terminal env TERM=vt100 \
-		git for-each-ref --format="$color_format" >actual.raw &&
+	test_terminal git for-each-ref --format="$color_format" >actual.raw &&
 	test_decode_color <actual.raw >actual &&
 	test_cmp expected.color actual
 '
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index b545c33f83..0a86f8ea39 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1907,7 +1907,7 @@ test_expect_success '%(color) omitted without tty' '
 '
 
 test_expect_success TTY '%(color) present with tty' '
-	test_terminal env TERM=vt100 git tag $color_args >actual.raw &&
+	test_terminal git tag $color_args >actual.raw &&
 	test_decode_color <actual.raw >actual &&
 	test_cmp expect.color actual
 '
diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh
index 9128ec5acd..f0f1abd1c2 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -239,7 +239,7 @@ test_expect_success 'no color when stdout is a regular file' '
 test_expect_success TTY 'color when writing to a pager' '
 	rm -f paginated.out &&
 	test_config color.ui auto &&
-	test_terminal env TERM=vt100 git log &&
+	test_terminal git log &&
 	colorful paginated.out
 '
 
@@ -247,7 +247,7 @@ test_expect_success TTY 'colors are suppressed by color.pager' '
 	rm -f paginated.out &&
 	test_config color.ui auto &&
 	test_config color.pager false &&
-	test_terminal env TERM=vt100 git log &&
+	test_terminal git log &&
 	! colorful paginated.out
 '
 
@@ -266,7 +266,7 @@ test_expect_success 'color when writing to a file intended for a pager' '
 test_expect_success TTY 'colors are sent to pager for external commands' '
 	test_config alias.externallog "!git log" &&
 	test_config color.ui auto &&
-	test_terminal env TERM=vt100 git -p externallog &&
+	test_terminal git -p externallog &&
 	colorful paginated.out
 '
 
diff --git a/t/test-terminal.perl b/t/test-terminal.perl
index 96b6a03e1c..46bf618479 100755
--- a/t/test-terminal.perl
+++ b/t/test-terminal.perl
@@ -80,6 +80,7 @@ sub copy_stdio {
 if ($#ARGV < 1) {
 	die "usage: test-terminal program args";
 }
+$ENV{TERM} = 'vt100';
 my $master_in = new IO::Pty;
 my $master_out = new IO::Pty;
 my $master_err = new IO::Pty;
-- 
2.14.2.1079.gce6b466188
Previous: Jeff KingNext: Jeff King
Message 24 of 42 in “Updated to v2.14.2 on macOS; git add --patch broken”
  1. Toni UebernickelSep 27, 2017
  2. Jeff KingSep 27, 2017
  3. Toni UebernickelSep 27, 2017
  4. Jeff KingSep 27, 2017
  5. Jonathan NiederSep 27, 2017
  6. Jonathan NiederSep 27, 2017
  7. Toni UebernickelSep 28, 2017
  8. Jeff KingSep 28, 2017
  9. Toni UebernickelSep 28, 2017
  10. Jonathan NiederOct 2, 2017
  11. Junio C HamanoOct 3, 2017
  12. Junio C HamanoOct 3, 2017
  13. Junio C HamanoOct 3, 2017
  14. Jeff KingOct 3, 2017
  15. Junio C HamanoOct 3, 2017
  16. Jeff KingOct 3, 2017
  17. Junio C HamanoOct 3, 2017
  18. Jeff KingOct 3, 2017
  19. Junio C HamanoOct 3, 2017
  20. Jeff KingOct 3, 2017
  21. Tsvi MostoviczOct 3, 2017
  22. Junio C HamanoOct 3, 2017
  23. Jeff KingOct 3, 2017
  24. 01/12 test-terminal: set TERM=vt100Jeff King, Oct 3, 2017
  25. 02/12 t4015: prefer --color to -c color.diff=alwaysJeff King, Oct 3, 2017
  26. 03/12 t4015: use --color with --color-movedJeff King, Oct 3, 2017
  27. 04/12 t3701: use test-terminal to collect color outputJeff King, Oct 3, 2017
  28. 05/12 t7508: use test_terminal for color outputJeff King, Oct 3, 2017
  29. 06/12 t7502: use diff.noprefix for --verbose testJeff King, Oct 3, 2017
  30. 07/12 t6006: drop "always" color config testsJeff King, Oct 3, 2017
  31. 08/12 t3203: drop "always" color testJeff King, Oct 3, 2017
  32. 09/12 t7301: use test_terminal to check colorJeff King, Oct 3, 2017
  33. 10/12 t3205: use --color instead of color.branch=alwaysJeff King, Oct 3, 2017
  34. 11/12 provide --color option for all ref-filter usersJeff King, Oct 3, 2017
  35. 12/12 color: make "always" the same as "auto" in configJeff King, Oct 3, 2017
  36. Junio C HamanoOct 4, 2017
  37. Jeff KingOct 5, 2017
  38. Jan PrachařOct 20, 2017
  39. Jeff KingOct 3, 2017
  40. 0/2 fixing "add -p" regressionJunio C Hamano, Oct 3, 2017
  41. 1/2 Revert "color: check color.ui in git_default_config()"Junio C Hamano, Oct 3, 2017
  42. 2/2 colors: git_default_config() does not read color.uiJunio C Hamano, Oct 3, 2017

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.