Skip to content

Commit cdbdc6b

Browse files
pks-tgitster
authored andcommitted
t: refactor tests depending on Perl substitution operator
We have a bunch of tests that use Perl to perform substitution via the "s/" operator. These usecases can be trivially replaced with sed(1) and tr(1). 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 db8ff64 commit cdbdc6b

11 files changed

+40
-60
lines changed

t/t0008-ignores.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ test_description=check-ignore
55
TEST_CREATE_REPO_NO_TEMPLATE=1
66
. ./test-lib.sh
77

8-
if ! test_have_prereq PERL_TEST_HELPERS
9-
then
10-
skip_all='skipping ignores tests; Perl not available'
11-
test_done
12-
fi
13-
148
init_vars () {
159
global_excludes="global-excludes"
1610
}
@@ -45,11 +39,11 @@ test_stderr () {
4539
}
4640

4741
broken_c_unquote () {
48-
"$PERL_PATH" -pe 's/^"//; s/\\//; s/"$//; tr/\n/\0/' "$@"
42+
sed -e 's/^"//' -e 's/\\//' -e 's/"$//' "$1" | tr '\n' '\0'
4943
}
5044

5145
broken_c_unquote_verbose () {
52-
"$PERL_PATH" -pe 's/ "/ /; s/\\//; s/"$//; tr/:\t\n/\0/' "$@"
46+
sed -e 's/ "/ /' -e 's/\\//' -e 's/"$//' "$1" | tr ':\t\n' '\000'
5347
}
5448

