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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 3, 2025 at 07:06 UTC cdbdc6bf8caddc32e5fae7bfe4a63c54be21093f
11 files changed +40 -60
t/t0008-ignores.sh
+2 -8
@@ -5,12 +5,6 @@ test_description=check-ignore
5 TEST_CREATE_REPO_NO_TEMPLATE=1
6 . ./test-lib.sh
7
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 -
8 init_vars () {
9 global_excludes="global-excludes"
10 }
@@ -45,11 +39,11 @@ test_stderr () {
39 }
40
41 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'
43 }
44
45 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'
47 }
48
49 stderr_contains () {
t/t4029-diff-trailing-space.sh
+3 -2
@@ -18,7 +18,7 @@ index 5f6a263..8cb8bae 100644
18 EOF
19 exit 1
20
21 -test_expect_success PERL_TEST_HELPERS "$test_description" '
21 +test_expect_success "$test_description" '
22 printf "\nx\n" > f &&
23 before=$(git hash-object f) &&
24 before=$(git rev-parse --short $before) &&
@@ -31,7 +31,8 @@ test_expect_success PERL_TEST_HELPERS "$test_description" '
31 git config --bool diff.suppressBlankEmpty true &&
32 git diff f > actual &&
33 test_cmp exp actual &&
34 - perl -i.bak -p -e "s/^\$/ /" exp &&
34 + sed "s/^\$/ /" exp >exp.munged &&
35 + mv exp.munged exp &&
36 git config --bool diff.suppressBlankEmpty false &&
37 git diff f > actual &&
38 test_cmp exp actual &&
t/t4200-rerere.sh
+3 -9
@@ -27,12 +27,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
27
28 . ./test-lib.sh
29
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 -
30 test_expect_success 'setup' '
31 cat >a1 <<-\EOF &&
32 Some title
@@ -87,7 +81,7 @@ test_expect_success 'activate rerere, old style (conflicting merge)' '
81 test_might_fail git config --unset rerere.enabled &&
82 test_must_fail git merge first &&
83
90 - sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
84 + sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
85 rr=.git/rr-cache/$sha1 &&
86 grep "^=======\$" $rr/preimage &&
87 ! test -f $rr/postimage &&
@@ -100,7 +94,7 @@ test_expect_success 'rerere.enabled works, too' '
94 git reset --hard &&
95 test_must_fail git merge first &&
96
103 - sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
97 + sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
98 rr=.git/rr-cache/$sha1 &&
99 grep ^=======$ $rr/preimage
100 '
@@ -110,7 +104,7 @@ test_expect_success 'set up rr-cache' '
104 git config rerere.enabled true &&
105 git reset --hard &&
106 test_must_fail git merge first &&
113 - sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
107 + sha1=$(sed "s/ .*//" .git/MERGE_RR) &&
108 rr=.git/rr-cache/$sha1
109 '
110
t/t5303-pack-corruption-resilience.sh
+6 -4
@@ -99,11 +99,12 @@ test_expect_success '... and loose copy of first delta allows for partial recove
99 git cat-file blob $blob_3 > /dev/null
100 '
101
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' '
103 create_new_pack &&
104 git prune-packed &&
105 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 &&
108 test_must_fail git cat-file blob $blob_1 > /dev/null &&
109 test_must_fail git cat-file blob $blob_2 > /dev/null &&
110 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' '
157 git cat-file blob $blob_3 > /dev/null
158 '
159
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' '
161 create_new_pack &&
162 git prune-packed &&
163 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 &&
166 git cat-file blob $blob_1 > /dev/null &&
167 test_must_fail git cat-file blob $blob_2 > /dev/null &&
168 test_must_fail git cat-file blob $blob_3 > /dev/null
t/t5310-pack-bitmaps.sh
+2 -2
@@ -395,7 +395,7 @@ test_bitmap_cases () {
395 )
396 '
397
398 - test_expect_success PERL_TEST_HELPERS 'pack.preferBitmapTips' '
398 + test_expect_success 'pack.preferBitmapTips' '
399 git init repo &&
400 test_when_finished "rm -fr repo" &&
401 (
@@ -421,7 +421,7 @@ test_bitmap_cases () {
421
422 # mark the commits which did not receive bitmaps as preferred,
423 # and generate the bitmap again
424 - perl -pe "s{^}{create refs/tags/include/$. }" <before |
424 + sed "s|\(.*\)|create refs/tags/include/\1 \1|" before |
425 git update-ref --stdin &&
426 git -c pack.preferBitmapTips=refs/tags/include repack -adb &&
427
t/t5534-push-signed.sh
+2 -2
@@ -177,7 +177,7 @@ test_expect_success GPGSSH 'ssh signed push sends push certificate' '
177 test_cmp expect dst/push-cert-status
178 '
179
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' '
181 # First, invoke receive-pack with dummy input to obtain its preamble.
182 prepare_dst &&
183 git -C dst config receive.certnonceseed sekrit &&
@@ -205,7 +205,7 @@ test_expect_success GPG,PERL_TEST_HELPERS 'inconsistent push options in signed p
205 # Tweak the push output to make the push option outside the cert
206 # different, then replay it on a fresh dst, checking that ff is not
207 # deleted.
208 - perl -pe "s/([^ ])bar/\$1baz/" push >push.tweak &&
208 + sed "s/\([^ ]\)bar/\1baz/" push >push.tweak &&
209 prepare_dst &&
210 git -C dst config receive.certnonceseed sekrit &&
211 git -C dst config receive.advertisepushoptions 1 &&
t/t6011-rev-list-with-bad-commit.sh
+9 -11
@@ -4,12 +4,6 @@ test_description='git rev-list should notice bad commits'
4
5 . ./test-lib.sh
6
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 -
7 # Note:
8 # - compression level is set to zero to make "corruptions" easier to perform
9 # - reflog is disabled to avoid extra references which would twart the test
@@ -41,11 +35,15 @@ test_expect_success 'verify number of revisions' \
35 first_commit=$(git rev-parse HEAD~3)
36 '
37
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 +'
47
48 test_expect_success 'rev-list should fail' '
49 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
+2 -7
@@ -4,12 +4,6 @@ test_description='check handling of disallowed .gitmodule urls'
4
5 . ./test-lib.sh
6
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 -
7 test_expect_success 'setup' '
8 git config --global protocol.file.allow always
9 '
@@ -39,7 +33,8 @@ test_expect_success 'fsck accepts protected dash' '
33 '
34
35 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 &&
38 git commit -am "drop protection"
39 '
40
t/t7508-status.sh
+2 -2
@@ -1064,9 +1064,9 @@ test_expect_success 'status -s submodule summary (clean submodule)' '
1064 test_cmp expect output
1065 '
1066
1067 -test_expect_success PERL_TEST_HELPERS 'status -z implies porcelain' '
1067 +test_expect_success 'status -z implies porcelain' '
1068 git status --porcelain |
1069 - perl -pe "s/\012/\000/g" >expect &&
1069 + tr "\012" "\000" >expect &&
1070 git status -z >output &&
1071 test_cmp expect output
1072 '
t/t8006-blame-textconv.sh
+1 -7
@@ -4,12 +4,6 @@ test_description='git blame textconv support'
4
5 . ./test-lib.sh
6
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 -
7 find_blame() {
8 sed -e 's/^[^(]*//'
9 }
@@ -17,7 +11,7 @@ find_blame() {
11 cat >helper <<'EOF'
12 #!/bin/sh
13 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"
15 EOF
16 chmod +x helper
17
t/t9137-git-svn-dcommit-clobber-series.sh
+8 -6
@@ -15,13 +15,13 @@ test_expect_success 'initialize repo' '
15 test -e file
16 '
17
18 -test_expect_success PERL_TEST_HELPERS '(supposedly) non-conflicting change from SVN' '
18 +test_expect_success '(supposedly) non-conflicting change from SVN' '
19 test x"$(sed -n -e 58p < file)" = x58 &&
20 test x"$(sed -n -e 61p < file)" = x61 &&
21 svn_cmd co "$svnrepo" tmp &&
22 (cd tmp &&
23 - perl -i.bak -p -e "s/^58$/5588/" file &&
24 - perl -i.bak -p -e "s/^61$/6611/" file &&
23 + sed -e "s/^58$/5588/" -e "s/^61$/6611/" file >file.munged &&
24 + mv file.munged file &&
25 poke file &&
26 test x"$(sed -n -e 58p < file)" = x5588 &&
27 test x"$(sed -n -e 61p < file)" = x6611 &&
@@ -37,11 +37,13 @@ test_expect_success 'some unrelated changes to git' "
37 git commit -m bye-life life
38 "
39
40 -test_expect_success PERL_TEST_HELPERS 'change file but in unrelated area' "
40 +test_expect_success 'change file but in unrelated area' "
41 test x\"\$(sed -n -e 4p < file)\" = x4 &&
42 test x\"\$(sed -n -e 7p < file)\" = x7 &&
43 - perl -i.bak -p -e 's/^4\$/4444/' file &&
44 - perl -i.bak -p -e 's/^7\$/7777/' file &&
43 + sed -e 's/^4\$/4444/' \
44 + -e 's/^7\$/7777/' \
45 + file >file.munged &&
46 + mv file.munged file &&
47 test x\"\$(sed -n -e 4p < file)\" = x4444 &&
48 test x\"\$(sed -n -e 7p < file)\" = x7777 &&
49 git commit -m '4 => 4444, 7 => 7777' file &&