Skip to content

Commit 6aec8d3

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cdbdc6b commit 6aec8d3

14 files changed

+51
-67
lines changed

t/t0610-reftable-basics.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,11 @@ test_expect_success 'basic: commit and list refs' '
643643
test_cmp actual expect
644644
'
645645

646-
test_expect_success PERL_TEST_HELPERS 'basic: can write large commit message' '
646+
test_expect_success 'basic: can write large commit message' '
647647
test_when_finished "rm -rf repo" &&
648648
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 &&
652651
git -C repo commit --allow-empty --file=../commit-msg
653652
'
654653

t/t0613-reftable-write-options.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ test_expect_success 'small block size leads to multiple ref blocks' '
139139
)
140140
'
141141

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' '
143143
test_when_finished "rm -rf repo" &&
144144
git init repo &&
145145
(
146146
cd repo &&
147147
test_commit A &&
148-
perl -e "print \"a\" x 500" >logmsg &&
148+
test-tool genzeros 500 | tr "\000" "a" >logmsg &&
149149
cat >expect <<-EOF &&
150150
fatal: update_ref failed for ref ${SQ}refs/heads/logme${SQ}: reftable: transaction failure: entry too large
151151
EOF

t/t1010-mktree.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ test_expect_success 'ls-tree piped to mktree (2)' '
4141
test_cmp tree.withsub actual
4242
'
4343

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 |
4646
git mktree >actual &&
4747
test_cmp tree actual
4848
'
4949

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 |
5252
git mktree >actual &&
5353
test_cmp tree.withsub actual
5454
'

t/t4150-am.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ test_expect_success 'am --patch-format=mboxrd handles mboxrd' '
10731073
test_cmp msg out
10741074
'
10751075

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' '
10771077
FORTY="String that has a length of more than forty characters" &&
10781078
LONG="$FORTY $FORTY" &&
10791079
rm -fr .git/rebase-apply &&
@@ -1084,13 +1084,13 @@ test_expect_success PERL_TEST_HELPERS 'am works with multi-line in-body headers'
10841084
Body test" --author="$LONG <[email protected]>" &&
10851085
git format-patch --stdout -1 >patch &&
10861086
# bump from, date, and subject down to in-body header
1087-
perl -lpe "
1088-
if (/^From:/) {
1087+
awk "
1088+
/^From:/{
10891089
print \"From: x <x\@example.com>\";
10901090
print \"Date: Sat, 1 Jan 2000 00:00:00 +0000\";
10911091
print \"Subject: x\n\";
1092-
}
1093-
" patch >msg &&
1092+
}; 1
1093+
" <patch >msg &&
10941094
git checkout HEAD^ &&
10951095
git am msg &&
10961096
# Ensure that the author and full message are present

t/t5300-pack-object.sh

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,11 @@ test_description='git pack-object'
77

88
. ./test-lib.sh
99

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-
1610
test_expect_success 'setup' '
1711
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 &&
2115
test-tool genrandom "seed a" 2097152 >a_big &&
2216
test-tool genrandom "seed b" 2097152 >b_big &&
2317
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'
146140
# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas>
147141
# e.g.: check_deltas stderr -gt 0
148142
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") &&
150144
shift &&
151145
if ! test "$deltas" "$@"
152146
then
@@ -221,7 +215,7 @@ test_expect_success 'unpack with OFS_DELTA (core.fsyncmethod=batch)' '
221215
check_unpack test-3-${packname_3} obj-list "$BATCH_CONFIGURATION"
222216
'
223217

224-
test_expect_success 'compare delta flavors' '
218+
test_expect_success PERL_TEST_HELPERS 'compare delta flavors' '
225219
perl -e '\''
226220
defined($_ = -s $_) or die for @ARGV;
227221
exit 1 if $ARGV[0] <= $ARGV[1];

t/t5326-multi-pack-bitmaps.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ test_midx_bitmap_cases () {
153153
)
154154
'
155155

156-
test_expect_success PERL_TEST_HELPERS 'pack.preferBitmapTips' '
156+
test_expect_success 'pack.preferBitmapTips' '
157157
git init repo &&
158158
test_when_finished "rm -fr repo" &&
159159
(
@@ -176,8 +176,8 @@ test_midx_bitmap_cases () {
176176
comm -13 bitmaps commits >before &&
177177
test_line_count = 1 before &&
178178
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 &&
181181
182182
rm -fr $midx-$(midx_checksum $objdir).bitmap &&
183183
rm -fr $midx &&

t/t5333-pseudo-merge-bitmaps.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
66

77
. ./test-lib.sh
88

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-
159
test_pseudo_merges () {
1610
test-tool bitmap dump-pseudo-merges
1711
}
@@ -34,9 +28,8 @@ test_pseudo_merges_reused () {
3428

3529
tag_everything () {
3630
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
4033
}
4134

4235
test_expect_success 'setup' '
@@ -108,7 +101,7 @@ test_expect_success 'stale bitmap traversal with pseudo-merges' '
108101
test_cmp expect actual
109102
'
110103

111-
test_expect_success 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' '
104+
test_expect_success PERL_TEST_HELPERS 'bitmapPseudoMerge.sampleRate adjusts commit selection rate' '
112105
test_config bitmapPseudoMerge.test.pattern "refs/tags/" &&
113106
test_config bitmapPseudoMerge.test.maxMerges 1 &&
114107
test_config bitmapPseudoMerge.test.stableThreshold never &&
@@ -241,8 +234,7 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
241234
test_commit_bulk 16 &&
242235
243236
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 |
246238
git update-ref --stdin || return 1
247239
done &&
248240
@@ -258,7 +250,7 @@ test_expect_success 'pseudo-merge pattern with capture groups' '
258250
do
259251
test_pseudo_merge_commits $m >oids &&
260252
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" &&
262254
sort -u || return 1
263255
done >remotes &&
264256

t/t5410-receive-pack-alternates.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ test_expect_success 'setup' '
1717
'
1818

1919
extract_haves () {
20-
depacketize | perl -lne '/^(\S+) \.have/ and print $1'
20+
depacketize | sed -n 's/^\([^ ][^ ]*\) \.have/\1/p'
2121
}
2222

23-
test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsCommand' '
23+
test_expect_success 'with core.alternateRefsCommand' '
2424
write_script fork/alternate-refs <<-\EOF &&
2525
git --git-dir="$1" for-each-ref \
2626
--format="%(objectname)" \
@@ -33,7 +33,7 @@ test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsCommand' '
3333
test_cmp expect actual.haves
3434
'
3535

36-
test_expect_success PERL_TEST_HELPERS 'with core.alternateRefsPrefixes' '
36+
test_expect_success 'with core.alternateRefsPrefixes' '
3737
test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
3838
git rev-parse private/branch >expect &&
3939
printf "0000" | git receive-pack fork >actual &&

t/t5701-git-serve.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,18 @@ test_expect_success 'refs/heads prefix' '
220220
test_cmp expect actual
221221
'
222222

223-
test_expect_success PERL_TEST_HELPERS 'ignore very large set of prefixes' '
223+
test_expect_success 'ignore very large set of prefixes' '
224224
# generate a large number of ref-prefixes that we expect
225225
# to match nothing; the value here exceeds TOO_MANY_PREFIXES
226226
# from ls-refs.c.
227227
{
228228
echo command=ls-refs &&
229229
echo object-format=$(test_oid algo) &&
230230
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+
}" &&
232235
echo 0000
233236
} |
234237
test-tool pkt-line pack >in &&

t/t6013-rev-list-reverse-parents.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ test_expect_success 'set up --reverse example' '
2626
commit five
2727
'
2828

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 &&
3235
git rev-list --reverse --parents --full-history main -- foo \
3336
> actual &&
3437
test_cmp expected actual
3538
'
3639

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 &&
4042
git rev-list --boundary --reverse --parents --full-history \
4143
main ^root -- foo > actual &&
4244
test_cmp expected actual

0 commit comments

Comments
 (0)