5549
stderr_contains () {

t/t4029-diff-trailing-space.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ index 5f6a263..8cb8bae 100644
1818
EOF
1919
exit 1
2020

21-
test_expect_success PERL_TEST_HELPERS "$test_description" '
21+
test_expect_success "$test_description" '
2222
printf "\nx\n" > f &&
2323
before=$(git hash-object f) &&
2424
before=$(git rev-parse --short $before) &&
@@ -31,7 +31,8 @@ test_expect_success PERL_TEST_HELPERS "$test_description" '
3131
git config --bool diff.suppressBlankEmpty true &&
3232
git diff f > actual &&
3333
test_cmp exp actual &&
34-
perl -i.bak -p -e "s/^\$/ /" exp &&
34+
sed "s/^\$/ /" exp >exp.munged &&
35+
mv exp.munged exp &&
3536
git config --bool diff.suppressBlankEmpty false &&
3637
git diff f > actual &&
3738
test_cmp exp actual &&

t/t4200-rerere.sh

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
2727

2828
. ./test-lib.sh
2929

30-
if ! test_have_prereq PERL_TEST_HELPERS
31-
then
32-
skip_all='skipping rerere tests; Perl not available'
33-
test_done
34-
fi
35-
3630
test_expect_success 'setup' '
3731
cat >a1 <<-\EOF &&
3832
Some title
@@ -87,7 +81,7 @@ test_expect_success 'activate rerere, old style (conflicting merge)' '
8781
test_might_fail git config --unset rerere.enabled &&
8882
test_must_fail git merge first &&
8983
90-
sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
84+
sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
9185
rr=.git/rr-cache/$sha1 &&
9286
grep "^=======\$" $rr/preimage &&
9387
! test -f $rr/postimage &&
@@ -100,7 +94,7 @@ test_expect_success 'rerere.enabled works, too' '
10094
git reset --hard &&
10195
test_must_fail git merge first &&
10296
103-
sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
97+
sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
10498
rr=.git/rr-cache/$sha1 &&
10599
grep ^=======$ $rr/preimage
106100
'
@@ -110,7 +104,7 @@ test_expect_success 'set up rr-cache' '
110104
git config rerere.enabled true &&
111105
git reset --hard &&
112106
test_must_fail git merge first &&
113-
sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
107+
sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
114108
rr=.git/rr-cache/$sha1
115109
'
116110

t/t5303-pack-corruption-resilience.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ test_expect_success '... and loose copy of first delta allows for partial recove
9999
git cat-file blob $blob_3 > /dev/null
100100
'
101101

102-
test_expect_success PERL_TEST_HELPERS 'create corruption in data of first object' '
102+
test_expect_success 'create corruption in data of first object' '
103103
create_new_pack &&
104104
git prune-packed &&
105105
chmod +w ${pack}.pack &&
106-
perl -i.bak -pe "s/ base /abcdef/" ${pack}.pack &&
106+
sed "s/ base /abcdef/" ${pack}.pack >${pack}.pack.munged &&
107+
mv ${pack}.pack.munged ${pack}.pack &&
107108
test_must_fail git cat-file blob $blob_1 > /dev/null &&
108109
test_must_fail git cat-file blob $blob_2 > /dev/null &&
109110
test_must_fail git cat-file blob $blob_3 > /dev/null
@@ -156,11 +157,12 @@ test_expect_success '... and then a repack "clears" the corruption' '
156157
git cat-file blob $blob_3 > /dev/null
157158
'
158159

159-
test_expect_success PERL_TEST_HELPERS 'create corruption in data of first delta' '
160+
test_expect_success 'create corruption in data of first delta' '
160161
create_new_pack &&
161162
git prune-packed &&
162163
chmod +w ${pack}.pack &&
163-
perl -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack &&
164+
sed "s/ delta1 /abcdefgh/" ${pack}.pack >${pack}.pack.munged &&
165+
mv ${pack}.pack.munged ${pack}.pack &&
164166
git cat-file blob $blob_1 > /dev/null &&
165167
test_must_fail git cat-file blob $blob_2 > /dev/null &&
166168
test_must_fail git cat-file blob $blob_3 > /dev/null

t/t5310-pack-bitmaps.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ test_bitmap_cases () {
395395
)
396396
'
397397

398-
test_expect_success PERL_TEST_HELPERS 'pack.preferBitmapTips' '
398+
test_expect_success 'pack.preferBitmapTips' '
399399
git init repo &&
400400
test_when_finished "rm -fr repo" &&
401401
(
@@ -421,7 +421,7 @@ test_bitmap_cases () {
421421
422422
# mark the commits which did not receive bitmaps as preferred,
423423
# and generate the bitmap again
424-
perl -pe "s{^}{create refs/tags/include/$. }" <before |
424+
sed "s|\(.*\)|create refs/tags/include/\1 \1|" before |
425425
git update-ref --stdin &&
426426
git -c pack.preferBitmapTips=refs/tags/include repack -adb &&
427427

t/t5534-push-signed.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ test_expect_success GPGSSH 'ssh signed push sends push certificate' '
177177
test_cmp expect dst/push-cert-status
178178
'
179179

180-
test_expect_success GPG,PERL_TEST_HELPERS 'inconsistent push options in signed push not allowed' '
180+
test_expect_success GPG 'inconsistent push options in signed push not allowed' '
181181
# First, invoke receive-pack with dummy input to obtain its preamble.
182182
prepare_dst &&
183183
git -C dst config receive.certnonceseed sekrit &&
@@ -205,7 +205,7 @@ test_expect_success GPG,PERL_TEST_HELPERS 'inconsistent push options in signed p
205205
# Tweak the push output to make the push option outside the cert
206206
# different, then replay it on a fresh dst, checking that ff is not
207207
# deleted.
208-
perl -pe "s/([^ ])bar/\$1baz/" push >push.tweak &&
208+
sed "s/\([^ ]\)bar/\1baz/" push >push.tweak &&
209209
prepare_dst &&
210210
git -C dst config receive.certnonceseed sekrit &&
211211
git -C dst config receive.advertisepushoptions 1 &&

t/t6011-rev-list-with-bad-commit.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ test_description='git rev-list should notice bad commits'
44

55
. ./test-lib.sh
66

7-
if ! test_have_prereq PERL_TEST_HELPERS
8-
then
9-
skip_all='skipping rev-list with bad commit tests; Perl not available'
10-
test_done
11-
fi
12-
137
# Note:
148
# - compression level is set to zero to make "corruptions" easier to perform
159
# - reflog is disabled to avoid extra references which would twart the test
@@ -41,11 +35,15 @@ test_expect_success 'verify number of revisions' \
4135
first_commit=$(git rev-parse HEAD~3)
4236
'
4337

44-
test_expect_success 'corrupt second commit object' \
45-
'
46-
perl -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack &&
47-
test_must_fail git fsck --full
48-
'
38+
test_expect_success 'corrupt second commit object' '
39+
for p in .git/objects/pack/*.pack
40+
do
41+
sed "s/second commit/socond commit/" "$p" >"$p.munged" &&
42+
mv "$p.munged" "$p" ||
43+
return 1
44+
done &&
45+
test_must_fail git fsck --full
46+
'
4947

5048
test_expect_success 'rev-list should fail' '
5149
test_must_fail env GIT_TEST_COMMIT_GRAPH=0 git -c core.commitGraph=false rev-list --all > /dev/null

t/t7416-submodule-dash-url.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ test_description='check handling of disallowed .gitmodule urls'
44

55
. ./test-lib.sh
66

7-
if ! test_have_prereq PERL_TEST_HELPERS
8-
then
9-
skip_all='skipping submodule dash URL tests; Perl not available'
10-
test_done
11-
fi
12-
137
test_expect_success 'setup' '
148
git config --global protocol.file.allow always
159
'
@@ -39,7 +33,8 @@ test_expect_success 'fsck accepts protected dash' '
3933
'
4034

4135
test_expect_success 'remove ./ protection from .gitmodules url' '
42-
perl -i -pe "s{\./}{}" .gitmodules &&
36+
sed "s|\./||" .gitmodules >.gitmodules.munged &&
37+
mv .gitmodules.munged .gitmodules &&
4338
git commit -am "drop protection"
4439
'
4540

t/t7508-status.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,9 +1064,9 @@ test_expect_success 'status -s submodule summary (clean submodule)' '
10641064
test_cmp expect output
10651065
'
10661066

1067-
test_expect_success PERL_TEST_HELPERS 'status -z implies porcelain' '
1067+
test_expect_success 'status -z implies porcelain' '
10681068
git status --porcelain |
1069-
perl -pe "s/\012/\000/g" >expect &&
1069+
tr "\012" "\000" >expect &&
10701070
git status -z >output &&
10711071
test_cmp expect output
10721072
'

t/t8006-blame-textconv.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ test_description='git blame textconv support'
44

55
. ./test-lib.sh
66

7-
if ! test_have_prereq PERL_TEST_HELPERS
8-
then
9-
skip_all='skipping blame textconv tests; Perl not available'
10-
test_done
11-
fi
12-
137
find_blame() {
148
sed -e 's/^[^(]*//'
159
}
1610

1711
cat >helper <<'EOF'
1812
#!/bin/sh
1913
grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
20-
"$PERL_PATH" -p -e 's/^bin: /converted: /' "$1"
14+
sed 's/^bin: /converted: /' "$1"
2115
EOF
2216
chmod +x helper
2317

0 commit comments

Comments
 (0)