Git fork

t: refactor tests depending on Perl to print data

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>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
6aec8d38 cdbdc6bf

+51 -67
+3 -4
t/t0610-reftable-basics.sh
··· 643 643 test_cmp actual expect 644 644 ' 645 645 646 - test_expect_success PERL_TEST_HELPERS 'basic: can write large commit message' ' 646 + test_expect_success 'basic: can write large commit message' ' 647 647 test_when_finished "rm -rf repo" && 648 648 git init repo && 649 - perl -e " 650 - print \"this is a long commit message\" x 50000 651 - " >commit-msg && 649 + 650 + awk "BEGIN { for (i = 0; i < 50000; i++) printf \"%s\", \"this is a long commit message\" }" >commit-msg && 652 651 git -C repo commit --allow-empty --file=../commit-msg 653 652 ' 654 653
+2 -2
t/t0613-reftable-write-options.sh
··· 139 139 ) 140 140 ' 141 141 142 - test_expect_success PERL_TEST_HELPERS 'small block size fails with large reflog message' ' 142 + test_expect_success 'small block size fails with large reflog message' ' 143 143 test_when_finished "rm -rf repo" && 144 144 git init repo && 145 145 ( 146 146 cd repo && 147 147 test_commit A && 148 - perl -e "print \"a\" x 500" >logmsg && 148 + test-tool genzeros 500 | tr "\000" "a" >logmsg && 149 149 cat >expect <<-EOF && 150 150 fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large 151 151 EOF
+4 -4
t/t1010-mktree.sh
··· 41 41 test_cmp tree.withsub actual 42 42 ' 43 43 44 - test_expect_success PERL_TEST_HELPERS 'ls-tree output in wrong order given to mktree (1)' ' 45 - perl -e "print reverse <>" <top | 44 + test_expect_success 'ls-tree output in wrong order given to mktree (1)' ' 45 + sort -r <top | 46 46 git mktree >actual && 47 47 test_cmp tree actual 48 48 ' 49 49 50 - test_expect_success PERL_TEST_HELPERS 'ls-tree output in wrong order given to mktree (2)' ' 51 - perl -e "print reverse <>" <top.withsub | 50 + test_expect_success 'ls-tree output in wrong order given to mktree (2)' ' 51 + sort -r <top.withsub | 52 52 git mktree >actual && 53 53 test_cmp tree.withsub actual 54 54 '
+5 -5
t/t4150-am.sh
··· 1073 1073 test_cmp msg out 1074 1074 ' 1075 1075 1076 - test_expect_success PERL_TEST_HELPERS 'am works with multi-line in-body headers' ' 1076 + test_expect_success 'am works with multi-line in-body headers' ' 1077 1077 FORTY="String that has a length of more than forty characters" && 1078 1078 LONG="$FORTY $FORTY" && 1079 1079 rm -fr .git/rebase-apply && ··· 1084 1084 Body test" --author="$LONG <long@example.com>" && 1085 1085 git format-patch --stdout -1 >patch && 1086 1086 # bump from, date, and subject down to in-body header 1087 - perl -lpe " 1088 - if (/^From:/) { 1087 + awk " 1088 + /^From:/{ 1089 1089 print \"From: x <x\@example.com>\"; 1090 1090 print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\"; 1091 1091 print \"Subject: x\n\"; 1092 - } 1093 - " patch >msg && 1092 + }; 1 1093 + " <patch >msg && 1094 1094 git checkout HEAD^ && 1095 1095 git am msg && 1096 1096 # Ensure that the author and full message are present
+5 -11
t/t5300-pack-object.sh
··· 7 7 8 8 . ./test-lib.sh 9 9 10 - if ! test_have_prereq PERL_TEST_HELPERS 11 - then 12 - skip_all='skipping pack-object tests; Perl not available' 13 - test_done 14 - fi 15 - 16 10 test_expect_success 'setup' ' 17 11 rm -f .git/index* && 18 - perl -e "print \"a\" x 4096;" >a && 19 - perl -e "print \"b\" x 4096;" >b && 20 - perl -e "print \"c\" x 4096;" >c && 12 + test-tool genzeros 4096 | tr "\000" "a" >a && 13 + test-tool genzeros 4096 | tr "\000" "b" >b && 14 + test-tool genzeros 4096 | tr "\000" "c" >c && 21 15 test-tool genrandom "seed a" 2097152 >a_big && 22 16 test-tool genrandom "seed b" 2097152 >b_big && 23 17 git update-index --add a a_big b b_big c && ··· 146 140 # usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas> 147 141 # e.g.: check_deltas stderr -gt 0 148 142 check_deltas() { 149 - deltas=$(perl -lne '/delta (\d+)/ and print $1' "$1") && 143 + deltas=$(sed -n 's/Total [0-9][0-9]* (delta \([0-9][0-9]*\)).*/\1/p' "$1") && 150 144 shift && 151 145 if ! test "$deltas" "$@" 152 146 then ··· 221 215 check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION" 222 216 ' 223 217 224 - test_expect_success 'compare delta flavors' ' 218 + test_expect_success PERL_TEST_HELPERS 'compare delta flavors' ' 225 219 perl -e '\'' 226 220 defined($_ = -s $_) or die for @ARGV; 227 221 exit 1 if $ARGV[0] <= $ARGV[1];
+3 -3
t/t5326-multi-pack-bitmaps.sh
··· 153 153 ) 154 154 ' 155 155 156 - test_expect_success PERL_TEST_HELPERS 'pack.preferBitmapTips' ' 156 + test_expect_success 'pack.preferBitmapTips' ' 157 157 git init repo && 158 158 test_when_finished "rm -fr repo" && 159 159 ( ··· 176 176 comm -13 bitmaps commits >before && 177 177 test_line_count = 1 before && 178 178 179 - perl -ne "printf(\"create refs/tags/include/%d \", $.); print" \ 180 - <before | git update-ref --stdin && 179 + sed "s|\(.*\)|create refs/tags/include/\1 \1|" before | 180 + git update-ref --stdin && 181 181 182 182 rm -fr $midx-$(midx_checksum $objdir).bitmap && 183 183 rm -fr $midx &&
+5 -13
t/t5333-pseudo-merge-bitmaps.sh
··· 6 6 7 7 . ./test-lib.sh 8 8 9 - if ! test_have_prereq PERL_TEST_HELPERS 10 - then 11 - skip_all='skipping pseudo-merge bitmap tests; Perl not available' 12 - test_done 13 - fi 14 - 15 9 test_pseudo_merges () { 16 10 test-tool bitmap dump-pseudo-merges 17 11 } ··· 34 28 35 29 tag_everything () { 36 30 git rev-list --all --no-object-names >in && 37 - perl -lne ' 38 - print "create refs/tags/" . $. . " " . $1 if /([0-9a-f]+)/ 39 - ' <in | git update-ref --stdin 31 + sed 's|\(.*\)|create refs/tags/\1 \1|' in | 32 + git update-ref --stdin 40 33 } 41 34 42 35 test_expect_success 'setup' ' ··· 108 101 test_cmp expect actual 109 102 ' 110 103 111 - test_expect_success 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' ' 104 + test_expect_success PERL_TEST_HELPERS 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' ' 112 105 test_config bitmapPseudoMerge.test.pattern "refs/tags/" && 113 106 test_config bitmapPseudoMerge.test.maxMerges 1 && 114 107 test_config bitmapPseudoMerge.test.stableThreshold never && ··· 241 234 test_commit_bulk 16 && 242 235 243 236 git rev-list HEAD~16.. >in && 244 - 245 - perl -lne "print \"create refs/remotes/$r/tags/\$. \$_\"" <in | 237 + sed "s|\(.*\)|create refs/remotes/$r/tags/\1 \1" in | 246 238 git update-ref --stdin || return 1 247 239 done && 248 240 ··· 258 250 do 259 251 test_pseudo_merge_commits $m >oids && 260 252 grep -f oids refs | 261 - perl -lne "print \$1 if /refs\/remotes\/([0-9]+)/" | 253 + sed -n "s|refs/remotes/\([0-9][0-9]*\)/|\1|p" && 262 254 sort -u || return 1 263 255 done >remotes && 264 256
+3 -3
t/t5410-receive-pack-alternates.sh
··· 17 17 ' 18 18 19 19 extract_haves () { 20 - depacketize | perl -lne '/^(\S+) \.have/ and print $1' 20 + depacketize | sed -n 's/^\([^ ][^ ]*\) \.have/\1/p' 21 21 } 22 22 23 - test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsCommand' ' 23 + test_expect_success 'with core.alternateRefsCommand' ' 24 24 write_script fork/alternate-refs <<-\EOF && 25 25 git --git-dir="$1" for-each-ref \ 26 26 --format="%(objectname)" \ ··· 33 33 test_cmp expect actual.haves 34 34 ' 35 35 36 - test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsPrefixes' ' 36 + test_expect_success 'with core.alternateRefsPrefixes' ' 37 37 test_config -C fork core.alternateRefsPrefixes "refs/heads/private" && 38 38 git rev-parse private/branch >expect && 39 39 printf "0000" | git receive-pack fork >actual &&
+5 -2
t/t5701-git-serve.sh
··· 220 220 test_cmp expect actual 221 221 ' 222 222 223 - test_expect_success PERL_TEST_HELPERS 'ignore very large set of prefixes' ' 223 + test_expect_success 'ignore very large set of prefixes' ' 224 224 # generate a large number of ref-prefixes that we expect 225 225 # to match nothing; the value here exceeds TOO_MANY_PREFIXES 226 226 # from ls-refs.c. ··· 228 228 echo command=ls-refs && 229 229 echo object-format=$(test_oid algo) && 230 230 echo 0001 && 231 - perl -le "print \"ref-prefix refs/heads/\$_\" for (1..65536)" && 231 + awk "{ 232 + for (i = 1; i <= 65536; i++) 233 + print \"ref-prefix refs/heads/\", \$i 234 + }" && 232 235 echo 0000 233 236 } | 234 237 test-tool pkt-line pack >in &&
+8 -6
t/t6013-rev-list-reverse-parents.sh
··· 26 26 commit five 27 27 ' 28 28 29 - test_expect_success PERL_TEST_HELPERS '--reverse --parents --full-history combines correctly' ' 30 - git rev-list --parents --full-history main -- foo | 31 - perl -e "print reverse <>" > expected && 29 + reverse () { 30 + awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' 31 + } 32 + 33 + test_expect_success '--reverse --parents --full-history combines correctly' ' 34 + git rev-list --parents --full-history main -- foo | reverse >expected && 32 35 git rev-list --reverse --parents --full-history main -- foo \ 33 36 > actual && 34 37 test_cmp expected actual 35 38 ' 36 39 37 - test_expect_success PERL_TEST_HELPERS '--boundary does too' ' 38 - git rev-list --boundary --parents --full-history main ^root -- foo | 39 - perl -e "print reverse <>" > expected && 40 + test_expect_success '--boundary does too' ' 41 + git rev-list --boundary --parents --full-history main ^root -- foo | reverse >expected && 40 42 git rev-list --boundary --reverse --parents --full-history \ 41 43 main ^root -- foo > actual && 42 44 test_cmp expected actual
+1 -7
t/t6115-rev-list-du.sh
··· 4 4 5 5 . ./test-lib.sh 6 6 7 - if ! test_have_prereq PERL_TEST_HELPERS 8 - then 9 - skip_all='skipping rev-list disk usage tests; Perl not available' 10 - test_done 11 - fi 12 - 13 7 # we want a mix of reachable and unreachable, as well as 14 8 # objects in the bitmapped pack and some outside of it 15 9 test_expect_success 'set up repository' ' ··· 28 22 disk_usage_slow () { 29 23 git rev-list --no-object-names "$@" | 30 24 git cat-file --batch-check="%(objectsize:disk)" | 31 - perl -lne '$total += $_; END { print $total}' 25 + awk '{ i += $1 } END { print i }' 32 26 } 33 27 34 28 # check behavior with given rev-list options; note that
+4 -4
t/t7006-pager.sh
··· 661 661 export GIT_TRACE2_BRIEF 662 662 ' 663 663 664 - test_expect_success PERL_TEST_HELPERS 'setup large log output' ' 665 - perl -e " 666 - print \"this is a long commit message\" x 50000 667 - " >commit-msg && 664 + test_expect_success 'setup large log output' ' 665 + test-tool genzeros 50000 | 666 + tr "\000" "a" | 667 + sed "s/a/this is a long commit message/g" >commit-msg && 668 668 git commit --allow-empty -F commit-msg 669 669 ' 670 670
+1 -1
t/t8002-blame.sh
··· 107 107 expect=$1 && shift && 108 108 echo $sha1 | cut -c 1-$expect >expect && 109 109 git blame "$@" abbrev.t >actual && 110 - perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha && 110 + sed -n "s/^[\^]\{0,1\}\([0-9a-f][0-9a-f]*\).*/\1/p" actual >actual.sha && 111 111 test_cmp expect actual.sha 112 112 } 113 113 '
+2 -2
t/t9850-shell.sh
··· 29 29 test_cmp expect actual 30 30 ' 31 31 32 - test_expect_success PERL_TEST_HELPERS 'shell complains of overlong commands' ' 33 - perl -e "print \"a\" x 2**12 for (0..2**19)" | 32 + test_expect_success 'shell complains of overlong commands' ' 33 + test-tool genzeros | tr "\000" "a" | 34 34 test_must_fail git shell 2>err && 35 35 grep "too long" err 36 36 '