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

Re: [PATCH v2 2/6] t/test-lib: don't print shell traces to stdout

From
Junio C Hamano <gitster@pobox.com>
Date
May 27, 2025, 19:47 UTC
Message-ID
<xmqqh615vnt7.fsf@gitster.g>
In-Reply-To
<20250527-pks-meson-tap-v2-2-ae360f77786e@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 20 quoted lines
> We have several flags like "--verbose", "--verbose-only" or "-x" that
> cause us to generate shell traces. The generated tracing output is split
> up in these cases so that the test's stdout is printed to file
> descriptor 3 whereas its stderr is printed to file descriptor 4.
> Depending on which options have been given, we then end up either:
>
>   - Redirecting both file descriptors to a file.
>
>   - Redirecting them to stdout and stderr, respectively.
>
>   - Closing them in case we're running in none-verbose mode.
>
> The second case causes problems though when passing output to a TAP
> parser. We print the test's stdout to the console's stdout, and that
> results in broken TAP output.
>
> Fix the issue by instead redirecting the test's stdout to the shell's
> stderr. This makes it impossible to discern stdout from stderr, but
> going by my own experience I never came across a usecase where I would
> have needed this distinction.

OK, so both stdout and stderr go to stderr, mixing everything into a single stream. Do we need to worry about funny buffering making the test output harder to verify? I mean, we only have to care about the ordering of lines within the original standard output (or standard error) stream independently, but now if the test thinks it wrote A to its stderr, then B to its stdout, and then C to its stderr, would we get them in the single output stream as A followed by B followed by C, or can sometimes buffered output can give us A then C then finally B?

Just an idle thought. What makes me more confused is that the updated t0000 tests seem to say that we now check standard output and standard error separately.

