Re: [PATCH v3 17/20] t0021: refactor `generate_random_characters()` to not depend on Perl
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Apr 1, 2025, 19:04 UTC
- Message-ID
- <92fd1e8b-4790-0c81-409a-be81aed9f290@gmx.de>
- In-Reply-To
- <20250327-b4-pks-t-perlless-v3-17-b436de9da1b8@pks.im>
Hi Patrick,
On Thu, 27 Mar 2025, Patrick Steinhardt wrote:
Show 10 quoted lines
> The `generate_random_characters()` helper function generates N > random characters in the range 'a-z' and writes them into a file. The > logic currently uses Perl, but it can be adapted rather easily by: > > - Making `test-tool genrandom` generate an infinite stream. > > - Using `tr -dc` to strip all characters which aren't in the range of > 'a-z'. > > - Using `test_copy_bytes()` to copy the first N bytes.
It would be conceptually more elegant to teach `genrandom` to optionally output only lower-case letters. But that would be admittedly result in a larger patch, therefore I am okay with keeping the patch as-is.
Ciao, Johannes
Show 45 quoted lines
>
> This allows us to drop the PERL_TEST_HELPERS prerequisite.
>
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> t/t0021-conversion.sh | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
> index 4a892a91780..bf10d253ec4 100755
> --- a/t/t0021-conversion.sh
> +++ b/t/t0021-conversion.sh
> @@ -20,8 +20,7 @@ EOF
> generate_random_characters () {
> LEN=$1
> NAME=$2
> - test-tool genrandom some-seed $LEN |
> - perl -pe "s/./chr((ord($&) % 26) + ord('a'))/sge" >"$TEST_ROOT/$NAME"
> + test-tool genrandom some-seed | tr -dc 'a-z' | test_copy_bytes "$LEN" >"$TEST_ROOT/$NAME"
> }
>
> filter_git () {
> @@ -619,7 +618,7 @@ test_expect_success 'required process filter should be used only for "clean" ope
> )
> '
>
> -test_expect_success PERL_TEST_HELPERS 'required process filter should process multiple packets' '
> +test_expect_success 'required process filter should process multiple packets' '
> test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
> test_config_global filter.protocol.required true &&
>
> @@ -684,7 +683,7 @@ test_expect_success PERL_TEST_HELPERS 'required process filter should process mu
> )
> '
>
> -test_expect_success PERL_TEST_HELPERS 'required process filter with clean error should fail' '
> +test_expect_success 'required process filter with clean error should fail' '
> test_config_global filter.protocol.process "test-tool rot13-filter --log=debug.log clean smudge" &&
> test_config_global filter.protocol.required true &&
> rm -rf repo &&
>
> --
> 2.49.0.472.ge94155a9ec.dirty
>
>