t: refactor tests depending on Perl transliteration operator
We have a bunch of tests that use Perl to perform character transliteration via the "y/" or "tr/" operator. These usecases can be trivially replaced with 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
db8ff64a3a5244b44e27e0d46a48a304a2e36456
7 files changed
+19
-31
t/helper/test-sha1.sh
+2
-2
@@ -15,7 +15,7 @@ do
15
{
16
test -z "$pfx" || echo "$pfx"
17
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
18
- perl -pe 'y/\000/g/'
18
+ tr "\000" "g"
19
} | ./t/helper/test-tool $sha1 $cnt
20
)
21
if test "$expect" = "$actual"
@@ -61,7 +61,7 @@ do
61
{
62
test -z "$pfx" || echo "$pfx"
63
dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
64
- perl -pe 'y/\000/g/'
64
+ tr "\000" "g"
65
} | sha1sum |
66
sed -e 's/ .*//'
67
)
t/lib-diff.sh
+2
-2
@@ -21,8 +21,8 @@ compare_diff_raw_z () {
21
# Also we do not check SHA1 hash generation in this test, which
22
# is a job for t0000-basic.sh
23
24
- perl -pe 'y/\000/\012/' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
25
- perl -pe 'y/\000/\012/' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
24
+ tr "\000" "\012" <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
25
+ tr "\000" "\012" <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
26
test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
27
}
28
t/t3300-funny-names.sh
+6
-6
@@ -63,14 +63,14 @@ test_expect_success 'ls-files quotes funny filename' '
63
test_cmp expected current
64
'
65
66
-test_expect_success PERL_TEST_HELPERS 'ls-files -z does not quote funny filename' '
66
+test_expect_success 'ls-files -z does not quote funny filename' '
67
cat >expected <<-\EOF &&
68
just space
69
no-funny
70
tabs ," (dq) and spaces
71
EOF
72
git ls-files -z >ls-files.z &&
73
- perl -pe "y/\000/\012/" <ls-files.z >current &&
73
+ tr "\000" "\012" <ls-files.z >current &&
74
test_cmp expected current
75
'
76
@@ -101,23 +101,23 @@ test_expect_success 'diff-tree --name-status quotes funny filename' '
101
test_cmp expected current
102
'
103
104
-test_expect_success PERL_TEST_HELPERS 'diff-index -z does not quote funny filename' '
104
+test_expect_success 'diff-index -z does not quote funny filename' '
105
cat >expected <<-\EOF &&
106
A
107
tabs ," (dq) and spaces
108
EOF
109
git diff-index -z --name-status $t0 >diff-index.z &&
110
- perl -pe "y/\000/\012/" <diff-index.z >current &&
110
+ tr "\000" "\012" <diff-index.z >current &&
111
test_cmp expected current
112
'
113
114
-test_expect_success PERL_TEST_HELPERS 'diff-tree -z does not quote funny filename' '
114
+test_expect_success 'diff-tree -z does not quote funny filename' '
115
cat >expected <<-\EOF &&
116
A
117
tabs ," (dq) and spaces
118
EOF
119
git diff-tree -z --name-status $t0 $t1 >diff-tree.z &&
120
- perl -pe y/\\000/\\012/ <diff-tree.z >current &&
120
+ tr "\000" "\012" <diff-tree.z >current &&
121
test_cmp expected current
122
'
123
t/t4020-diff-external.sh
+3
-3
@@ -237,9 +237,9 @@ check_external_diff 0 empty empty 0 on --quiet
237
check_external_diff 1 empty empty 1 on --quiet
238
check_external_diff 128 empty error 2 on --quiet
239
240
-echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
240
+echo NULZbetweenZwords | tr "Z" "\000" > file
241
242
-test_expect_success PERL_TEST_HELPERS 'force diff with "diff"' '
242
+test_expect_success 'force diff with "diff"' '
243
after=$(git hash-object file) &&
244
after=$(git rev-parse --short $after) &&
245
echo >.gitattributes "file diff" &&
@@ -300,7 +300,7 @@ test_expect_success 'external diff with autocrlf = true' '
300
test $(wc -l <crlfed.txt) = $(keep_only_cr <crlfed.txt | wc -c)
301
'
302
303
-test_expect_success PERL_TEST_HELPERS 'diff --cached' '
303
+test_expect_success 'diff --cached' '
304
test_config core.autocrlf true &&
305
git add file &&
306
git update-index --assume-unchanged file &&
t/t4103-apply-binary.sh
+3
-9
@@ -11,12 +11,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11
12
. ./test-lib.sh
13
14
-if ! test_have_prereq PERL_TEST_HELPERS
15
-then
16
- skip_all='skipping apply-binary tests; Perl not available'
17
- test_done
18
-fi
19
-
14
test_expect_success 'setup' '
15
cat >file1 <<-\EOF &&
16
A quick brown fox jumps over the lazy dog.
@@ -32,10 +26,10 @@ test_expect_success 'setup' '
26
git commit -m "Initial Version" 2>/dev/null &&
27
28
git checkout -b binary &&
35
- perl -pe "y/x/\000/" <file1 >file3 &&
29
+ tr "x" "\000" <file1 >file3 &&
30
cat file3 >file4 &&
31
git add file2 &&
38
- perl -pe "y/\000/v/" <file3 >file1 &&
32
+ tr "y" "\000" <file3 >file1 &&
33
rm -f file2 &&
34
git update-index --add --remove file1 file2 file3 file4 &&
35
git commit -m "Second Version" &&
@@ -164,7 +158,7 @@ test_expect_success 'apply binary -p0 diff' '
158
test -z "$(git diff --name-status binary -- file3)"
159
'
160
167
-test_expect_success 'reject truncated binary diff' '
161
+test_expect_success PERL_TEST_HELPERS 'reject truncated binary diff' '
162
do_reset &&
163
164
# this length is calculated to get us very close to
t/t4116-apply-reverse.sh
+2
-8
@@ -10,23 +10,17 @@ test_description='git apply in reverse
10
11
. ./test-lib.sh
12
13
-if ! test_have_prereq PERL_TEST_HELPERS
14
-then
15
- skip_all='skipping apply reverse tests; Perl not available'
16
- test_done
17
-fi
18
-
13
test_expect_success setup '
14
15
test_write_lines a b c d e f g h i j k l m n >file1 &&
22
- perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
16
+ tr "ijk" "\000\001\002" <file1 >file2 &&
17
18
git add file1 file2 &&
19
git commit -m initial &&
20
git tag initial &&
21
22
test_write_lines a b c g h i J K L m o n p q >file1 &&
29
- perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
23
+ tr "mon" "\000\001\002" <file1 >file2 &&
24
25
git commit -a -m second &&
26
git tag second &&
t/t4200-rerere.sh
+1
-1
@@ -194,7 +194,7 @@ test_expect_success 'rerere updates postimage timestamp' '
194
195
test_expect_success 'rerere clear' '
196
mv $rr/postimage .git/post-saved &&
197
- echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
197
+ echo "$sha1 a1" | tr "\012" "\000" >.git/MERGE_RR &&
198
git rerere clear &&
199
! test -d $rr
200
'