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>
Patrick Steinhardt committed
Apr 3, 2025 at 07:06 UTC
6aec8d38fddf22fa9fd3194acc2b891d295b5fbc
14 files changed
+51
-67
t/t0610-reftable-basics.sh
+3
-4
@@ -643,12 +643,11 @@ test_expect_success 'basic: commit and list refs' '
643
test_cmp actual expect
644
'
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
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 &&
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
t/t0613-reftable-write-options.sh
+2
-2
@@ -139,13 +139,13 @@ test_expect_success 'small block size leads to multiple ref blocks' '
139
)
140
'
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
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 &&
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
t/t1010-mktree.sh
+4
-4
@@ -41,14 +41,14 @@ test_expect_success 'ls-tree piped to mktree (2)' '
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 |
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 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
git mktree >actual &&
53
test_cmp tree.withsub actual
54
'
t/t4150-am.sh
+5
-5
@@ -1073,7 +1073,7 @@ test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
1073
test_cmp msg out
1074
'
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
FORTY="String that has a length of more than forty characters" &&
1078
LONG="$FORTY $FORTY" &&
1079
rm -fr .git/rebase-apply &&
@@ -1084,13 +1084,13 @@ test_expect_success PERL_TEST_HELPERS 'am works with multi-line in-body headers'
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:/) {
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
- }
1093
- " patch >msg &&
1092
+ }; 1
1093
+ " <patch >msg &&
1094
git checkout HEAD^ &&
1095
git am msg &&
1096
# Ensure that the author and full message are present
t/t5300-pack-object.sh
+5
-11
@@ -7,17 +7,11 @@ test_description='git pack-object'
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
-
10
test_expect_success 'setup' '
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 &&
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 &&
@@ -146,7 +140,7 @@ test_expect_success 'pack-object <stdin parsing: --stdin-packs handles garbage'
140
# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
141
# e.g.: check_deltas stderr -gt 0
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") &&
144
shift &&
145
if ! test "$deltas" "$@"
146
then
@@ -221,7 +215,7 @@ test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' '
215
check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
216
'
217
224
-test_expect_success 'compare delta flavors' '
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];
t/t5326-multi-pack-bitmaps.sh
+3
-3
@@ -153,7 +153,7 @@ test_midx_bitmap_cases () {
153
)
154
'
155
156
- test_expect_success PERL_TEST_HELPERS 'pack.preferBitmapTips' '
156
+ test_expect_success 'pack.preferBitmapTips' '
157
git init repo &&
158
test_when_finished "rm -fr repo" &&
159
(
@@ -176,8 +176,8 @@ test_midx_bitmap_cases () {
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 &&
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 &&
t/t5333-pseudo-merge-bitmaps.sh
+5
-13
@@ -6,12 +6,6 @@ GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
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
-
9
test_pseudo_merges () {
10
test-tool bitmap dump-pseudo-merges
11
}
@@ -34,9 +28,8 @@ test_pseudo_merges_reused () {
28
29
tag_everything () {
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
33
}
34
35
test_expect_success 'setup' '
@@ -108,7 +101,7 @@ test_expect_success 'stale bitmap traversal with pseudo-merges' '
101
test_cmp expect actual
102
'
103
111
-test_expect_success 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' '
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 &&
@@ -241,8 +234,7 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
234
test_commit_bulk 16 &&
235
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 |
238
git update-ref --stdin || return 1
239
done &&
240
@@ -258,7 +250,7 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
250
do
251
test_pseudo_merge_commits $m >oids &&
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" &&
254
sort -u || return 1
255
done >remotes &&
256
t/t5410-receive-pack-alternates.sh
+3
-3
@@ -17,10 +17,10 @@ test_expect_success 'setup' '
17
'
18
19
extract_haves () {
20
- depacketize | perl -lne '/^(\S+) \.have/ and print $1'
20
+ depacketize | sed -n 's/^\([^ ][^ ]*\) \.have/\1/p'
21
}
22
23
-test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsCommand' '
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,7 +33,7 @@ test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsCommand' '
33
test_cmp expect actual.haves
34
'
35
36
-test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsPrefixes' '
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 &&
t/t5701-git-serve.sh
+5
-2
@@ -220,7 +220,7 @@ test_expect_success 'refs/heads prefix' '
220
test_cmp expect actual
221
'
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
# 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,7 +228,10 @@ test_expect_success PERL_TEST_HELPERS 'ignore very large set of prefixes' '
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)" &&
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 &&
t/t6013-rev-list-reverse-parents.sh
+8
-6
@@ -26,17 +26,19 @@ test_expect_success 'set up --reverse example' '
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 &&
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
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 &&
42
git rev-list --boundary --reverse --parents --full-history \
43
main ^root -- foo > actual &&
44
test_cmp expected actual
t/t6115-rev-list-du.sh
+1
-7
@@ -4,12 +4,6 @@ test_description='basic tests of rev-list --disk-usage'
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
-
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' '
@@ -28,7 +22,7 @@ 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)" |
31
- perl -lne '$total += $_; END { print $total}'
25
+ awk '{ i += $1 } END { print i }'
26
}
27
28
# check behavior with given rev-list options; note that
t/t7006-pager.sh
+4
-4
@@ -661,10 +661,10 @@ test_expect_success 'setup trace2' '
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 &&
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
t/t8002-blame.sh
+1
-1
@@ -107,7 +107,7 @@ test_expect_success 'set up abbrev tests' '
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 &&
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
'
t/t9850-shell.sh
+2
-2
@@ -29,8 +29,8 @@ test_expect_success 'shell allows interactive command' '
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)" |
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
'