Subject: Re: [PATCH v4 12/20] t: refactor tests depending on Perl to print data

From: SZEDER Gábor <[email-masked]>
Date: Tue, 10 Jun 2025 21:52:39 +0200

On Thu, Apr 03, 2025 at 07:06:03AM +0200, Patrick Steinhardt wrote:
> A bunch of tests rely on Perl to print data in various different ways.
> These usages fall into the following categories:
> 
>   - Print data conditionally by matching patterns. These usecases can be
>     converted to use awk(1) rather easily.
> 
>   - Print data repeatedly. These usecases can typically be converted to
>     use a combination of `test-tool genzeros` and sed(1).
> 
>   - Print data in reverse. These usecases can be converted to use
>     awk(1) or `sort -r`.
> 
> Refactor the tests accordingly so that we can drop a couple of
> PERL_TEST_HELPERS prerequisites.
> 
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---

> diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> index 4794510d70d..2ae93d3c967 100755
> --- a/t/t4150-am.sh
> +++ b/t/t4150-am.sh
> @@ -1073,7 +1073,7 @@ test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
>  	test_cmp msg out
>  '
>  
> -test_expect_success PERL_TEST_HELPERS 'am works with multi-line in-body headers' '
> +test_expect_success 'am works with multi-line in-body headers' '
>  	FORTY="String that has a length of more than forty characters" &&
>  	LONG="$FORTY $FORTY" &&
>  	rm -fr .git/rebase-apply &&
> @@ -1084,13 +1084,13 @@ test_expect_success PERL_TEST_HELPERS 'am works with multi-line in-body headers'
>      Body test" --author="$LONG <[email-masked]>" &&
>  	git format-patch --stdout -1 >patch &&
>  	# bump from, date, and subject down to in-body header
> -	perl -lpe "
> -		if (/^From:/) {
> +	awk "
> +		/^From:/{
>  			print \"From: x <x\@example.com>\";
>  			print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
>  			print \"Subject: x\n\";
> -		}
> -	" patch >msg &&
> +		}; 1
> +	" <patch >msg &&

With the conversion to awk I get the following warning from gawk:

  awk: cmd. line:3: warning: escape sequence `\@' treated as plain `@'

>  	git checkout HEAD^ &&
>  	git am msg &&
>  	# Ensure that the author and full message are present

> diff --git a/t/t5333-pseudo-merge-bitmaps.sh b/t/t5333-pseudo-merge-bitmaps.sh
> index 1059ff45fe4..56674db562f 100755
> --- a/t/t5333-pseudo-merge-bitmaps.sh
> +++ b/t/t5333-pseudo-merge-bitmaps.sh
> @@ -6,12 +6,6 @@ GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
>  
>  . ./test-lib.sh
>  
> -if ! test_have_prereq PERL_TEST_HELPERS
> -then
> -	skip_all='skipping pseudo-merge bitmap tests; Perl not available'
> -	test_done
> -fi
> -
>  test_pseudo_merges () {
>  	test-tool bitmap dump-pseudo-merges
>  }
> @@ -34,9 +28,8 @@ test_pseudo_merges_reused () {
>  
>  tag_everything () {
>  	git rev-list --all --no-object-names >in &&
> -	perl -lne '
> -		print "create refs/tags/" . $. . " " . $1 if /([0-9a-f]+)/
> -	' <in | git update-ref --stdin
> +	sed 's|\(.*\)|create refs/tags/\1 \1|' in |
> +	git update-ref --stdin
>  }
>  
>  test_expect_success 'setup' '
> @@ -108,7 +101,7 @@ test_expect_success 'stale bitmap traversal with pseudo-merges' '
>  	test_cmp expect actual
>  '
>  
> -test_expect_success 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' '
> +test_expect_success PERL_TEST_HELPERS 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' '
>  	test_config bitmapPseudoMerge.test.pattern "refs/tags/" &&
>  	test_config bitmapPseudoMerge.test.maxMerges 1 &&
>  	test_config bitmapPseudoMerge.test.stableThreshold never &&
> @@ -241,8 +234,7 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
>  			test_commit_bulk 16 &&
>  
>  			git rev-list HEAD~16.. >in &&
> -
> -			perl -lne "print \"create refs/remotes/$r/tags/\$. \$_\"" <in |
> +			sed "s|\(.*\)|create refs/remotes/$r/tags/\1 \1" in |

This conversion results in the error:

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

I find it suspicious that the test still succeeds...

>  			git update-ref --stdin || return 1
>  		done &&
>  
> @@ -258,7 +250,7 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
>  		do
>  			test_pseudo_merge_commits $m >oids &&
>  			grep -f oids refs |
> -			perl -lne "print \$1 if /refs\/remotes\/([0-9]+)/" |
> +			sed -n "s|refs/remotes/\([0-9][0-9]*\)/|\1|p" &&
>  			sort -u || return 1
>  		done >remotes &&
>