Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 01/12] t: prepare `test_match_signal ()` calls for `set -e`
Date: Tue, 14 Apr 2026 09:23:26 +0200	[thread overview]
Message-ID: <ad3rbjDYad8rTybG@pks.im> (raw)
In-Reply-To: <xmqqldeqkesa.fsf@gitster.g>

On Mon, Apr 13, 2026 at 09:26:13AM -0700, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > We have a couple of calls to `test_match_signal ()` where we execute a
> > Git command and expect it to die with a specific signal. These calls
> > will essentially execute the process in a subshell via `foo; echo $?`,
> > but as we expect `foo` to fail this will cause the overall subshell to
> > fail once we `set -e`.
> >
> > Fix this issue by using `foo || echo $?` instead.
> 
> Hmph, if the 'foo' command that is expected to fail succeeds by a
> bug, we won't see 0 on the standard output anymore.  Comparing 13
> with 0 or 13 with an empty string "" would fail either way, so that
> may not give us a practical difference, but this somehow leaves a
> foul small in my nose.

Hm, true, it is a wee bit ugly.

> The technique used in <20260325062114.2067946-2-gitster@pobox.com>
> would give us something ugly like
> 
> -	OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
> +	OUT=$( ((st=0; large_git || st=$?; echo $st 1>&3) | :) 3>&1 ) &&
> 
> and it ensures that we give 0 when we succeed, but I am not sure if
> this is worth doing.
> 
> Or perhaps
> 
> -	OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
> +	OUT=$( ((large_git || echo $? 1>&3) | :) 3>&1 ) &&
> +	OUT=${OUT:-0} &&
> 
> I dunno.
> 
> If "large_git" somehow writes into file descriptor #3, then OUT will
> be contaminated with something other than $?, so the additional "if
> empty substitute with 0" would not work without doing something like
> 
> -	OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
> +	OUT=$( ((large_git 3>/dev/null || echo $? 1>&3) | :) 3>&1 ) &&
> +	OUT=${OUT:-0} &&
> 
> I guess.  For that matter, if large_git spits out "13" to its file
> descriptor #3, I do not know what would have happened ;-)

How about the below patch? It's a mouthful, but the intent is quite
explicit and it's overall not too bad, if you ask me.

Patrick

diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh
index 74c2a27972..84319cf169 100755
--- a/t/t0005-signals.sh
+++ b/t/t0005-signals.sh
@@ -42,12 +42,12 @@ test_expect_success 'create blob' '
 '
 
 test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
-	OUT=$( ((large_git || echo $? 1>&3) | :) 3>&1 ) &&
+	OUT=$( ((large_git && echo 0 1>&3 || echo $? 1>&3) | :) 3>&1 ) &&
 	test_match_signal 13 "$OUT"
 '
 
 test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
-	OUT=$( ((trap "" PIPE && large_git || echo $? 1>&3) | :) 3>&1 ) &&
+	OUT=$( ((trap "" PIPE && large_git && echo 0 1>&3 || echo $? 1>&3) | :) 3>&1 ) &&
 	test_match_signal 13 "$OUT"
 '
 
diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh
index 8e68a00dcb..a371ea690e 100755
--- a/t/t3600-rm.sh
+++ b/t/t3600-rm.sh
@@ -260,7 +260,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft (induce S
 
 test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' '
 	choke_git_rm_setup &&
-	OUT=$( ((trap "" PIPE && git rm -n "some-file-*" || echo $? 1>&3) | :) 3>&1 ) &&
+	OUT=$( ((trap "" PIPE && git rm -n "some-file-*" && echo 0 1>&3 || echo $? 1>&3) | :) 3>&1 ) &&
 	test_match_signal 13 "$OUT" &&
 	test_path_is_missing .git/index.lock
 '

  reply	other threads:[~2026-04-14  7:23 UTC|newest]

Thread overview: 133+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13  9:49 [PATCH 00/12] t: detect errors outside of test cases Patrick Steinhardt
2026-04-13  9:49 ` [PATCH 01/12] t: prepare `test_match_signal ()` calls for `set -e` Patrick Steinhardt
2026-04-13 16:26   ` Junio C Hamano
2026-04-14  7:23     ` Patrick Steinhardt [this message]
2026-04-14 17:49       ` Junio C Hamano
2026-04-13  9:49 ` [PATCH 02/12] t: prepare `test_must_fail ()` " Patrick Steinhardt
2026-04-13 16:33   ` Junio C Hamano
2026-04-14  7:23     ` Patrick Steinhardt
2026-04-14  6:23   ` Jeff King
2026-04-14 17:41     ` Junio C Hamano
2026-04-15  6:58       ` Patrick Steinhardt
2026-04-16  5:40         ` Jeff King
2026-04-13  9:49 ` [PATCH 03/12] t: prepare `stop_git_daemon " Patrick Steinhardt
2026-04-13 16:53   ` Junio C Hamano
2026-04-13  9:49 ` [PATCH 04/12] t: prepare `git config --unset` calls " Patrick Steinhardt
2026-04-13 16:59   ` Junio C Hamano
2026-04-13  9:49 ` [PATCH 05/12] t: prepare conditional test execution " Patrick Steinhardt
2026-04-13 17:04   ` Junio C Hamano
2026-04-13  9:49 ` [PATCH 06/12] t: prepare execution of potentially failing commands " Patrick Steinhardt
2026-04-13 17:09   ` Junio C Hamano
2026-04-14  7:23     ` Patrick Steinhardt
2026-04-14 13:41       ` Junio C Hamano
2026-04-13 22:32   ` Junio C Hamano
2026-04-14  1:09     ` Junio C Hamano
2026-04-14  7:23       ` Patrick Steinhardt
2026-04-14  7:23       ` Patrick Steinhardt
2026-04-14 13:40         ` Junio C Hamano
2026-04-14 22:03         ` Jeff King
2026-04-14 22:52           ` Jeff King
2026-04-14 23:08             ` Jeff King
2026-04-15  6:48               ` Patrick Steinhardt
2026-04-16  5:49                 ` Jeff King
2026-04-16  8:03                   ` Patrick Steinhardt
2026-04-16 14:34                   ` Junio C Hamano
2026-04-18  8:01                     ` Jeff King
2026-04-15 15:31               ` Junio C Hamano
2026-04-13  9:49 ` [PATCH 07/12] t: prepare `test_when_finished ()`/`test_atexit()` " Patrick Steinhardt
2026-04-13 17:23   ` Junio C Hamano
2026-04-14  7:24     ` Patrick Steinhardt
2026-04-13  9:49 ` [PATCH 08/12] t0008: silence error in subshell when using `grep -v` Patrick Steinhardt
2026-04-13 17:28   ` Junio C Hamano
2026-04-14  7:23     ` Patrick Steinhardt
2026-04-13  9:49 ` [PATCH 09/12] t1301: don't fail in case setfacl(1) doesn't exist or fails Patrick Steinhardt
2026-04-13  9:49 ` [PATCH 10/12] t6002: fix use of `expr` with `set -e` Patrick Steinhardt
2026-04-13  9:49 ` [PATCH 11/12] t9902: fix use of `read` " Patrick Steinhardt
2026-04-13  9:49 ` [PATCH 12/12] t: detect errors outside of test cases Patrick Steinhardt
2026-04-13 17:29   ` Junio C Hamano
2026-04-13 21:33 ` [PATCH 00/12] " Junio C Hamano
2026-04-13 21:46   ` Junio C Hamano
2026-04-15 13:06 ` [PATCH v2 " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 01/12] t: prepare `test_match_signal ()` calls for `set -e` Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 02/12] t: prepare `test_must_fail ()` " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 03/12] t: prepare `stop_git_daemon " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 04/12] t: prepare `git config --unset` calls " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 05/12] t: prepare conditional test execution " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 06/12] t: prepare execution of potentially failing commands " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 07/12] t: prepare `test_when_finished ()`/`test_atexit()` " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 08/12] t0008: silence error in subshell when using `grep -v` Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 09/12] t1301: don't fail in case setfacl(1) doesn't exist or fails Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 10/12] t6002: fix use of `expr` with `set -e` Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 11/12] t9902: fix use of `read` " Patrick Steinhardt
2026-04-15 13:06   ` [PATCH v2 12/12] t: detect errors outside of test cases Patrick Steinhardt
2026-04-16  6:00     ` Jeff King
2026-04-16 10:46       ` Patrick Steinhardt
2026-04-16 11:19 ` [PATCH v3 00/12] " Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 01/12] t: prepare `test_match_signal ()` calls for `set -e` Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 02/12] t: prepare `test_must_fail ()` " Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 03/12] t: prepare `stop_git_daemon " Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 04/12] t: prepare `git config --unset` calls " Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 05/12] t: prepare conditional test execution " Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 06/12] t: prepare execution of potentially failing commands " Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 07/12] t: prepare `test_when_finished ()`/`test_atexit()` " Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 08/12] t0008: silence error in subshell when using `grep -v` Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 09/12] t1301: don't fail in case setfacl(1) doesn't exist or fails Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 10/12] t6002: fix use of `expr` with `set -e` Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 11/12] t9902: fix use of `read` " Patrick Steinhardt
2026-04-16 20:12     ` SZEDER Gábor
2026-04-16 20:42       ` Junio C Hamano
2026-04-17  9:44         ` Patrick Steinhardt
2026-04-16 11:19   ` [PATCH v3 12/12] t: detect errors outside of test cases Patrick Steinhardt
2026-04-16 16:06     ` Junio C Hamano
2026-04-17 10:50 ` [PATCH v4 00/12] " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 01/12] t: prepare `test_match_signal ()` calls for `set -e` Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 02/12] t: prepare `test_must_fail ()` " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 03/12] t: prepare `stop_git_daemon " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 04/12] t: prepare `git config --unset` calls " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 05/12] t: prepare conditional test execution " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 06/12] t: prepare execution of potentially failing commands " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 07/12] t: prepare `test_when_finished ()`/`test_atexit()` " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 08/12] t0008: silence error in subshell when using `grep -v` Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 09/12] t1301: don't fail in case setfacl(1) doesn't exist or fails Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 10/12] t6002: fix use of `expr` with `set -e` Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 11/12] t9902: fix use of `read` " Patrick Steinhardt
2026-04-17 10:50   ` [PATCH v4 12/12] t: detect errors outside of test cases Patrick Steinhardt
2026-04-18  6:50     ` Jeff King
2026-04-18 12:17       ` Ben Knoble
2026-04-18 17:44         ` Jeff King
2026-04-18 19:24           ` Junio C Hamano
2026-04-18 21:05             ` Jeff King
2026-04-20  6:11               ` Patrick Steinhardt
2026-04-18 19:17         ` brian m. carlson
2026-04-18 21:30           ` Jeff King
2026-04-18 21:54             ` brian m. carlson
2026-04-19  2:10               ` Jeff King
2026-04-20  7:27 ` [PATCH v5 00/12] " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 01/12] t: prepare `test_match_signal ()` calls for `set -e` Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 02/12] t: prepare `test_must_fail ()` " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 03/12] t: prepare `stop_git_daemon " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 04/12] t: prepare `git config --unset` calls " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 05/12] t: prepare conditional test execution " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 06/12] t: prepare execution of potentially failing commands " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 07/12] t: prepare `test_when_finished ()`/`test_atexit()` " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 08/12] t0008: silence error in subshell when using `grep -v` Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 09/12] t1301: don't fail in case setfacl(1) doesn't exist or fails Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 10/12] t6002: fix use of `expr` with `set -e` Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 11/12] t9902: fix use of `read` " Patrick Steinhardt
2026-04-20  7:27   ` [PATCH v5 12/12] t: detect errors outside of test cases Patrick Steinhardt
2026-04-20 16:19   ` [PATCH v5 00/12] " Junio C Hamano
2026-04-21  3:00     ` Jeff King
2026-04-21  5:41       ` Patrick Steinhardt
2026-04-21  7:34 ` [PATCH v6 " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 01/12] t: prepare `test_match_signal ()` calls for `set -e` Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 02/12] t: prepare `test_must_fail ()` " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 03/12] t: prepare `stop_git_daemon " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 04/12] t: prepare `git config --unset` calls " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 05/12] t: prepare conditional test execution " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 06/12] t: prepare execution of potentially failing commands " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 07/12] t: prepare `test_when_finished ()`/`test_atexit()` " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 08/12] t0008: silence error in subshell when using `grep -v` Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 09/12] t1301: don't fail in case setfacl(1) doesn't exist or fails Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 10/12] t6002: fix use of `expr` with `set -e` Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 11/12] t9902: fix use of `read` " Patrick Steinhardt
2026-04-21  7:34   ` [PATCH v6 12/12] t: detect errors outside of test cases Patrick Steinhardt

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=ad3rbjDYad8rTybG@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@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