]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t0021: refactor `generate_random_characters()` to not depend on Perl
authorPatrick Steinhardt <ps@pks.im>
Thu, 3 Apr 2025 05:06:08 +0000 (07:06 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Apr 2025 21:47:40 +0000 (14:47 -0700)
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.

This allows us to drop the PERL_TEST_HELPERS prerequisite.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t0021-conversion.sh

index 4a892a917807001d604a6113e245ce5ca692d3e5..bf10d253ec40991a077ae985857781542b14aec8 100755 (executable)
@@ -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 &&