threads / patch / 63752

patch, 2 partst: fixes for Perl-less tests

Subject: [PATCH 0/2] t: fixes for Perl-less tests

## tl;dr

5 messages between Jul 7, 2025 and Jul 8, 2025. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

Patrick Steinhardt· Jul 7, 2025, 11:08 UTC · lore
Hi,

this small patch series addresses two issues introduced by my conversion away from Perl in some of our tests, as reported by SZEDER [1].

Thanks!
Patrick
[1]: <aEiNBwUkjbo2QlFY@szeder.dev>
---
Patrick Steinhardt (2):
      t4150: fix warning printed by awk due to escaped '\@'
      t5333: fix missing terminator for sed(1) 's' command
 t/t4150-am.sh                   | 2 +-
 t/t5333-pseudo-merge-bitmaps.sh | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

--- base-commit: 8b6f19ccfc3aefbd0f22f6b7d56ad6a3fc5e4f37 change-id: 20250707-b4-pks-t-perlless-fixes-4dd2280de666

Patrick Steinhardt· Jul 7, 2025, 11:08 UTC · re: Patrick Steinhardt · lore

[PATCH 1/2] t4150: fix warning printed by awk due to escaped '\@'

In 6aec8d38fdd (t: refactor tests depending on Perl to print data, 2025-04-03) we have changed one of the tests in t4150 to use awk(1) instead of Perl. The test works, but at least gawk(1) prints a warning now:

    awk: cmd. line:3: warning: escape sequence `\@' treated as plain `@'
Fix this by removing the backslash.
Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t4150-am.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to t/t4150-am.sh +1 −1
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index 2ae93d3c967..699a81ab5cc 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -1086,7 +1086,7 @@ test_expect_success 'am works with multi-line in-body headers' '
 	# bump from, date, and subject down to in-body header
 	awk "
 		/^From:/{
-			print \"From: x <x\@example.com>\";
+			print \"From: x <x@example.com>\";
 			print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
 			print \"Subject: x\n\";
 		}; 1
-- 
2.50.0.195.g74e6fc65d0.dirty
Patrick Steinhardt· Jul 7, 2025, 11:08 UTC · re: Patrick Steinhardt · lore

[PATCH 2/2] t5333: fix missing terminator for sed(1) 's' command

In 6aec8d38fdd (t: refactor tests depending on Perl to print data, 2025-04-03) we have changed some of the tests in t4150 to use sed(1) instead of Perl. One of the conversions is broken though:

    sed: -e expression #1, char 41: unterminated `s' command

Curiously enough, the test itself still passes. This is caused by a sequence of failures:

  1. The output of sed(1) is piped into git-update-ref(1), and because
     sed(1) is the upstream command we don't notice that it fails.
  2. git-update-ref(1) does not receive any input and thus won't create
     any references.
  3. We then repack the repository with the configured pseudo merges
     pattern, but as we didn't create any references the pattern doesn't
     match anything.
  4. We use `test_pseudo_merges()` to compute the list of pseudo-merges
     and write it into a file. This file is empty as there are none.
  5. The loop over the pseudo-merges becomes a no-op.
  6. The final test succeeds as well because the number of lines in an
     empty file is obviously the same as the number of unique lines,
     namely zero.

Fix the issue by adding the terminating '|' to the sed(1) command. Furthermore, make the test a tiny bit more robust by not using it as part of a pipe.

Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t5333-pseudo-merge-bitmaps.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to t/t5333-pseudo-merge-bitmaps.sh +2 −2
diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh
index ba5ae6a00c9..1f7a5d82ee4 100755
--- a/t/t5333-pseudo-merge-bitmaps.sh
+++ b/t/t5333-pseudo-merge-bitmaps.sh
@@ -234,8 +234,8 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
 			test_commit_bulk 16 &&
 
 			git rev-list HEAD~16.. >in &&
-			sed "s|\(.*\)|create refs/remotes/$r/tags/\1 \1" in |
-			git update-ref --stdin || return 1
+			sed "s|\(.*\)|create refs/remotes/$r/tags/\1 \1|" in >refs &&
+			git update-ref --stdin <refs || return 1
 		done &&
 
 		git \
-- 
2.50.0.195.g74e6fc65d0.dirty
Junio C Hamano· Jul 7, 2025, 16:15 UTC · re: Patrick Steinhardt · lore

Re: [PATCH 2/2] t5333: fix missing terminator for sed(1) 's' command

