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>
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
'
)
'
-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
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
'
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 &&
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
. ./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 &&
# 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
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];
)
'
- test_expect_success PERL_TEST_HELPERS 'pack.preferBitmapTips' '
+ test_expect_success 'pack.preferBitmapTips' '
git init repo &&
test_when_finished "rm -fr repo" &&
(
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 &&
. ./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
}
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' '
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 &&
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 &&
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 &&
'
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)" \
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 &&
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.
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 &&
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
. ./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' '
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
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
'
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
}
'
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
'