Show 93 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  t/t0000-basic.sh | 35 +++++++++++++++++++----------------
>  t/test-lib.sh    |  4 ++--
>  2 files changed, 21 insertions(+), 18 deletions(-)
>
> diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
> index 35c5c2b4f9b..16b785f3b91 100755
> --- a/t/t0000-basic.sh
> +++ b/t/t0000-basic.sh
> @@ -219,41 +219,44 @@ test_expect_success 'subtest: --verbose option' '
>  	test_expect_success "failing test" false
>  	test_done
>  	EOF
> -	mv t1234-verbose/out t1234-verbose/out+ &&
> -	grep -v "^Initialized empty" t1234-verbose/out+ >t1234-verbose/out &&
> -	check_sub_test_lib_test t1234-verbose <<-\EOF
> -	> expecting success of 1234.1 '\''passing test'\'': true
> +	mv t1234-verbose/err t1234-verbose/err+ &&
> +	grep -v "^Initialized empty" t1234-verbose/err+ >t1234-verbose/err &&
> +	check_sub_test_lib_test_err t1234-verbose \
> +		<<-\EOF_OUT 3<<-\EOF_ERR
>  	> ok 1 - passing test
> +	> ok 2 - test with output
> +	> not ok 3 - failing test
> +	> #	false
> +	> # failed 1 among 3 test(s)
> +	> 1..3
> +	EOF_OUT
> +	> expecting success of 1234.1 '\''passing test'\'': true
>  	> Z
>  	> expecting success of 1234.2 '\''test with output'\'': echo foo
>  	> foo
> -	> ok 2 - test with output
>  	> Z
>  	> expecting success of 1234.3 '\''failing test'\'': false
> -	> not ok 3 - failing test
> -	> #	false
>  	> Z
> -	> # failed 1 among 3 test(s)
> -	> 1..3
> -	EOF
> +	EOF_ERR
>  '
>  
>  test_expect_success 'subtest: --verbose-only option' '
>  	run_sub_test_lib_test_err \
>  		t1234-verbose \
>  		--verbose-only=2 &&
> -	check_sub_test_lib_test t1234-verbose <<-\EOF
> +	check_sub_test_lib_test_err t1234-verbose <<-\EOF_OUT 3<<-\EOF_ERR
>  	> ok 1 - passing test
> -	> Z
> -	> expecting success of 1234.2 '\''test with output'\'': echo foo
> -	> foo
>  	> ok 2 - test with output
> -	> Z
>  	> not ok 3 - failing test
>  	> #	false
>  	> # failed 1 among 3 test(s)
>  	> 1..3
> -	EOF
> +	EOF_OUT
> +	> Z
> +	> expecting success of 1234.2 '\''test with output'\'': echo foo
> +	> foo
> +	> Z
> +	EOF_ERR
>  '
>  
>  test_expect_success 'subtest: skip one with GIT_SKIP_TESTS' '
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index af722d383d9..6ce8570226c 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -707,7 +707,7 @@ then
>  	exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3
>  elif test "$verbose" = "t"
>  then
> -	exec 4>&2 3>&1
> +	exec 4>&2 3>&2
>  else
>  	exec 4>/dev/null 3>/dev/null
>  fi
> @@ -949,7 +949,7 @@ maybe_setup_verbose () {
>  	test -z "$verbose_only" && return
>  	if match_pattern_list $test_count "$verbose_only"
>  	then
> -		exec 4>&2 3>&1
> +		exec 4>&2 3>&2
>  		# Emit a delimiting blank line when going from
>  		# non-verbose to verbose.  Within verbose mode the
>  		# delimiter is printed by test_expect_*.  The choice
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 41 of 79 in “meson: parse TAP output generated by our tests”
  1. 0/4 meson: parse TAP output generated by our testsPatrick Steinhardt, May 6, 2025
  2. 1/4 t: fix cases where output breaks TAP formatPatrick Steinhardt, May 6, 2025
  3. Phillip WoodMay 6, 2025
  4. Patrick SteinhardtMay 7, 2025
  5. Phillip WoodMay 7, 2025
  6. Karthik NayakMay 14, 2025
  7. 2/4 t/test-lib: don't print shell traces to stdoutPatrick Steinhardt, May 6, 2025
  8. 3/4 meson: introduce kwargs variable for testsPatrick Steinhardt, May 6, 2025
  9. Karthik NayakMay 15, 2025
  10. 4/4 meson: parse TAP output generated by our testsPatrick Steinhardt, May 6, 2025
  11. Karthik NayakMay 15, 2025
  12. Patrick SteinhardtMay 15, 2025
  13. Karthik NayakMay 15, 2025
  14. Patrick SteinhardtMay 6, 2025
  15. Patrick SteinhardtMay 7, 2025
  16. Patrick SteinhardtMay 21, 2025
  17. Hridoy AhmedMay 21, 2025
  18. Junio C HamanoMay 21, 2025
  19. Junio C HamanoMay 21, 2025
  20. Patrick SteinhardtMay 23, 2025
  21. Patrick SteinhardtMay 23, 2025
  22. Junio C HamanoMay 23, 2025
  23. Ramsay JonesMay 23, 2025
  24. Ramsay JonesMay 23, 2025
  25. Junio C HamanoMay 23, 2025
  26. Patrick SteinhardtMay 26, 2025
  27. Phillip WoodMay 26, 2025
  28. Todd ZullingerMay 26, 2025
  29. Eli SchwartzMay 26, 2025
  30. Patrick SteinhardtMay 26, 2025
  31. Junio C HamanoMay 27, 2025
  32. Patrick SteinhardtMay 28, 2025
  33. Junio C HamanoMay 27, 2025
  34. 0/6 meson: parse TAP output generated by our testsPatrick Steinhardt, May 27, 2025
  35. 1/6 t: fix cases where output breaks TAP formatPatrick Steinhardt, May 27, 2025
  36. Eric SunshineMay 27, 2025
  37. Patrick SteinhardtMay 28, 2025
  38. Eric SunshineMay 28, 2025
  39. Patrick SteinhardtMay 30, 2025
  40. 2/6 t/test-lib: don't print shell traces to stdoutPatrick Steinhardt, May 27, 2025
  41. Junio C HamanoMay 27, 2025
  42. Patrick SteinhardtMay 28, 2025
  43. 3/6 t/test-lib: fix TAP format for BASH_XTRACEFD warningPatrick Steinhardt, May 27, 2025
  44. 4/6 t7815: fix unexpectedly passing test on macOSPatrick Steinhardt, May 27, 2025
  45. 6/6 meson: parse TAP output generated by our testsPatrick Steinhardt, May 27, 2025
  46. 5/6 meson: introduce kwargs variable for testsPatrick Steinhardt, May 27, 2025
  47. 00/10 meson: parse TAP output generated by our testsPatrick Steinhardt, May 30, 2025
  48. 01/10 t: stop announcing prereqsPatrick Steinhardt, May 30, 2025
  49. Karthik NayakMay 31, 2025
  50. 03/10 t9822: use prereq to check for ISO-8859-1 supportPatrick Steinhardt, May 30, 2025
  51. 02/10 t: silence output from `test_create_repo()`Patrick Steinhardt, May 30, 2025
  52. Eric SunshineMay 30, 2025
  53. 04/10 t983*: use prereq to check for Python-specific git-b4(1) supportPatrick Steinhardt, May 30, 2025
  54. Todd ZullingerMay 30, 2025
  55. Patrick SteinhardtMay 30, 2025
  56. 05/10 t/test-lib: don't print shell traces to stdoutPatrick Steinhardt, May 30, 2025
  57. Karthik NayakMay 31, 2025
  58. 06/10 t/test-lib: fix TAP format for BASH_XTRACEFD warningPatrick Steinhardt, May 30, 2025
  59. Karthik NayakMay 31, 2025
  60. 07/10 t7815: fix unexpectedly passing test on macOSPatrick Steinhardt, May 30, 2025
  61. Karthik NayakMay 31, 2025
  62. Kristoffer HaugsbakkJun 1, 2025
  63. Patrick SteinhardtJun 2, 2025
  64. 08/10 test-lib: fail on unexpectedly passing testsPatrick Steinhardt, May 30, 2025
  65. 09/10 meson: introduce kwargs variable for testsPatrick Steinhardt, May 30, 2025
  66. 10/10 meson: parse TAP output generated by our testsPatrick Steinhardt, May 30, 2025
  67. Karthik NayakMay 31, 2025
  68. 00/10 meson: parse TAP output generated by our testsPatrick Steinhardt, Jun 2, 2025
  69. 01/10 t: stop announcing prereqsPatrick Steinhardt, Jun 2, 2025
  70. 02/10 t: silence output from `test_create_repo()`Patrick Steinhardt, Jun 2, 2025
  71. 03/10 t9822: use prereq to check for ISO-8859-1 supportPatrick Steinhardt, Jun 2, 2025
  72. 04/10 t983*: use prereq to check for Python-specific git-p4(1) supportPatrick Steinhardt, Jun 2, 2025
  73. 06/10 t/test-lib: fix TAP format for BASH_XTRACEFD warningPatrick Steinhardt, Jun 2, 2025
  74. 05/10 t/test-lib: don't print shell traces to stdoutPatrick Steinhardt, Jun 2, 2025
  75. 08/10 test-lib: fail on unexpectedly passing testsPatrick Steinhardt, Jun 2, 2025
  76. 07/10 t7815: fix unexpectedly passing test on macOSPatrick Steinhardt, Jun 2, 2025
  77. 09/10 meson: introduce kwargs variable for testsPatrick Steinhardt, Jun 2, 2025
  78. 10/10 meson: parse TAP output generated by our testsPatrick Steinhardt, Jun 2, 2025
  79. Karthik NayakJun 2, 2025

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.