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