Patrick Steinhardt <ps@pks.im> writes:
Show 29 quoted lines
> In 6aec8d38fdd (t: refactor tests depending on Perl to print data,
> 2025-04-03) we have changed some of the tests in t4150 to use sed(1)
> instead of Perl. One of the conversions is broken though:
>
>     sed: -e expression #1, char 41: unterminated `s' command
>
> Curiously enough, the test itself still passes. This is caused by a
> sequence of failures:
>
>   1. The output of sed(1) is piped into git-update-ref(1), and because
>      sed(1) is the upstream command we don't notice that it fails.
>
>   2. git-update-ref(1) does not receive any input and thus won't create
>      any references.
>
>   3. We then repack the repository with the configured pseudo merges
>      pattern, but as we didn't create any references the pattern doesn't
>      match anything.
>
>   4. We use `test_pseudo_merges()` to compute the list of pseudo-merges
>      and write it into a file. This file is empty as there are none.
>
>   5. The loop over the pseudo-merges becomes a no-op.
>
>   6. The final test succeeds as well because the number of lines in an
>      empty file is obviously the same as the number of unique lines,
>      namely zero.
>
> Fix the issue by adding the terminating '|' to the sed(1) command.
OK.
> Furthermore, make the test a tiny bit more robust by not using it as
> part of a pipe.

While I do not think it would give us big enough improvement to revert this part of the change, I would have liked not to see this "furthermore" change. We are not in the business of catching segfault in 'sed' that is supplied by the platform, so there is no point in breaking the pipeline here.

Will queue.  Thanks.
Show 21 quoted lines
> Reported-by: SZEDER Gábor <szeder.dev@gmail.com>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
>  t/t5333-pseudo-merge-bitmaps.sh | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh
> index ba5ae6a00c9..1f7a5d82ee4 100755
> --- a/t/t5333-pseudo-merge-bitmaps.sh
> +++ b/t/t5333-pseudo-merge-bitmaps.sh
> @@ -234,8 +234,8 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
>  			test_commit_bulk 16 &&
>  
>  			git rev-list HEAD~16.. >in &&
> -			sed "s|\(.*\)|create refs/remotes/$r/tags/\1 \1" in |
> -			git update-ref --stdin || return 1
> +			sed "s|\(.*\)|create refs/remotes/$r/tags/\1 \1|" in >refs &&
> +			git update-ref --stdin <refs || return 1
>  		done &&
>  
>  		git \
Patrick Steinhardt· Jul 8, 2025, 06:44 UTC · re: Junio C Hamano · lore

Re: [PATCH 2/2] t5333: fix missing terminator for sed(1) 's' command

On Mon, Jul 07, 2025 at 09:15:49AM -0700, Junio C Hamano wrote:
Show 44 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
> 
> > In 6aec8d38fdd (t: refactor tests depending on Perl to print data,
> > 2025-04-03) we have changed some of the tests in t4150 to use sed(1)
> > instead of Perl. One of the conversions is broken though:
> >
> >     sed: -e expression #1, char 41: unterminated `s' command
> >
> > Curiously enough, the test itself still passes. This is caused by a
> > sequence of failures:
> >
> >   1. The output of sed(1) is piped into git-update-ref(1), and because
> >      sed(1) is the upstream command we don't notice that it fails.
> >
> >   2. git-update-ref(1) does not receive any input and thus won't create
> >      any references.
> >
> >   3. We then repack the repository with the configured pseudo merges
> >      pattern, but as we didn't create any references the pattern doesn't
> >      match anything.
> >
> >   4. We use `test_pseudo_merges()` to compute the list of pseudo-merges
> >      and write it into a file. This file is empty as there are none.
> >
> >   5. The loop over the pseudo-merges becomes a no-op.
> >
> >   6. The final test succeeds as well because the number of lines in an
> >      empty file is obviously the same as the number of unique lines,
> >      namely zero.
> >
> > Fix the issue by adding the terminating '|' to the sed(1) command.
> 
> OK.
> 
> > Furthermore, make the test a tiny bit more robust by not using it as
> > part of a pipe.
> 
> While I do not think it would give us big enough improvement to
> revert this part of the change, I would have liked not to see this
> "furthermore" change.  We are not in the business of catching
> segfault in 'sed' that is supplied by the platform, so there is no
> point in breaking the pipeline here.
> 
> Will queue.  Thanks.

Segfaults not, but if the pipeline was broken up from the beginning we would have noticed that sed(1) returned an error due to the missing separator. True though that it doesn't buy us much now that the error is fixed. It's not like this line of code is likely to change regularly in the future.

I'll not send a new version of this patch series to get rid of it, but if I need to resend I'll remove that part.

Thanks!
Patrick

← back to recent threads