git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org,  Phillip Wood <phillip.wood123@gmail.com>,
	 Karthik Nayak <karthik.188@gmail.com>,
	 Ramsay Jones <ramsay@ramsayjones.plus.com>,
	 Eli Schwartz <eschwartz@gentoo.org>,
	 Todd Zullinger <tmz@pobox.com>
Subject: Re: [PATCH v2 2/6] t/test-lib: don't print shell traces to stdout
Date: Tue, 27 May 2025 12:47:00 -0700	[thread overview]
Message-ID: <xmqqh615vnt7.fsf@gitster.g> (raw)
In-Reply-To: <20250527-pks-meson-tap-v2-2-ae360f77786e@pks.im> (Patrick Steinhardt's message of "Tue, 27 May 2025 16:02:50 +0200")

Patrick Steinhardt <ps@pks.im> writes:

> 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.

> 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

  reply	other threads:[~2025-05-27 19:47 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 10:59 [PATCH 0/4] meson: parse TAP output generated by our tests Patrick Steinhardt
2025-05-06 10:59 ` [PATCH 1/4] t: fix cases where output breaks TAP format Patrick Steinhardt
2025-05-06 13:17   ` Phillip Wood
2025-05-07  6:52     ` Patrick Steinhardt
2025-05-07 10:12       ` Phillip Wood
2025-05-14 18:51   ` Karthik Nayak
2025-05-06 10:59 ` [PATCH 2/4] t/test-lib: don't print shell traces to stdout Patrick Steinhardt
2025-05-06 10:59 ` [PATCH 3/4] meson: introduce kwargs variable for tests Patrick Steinhardt
2025-05-15  7:39   ` Karthik Nayak
2025-05-06 10:59 ` [PATCH 4/4] meson: parse TAP output generated by our tests Patrick Steinhardt
2025-05-15  7:48   ` Karthik Nayak
2025-05-15  8:20     ` Patrick Steinhardt
2025-05-15 11:35       ` Karthik Nayak
2025-05-06 12:29 ` [PATCH 0/4] " Patrick Steinhardt
2025-05-07  7:06   ` Patrick Steinhardt
2025-05-21 10:57 ` Patrick Steinhardt
2025-05-21 11:56   ` Hridoy Ahmed
2025-05-21 16:06   ` Junio C Hamano
2025-05-21 21:26     ` Junio C Hamano
2025-05-23 10:03       ` Patrick Steinhardt
2025-05-23 15:00         ` Patrick Steinhardt
2025-05-23 15:58           ` Junio C Hamano
2025-05-23 16:40             ` Ramsay Jones
2025-05-23 16:53               ` Ramsay Jones
2025-05-23 19:33               ` Junio C Hamano
2025-05-26 12:44                 ` Patrick Steinhardt
2025-05-26 13:31                   ` Phillip Wood
2025-05-26 14:23                     ` Todd Zullinger
2025-05-26 13:54                   ` Eli Schwartz
2025-05-26 13:59                     ` Patrick Steinhardt
2025-05-27 16:04                       ` Junio C Hamano
2025-05-28 12:27                         ` Patrick Steinhardt
2025-05-27 13:36                   ` Junio C Hamano
2025-05-27 14:02 ` [PATCH v2 0/6] " Patrick Steinhardt
2025-05-27 14:02   ` [PATCH v2 1/6] t: fix cases where output breaks TAP format Patrick Steinhardt
2025-05-27 19:47     ` Eric Sunshine
2025-05-28 15:55       ` Patrick Steinhardt
2025-05-28 20:14         ` Eric Sunshine
2025-05-30  7:50           ` Patrick Steinhardt
2025-05-27 14:02   ` [PATCH v2 2/6] t/test-lib: don't print shell traces to stdout Patrick Steinhardt
2025-05-27 19:47     ` Junio C Hamano [this message]
2025-05-28 15:55       ` Patrick Steinhardt
2025-05-27 14:02   ` [PATCH v2 3/6] t/test-lib: fix TAP format for BASH_XTRACEFD warning Patrick Steinhardt
2025-05-27 14:02   ` [PATCH v2 4/6] t7815: fix unexpectedly passing test on macOS Patrick Steinhardt
2025-05-27 14:02   ` [PATCH v2 5/6] meson: introduce kwargs variable for tests Patrick Steinhardt
2025-05-27 14:02   ` [PATCH v2 6/6] meson: parse TAP output generated by our tests Patrick Steinhardt
2025-05-30 13:31 ` [PATCH v3 00/10] " Patrick Steinhardt
2025-05-30 13:31   ` [PATCH v3 01/10] t: stop announcing prereqs Patrick Steinhardt
2025-05-31 21:00     ` Karthik Nayak
2025-05-30 13:31   ` [PATCH v3 02/10] t: silence output from `test_create_repo()` Patrick Steinhardt
2025-05-30 21:16     ` Eric Sunshine
2025-05-30 13:31   ` [PATCH v3 03/10] t9822: use prereq to check for ISO-8859-1 support Patrick Steinhardt
2025-05-30 13:31   ` [PATCH v3 04/10] t983*: use prereq to check for Python-specific git-b4(1) support Patrick Steinhardt
2025-05-30 14:08     ` Todd Zullinger
2025-05-30 14:21       ` Patrick Steinhardt
2025-05-30 13:31   ` [PATCH v3 05/10] t/test-lib: don't print shell traces to stdout Patrick Steinhardt
2025-05-31 21:21     ` Karthik Nayak
2025-05-30 13:31   ` [PATCH v3 06/10] t/test-lib: fix TAP format for BASH_XTRACEFD warning Patrick Steinhardt
2025-05-31 21:25     ` Karthik Nayak
2025-05-30 13:31   ` [PATCH v3 07/10] t7815: fix unexpectedly passing test on macOS Patrick Steinhardt
2025-05-31 21:28     ` Karthik Nayak
2025-06-01  9:19     ` Kristoffer Haugsbakk
2025-06-02  6:19       ` Patrick Steinhardt
2025-05-30 13:31   ` [PATCH v3 08/10] test-lib: fail on unexpectedly passing tests Patrick Steinhardt
2025-05-30 13:31   ` [PATCH v3 09/10] meson: introduce kwargs variable for tests Patrick Steinhardt
2025-05-30 13:31   ` [PATCH v3 10/10] meson: parse TAP output generated by our tests Patrick Steinhardt
2025-05-31 21:37   ` [PATCH v3 00/10] " Karthik Nayak
2025-06-02  6:44 ` [PATCH v4 " Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 01/10] t: stop announcing prereqs Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 02/10] t: silence output from `test_create_repo()` Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 03/10] t9822: use prereq to check for ISO-8859-1 support Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 04/10] t983*: use prereq to check for Python-specific git-p4(1) support Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 05/10] t/test-lib: don't print shell traces to stdout Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 06/10] t/test-lib: fix TAP format for BASH_XTRACEFD warning Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 07/10] t7815: fix unexpectedly passing test on macOS Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 08/10] test-lib: fail on unexpectedly passing tests Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 09/10] meson: introduce kwargs variable for tests Patrick Steinhardt
2025-06-02  6:44   ` [PATCH v4 10/10] meson: parse TAP output generated by our tests Patrick Steinhardt
2025-06-02  7:40   ` [PATCH v4 00/10] " Karthik Nayak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqh615vnt7.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=eschwartz@gentoo.org \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    --cc=phillip.wood123@gmail.com \
    --cc=ps@pks.im \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=tmz@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).