]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: refactor tests depending on Perl to print data
authorPatrick Steinhardt <ps@pks.im>
Thu, 3 Apr 2025 05:06:03 +0000 (07:06 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Apr 2025 21:47:39 +0000 (14:47 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
14 files changed:
t/t0610-reftable-basics.sh
t/t0613-reftable-write-options.sh
t/t1010-mktree.sh
t/t4150-am.sh
t/t5300-pack-object.sh
t/t5326-multi-pack-bitmaps.sh
t/t5333-pseudo-merge-bitmaps.sh
t/t5410-receive-pack-alternates.sh
t/t5701-git-serve.sh
t/t6013-rev-list-reverse-parents.sh
t/t6115-rev-list-du.sh
t/t7006-pager.sh
t/t8002-blame.sh
t/t9850-shell.sh

index 5e0a1fa176dbd763295ab2be5e8528b8a98051cf..77ed11e717220f20794c409e4dc73351d339c9c1 100755 (executable)
@@ -643,12 +643,11 @@ test_expect_success 'basic: commit and list refs' '
        test_cmp actual expect
 '
 
-test_expect_success PERL_TEST_HELPERS 'basic: can write large commit message' '
+test_expect_success 'basic: can write large commit message' '
        test_when_finished "rm -rf repo" &&
        git init repo &&
-       perl -e "
-               print \"this is a long commit message\" x 50000
-       " >commit-msg &&
+
+       awk "BEGIN { for (i = 0; i < 50000; i++) printf \"%s\", \"this is a long commit message\" }" >commit-msg &&
        git -C repo commit --allow-empty --file=../commit-msg
 '
 
index fa1e2f9eef8b88a8aaeecfa03ee57159f2e88926..42aa1592f87f282702e303672f1712cb2fcd1099 100755 (executable)
@@ -139,13 +139,13 @@ test_expect_success 'small block size leads to multiple ref blocks' '
        )
 '
 
-test_expect_success PERL_TEST_HELPERS 'small block size fails with large reflog message' '
+test_expect_success 'small block size fails with large reflog message' '
        test_when_finished "rm -rf repo" &&
        git init repo &&
        (
                cd repo &&
                test_commit A &&
-               perl -e "print \"a\" x 500" >logmsg &&
+               test-tool genzeros 500 | tr "\000" "a" >logmsg &&
                cat >expect <<-EOF &&
                fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
                EOF
index 4977998e2055ccc3829f0317ef3d15f344f4698f..e9973f74949661654ca6877edd0a3d2b170d811e 100755 (executable)
@@ -41,14 +41,14 @@ test_expect_success 'ls-tree piped to mktree (2)' '
        test_cmp tree.withsub actual
 '
 
-test_expect_success PERL_TEST_HELPERS 'ls-tree output in wrong order given to mktree (1)' '
-       perl -e "print reverse <>" <top |
+test_expect_success 'ls-tree output in wrong order given to mktree (1)' '
+       sort -r <top |
        git mktree >actual &&
        test_cmp tree actual
 '
 
-test_expect_success PERL_TEST_HELPERS 'ls-tree output in wrong order given to mktree (2)' '
-       perl -e "print reverse <>" <top.withsub |
+test_expect_success 'ls-tree output in wrong order given to mktree (2)' '
+       sort -r <top.withsub |
        git mktree >actual &&
        test_cmp tree.withsub actual
 '
index 4794510d70dc3cf90ae0678faf57d780ef098987..2ae93d3c967aad18cad7290d09a9e7323637c0c2 100755 (executable)
@@ -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 <long@example.com>" &&
        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 &&
        git checkout HEAD^ &&
        git am msg &&
        # Ensure that the author and full message are present
index 143856c29f14aef7b69b01cb300445231b36dba9..a5932b6a8be0acc7403a47ec35eb57aa46163490 100755 (executable)
@@ -7,17 +7,11 @@ test_description='git pack-object'
 
 . ./test-lib.sh
 
-if ! test_have_prereq PERL_TEST_HELPERS
-then
-       skip_all='skipping pack-object tests; Perl not available'
-       test_done
-fi
-
 test_expect_success 'setup' '
        rm -f .git/index* &&
-       perl -e "print \"a\" x 4096;" >a &&
-       perl -e "print \"b\" x 4096;" >b &&
-       perl -e "print \"c\" x 4096;" >c &&
+       test-tool genzeros 4096 | tr "\000" "a" >a &&
+       test-tool genzeros 4096 | tr "\000" "b" >b &&
+       test-tool genzeros 4096 | tr "\000" "c" >c &&
        test-tool genrandom "seed a" 2097152 >a_big &&
        test-tool genrandom "seed b" 2097152 >b_big &&
        git update-index --add a a_big b b_big c &&
@@ -146,7 +140,7 @@ test_expect_success 'pack-object <stdin parsing: --stdin-packs handles garbage'
 # usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
 # e.g.: check_deltas stderr -gt 0
 check_deltas() {
-       deltas=$(perl -lne '/delta (\d+)/ and print $1' "$1") &&
+       deltas=$(sed -n 's/Total [0-9][0-9]* (delta \([0-9][0-9]*\)).*/\1/p' "$1") &&
        shift &&
        if ! test "$deltas" "$@"
        then
@@ -221,7 +215,7 @@ test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' '
        check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
 '
 
-test_expect_success 'compare delta flavors' '
+test_expect_success PERL_TEST_HELPERS 'compare delta flavors' '
        perl -e '\''
                defined($_ = -s $_) or die for @ARGV;
                exit 1 if $ARGV[0] <= $ARGV[1];
index 627f8b4efdc3908b398bb3387077539f85950fdf..892aeb09e4b9d710acc625b27ab8eb277b0b690f 100755 (executable)
@@ -153,7 +153,7 @@ test_midx_bitmap_cases () {
                )
        '
 
-       test_expect_success PERL_TEST_HELPERS 'pack.preferBitmapTips' '
+       test_expect_success 'pack.preferBitmapTips' '
                git init repo &&
                test_when_finished "rm -fr repo" &&
                (
@@ -176,8 +176,8 @@ test_midx_bitmap_cases () {
                        comm -13 bitmaps commits >before &&
                        test_line_count = 1 before &&
 
-                       perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \
-                               <before | git update-ref --stdin &&
+                       sed "s|\(.*\)|create refs/tags/include/\1 \1|" before |
+                       git update-ref --stdin &&
 
                        rm -fr $midx-$(midx_checksum $objdir).bitmap &&
                        rm -fr $midx &&
index 1059ff45fe4475064ce9bff4a29497ffe2b8943f..56674db562f948891261c7f40f13f9d13f4ec6a7 100755 (executable)
@@ -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 |
                        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 &&
 
index 6a009fdcd71f041a9f235e3a9119d0d0158511aa..4e82fd102e37277919dc817187db6ee9fabac884 100755 (executable)
@@ -17,10 +17,10 @@ test_expect_success 'setup' '
 '
 
 extract_haves () {
-       depacketize | perl -lne '/^(\S+) \.have/ and print $1'
+       depacketize | sed -n 's/^\([^ ][^ ]*\) \.have/\1/p'
 }
 
-test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsCommand' '
+test_expect_success 'with core.alternateRefsCommand' '
        write_script fork/alternate-refs <<-\EOF &&
                git --git-dir="$1" for-each-ref \
                        --format="%(objectname)" \
@@ -33,7 +33,7 @@ test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsCommand' '
        test_cmp expect actual.haves
 '
 
-test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsPrefixes' '
+test_expect_success 'with core.alternateRefsPrefixes' '
        test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
        git rev-parse private/branch >expect &&
        printf "0000" | git receive-pack fork >actual &&
index 200bf06ecb3b4839b2a11d40b3a18b81ea569e0d..d4c28bae39e2adcc95162ea45cdacd25cf2ced63 100755 (executable)
@@ -220,7 +220,7 @@ test_expect_success 'refs/heads prefix' '
        test_cmp expect actual
 '
 
-test_expect_success PERL_TEST_HELPERS 'ignore very large set of prefixes' '
+test_expect_success 'ignore very large set of prefixes' '
        # generate a large number of ref-prefixes that we expect
        # to match nothing; the value here exceeds TOO_MANY_PREFIXES
        # from ls-refs.c.
@@ -228,7 +228,10 @@ test_expect_success PERL_TEST_HELPERS 'ignore very large set of prefixes' '
                echo command=ls-refs &&
                echo object-format=$(test_oid algo) &&
                echo 0001 &&
-               perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" &&
+               awk "{
+                       for (i = 1; i <= 65536; i++)
+                               print \"ref-prefix refs/heads/\", \$i
+               }" &&
                echo 0000
        } |
        test-tool pkt-line pack >in &&
index 8074185742c170cb20b135d1ab8e3177e3808b1f..273196f52b5cef8d3743f3fd3b38468c9de2d363 100755 (executable)
@@ -26,17 +26,19 @@ test_expect_success 'set up --reverse example' '
        commit five
        '
 
-test_expect_success PERL_TEST_HELPERS '--reverse --parents --full-history combines correctly' '
-       git rev-list --parents --full-history main -- foo |
-               perl -e "print reverse <>" > expected &&
+reverse () {
+       awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }'
+}
+
+test_expect_success '--reverse --parents --full-history combines correctly' '
+       git rev-list --parents --full-history main -- foo | reverse >expected &&
        git rev-list --reverse --parents --full-history main -- foo \
                > actual &&
        test_cmp expected actual
        '
 
-test_expect_success PERL_TEST_HELPERS '--boundary does too' '
-       git rev-list --boundary --parents --full-history main ^root -- foo |
-               perl -e "print reverse <>" > expected &&
+test_expect_success '--boundary does too' '
+       git rev-list --boundary --parents --full-history main ^root -- foo | reverse >expected &&
        git rev-list --boundary --reverse --parents --full-history \
                main ^root -- foo > actual &&
        test_cmp expected actual
index 6a74be576a295af1aba1065b373e4da88fef062e..04c577dad690cc59d8bfa75cec802af3da0a3589 100755 (executable)
@@ -4,12 +4,6 @@ test_description='basic tests of rev-list --disk-usage'
 
 . ./test-lib.sh
 
-if ! test_have_prereq PERL_TEST_HELPERS
-then
-       skip_all='skipping rev-list disk usage tests; Perl not available'
-       test_done
-fi
-
 # we want a mix of reachable and unreachable, as well as
 # objects in the bitmapped pack and some outside of it
 test_expect_success 'set up repository' '
@@ -28,7 +22,7 @@ test_expect_success 'set up repository' '
 disk_usage_slow () {
        git rev-list --no-object-names "$@" |
        git cat-file --batch-check="%(objectsize:disk)" |
-       perl -lne '$total += $_; END { print $total}'
+       awk '{ i += $1 } END { print i }'
 }
 
 # check behavior with given rev-list options; note that
index 49aae183829606198ccc4eb8266856eefe154915..9717e825f0d7a551db756c366e59882a5a26f332 100755 (executable)
@@ -661,10 +661,10 @@ test_expect_success 'setup trace2' '
        export GIT_TRACE2_BRIEF
 '
 
-test_expect_success PERL_TEST_HELPERS 'setup large log output' '
-       perl -e "
-               print \"this is a long commit message\" x 50000
-       " >commit-msg &&
+test_expect_success 'setup large log output' '
+       test-tool genzeros 50000 |
+       tr "\000" "a" |
+       sed "s/a/this is a long commit message/g" >commit-msg &&
        git commit --allow-empty -F commit-msg
 '
 
index b40199df2313e4efc4292d4099b2cf8ced614090..7822947f028ee6a78de01a70ab4e1b43716cb0e7 100755 (executable)
@@ -107,7 +107,7 @@ test_expect_success 'set up abbrev tests' '
                expect=$1 && shift &&
                echo $sha1 | cut -c 1-$expect >expect &&
                git blame "$@" abbrev.t >actual &&
-               perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha &&
+               sed -n "s/^[\^]\{0,1\}\([0-9a-f][0-9a-f]*\).*/\1/p" actual >actual.sha &&
                test_cmp expect actual.sha
        }
 '
index f619b60f2269ad6c560e3e8bc6ab99e8171e74d8..21c3af48bd0a57d4e08388d2b6b27c9affa740f4 100755 (executable)
@@ -29,8 +29,8 @@ test_expect_success 'shell allows interactive command' '
        test_cmp expect actual
 '
 
-test_expect_success PERL_TEST_HELPERS 'shell complains of overlong commands' '
-       perl -e "print \"a\" x 2**12 for (0..2**19)" |
+test_expect_success 'shell complains of overlong commands' '
+       test-tool genzeros | tr "\000" "a" |
        test_must_fail git shell 2>err &&
        grep "too long" err
 '