]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: refactor tests depending on Perl transliteration operator
authorPatrick Steinhardt <ps@pks.im>
Thu, 3 Apr 2025 05:06:01 +0000 (07:06 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Apr 2025 21:47:38 +0000 (14:47 -0700)
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>
t/helper/test-sha1.sh
t/lib-diff.sh
t/t3300-funny-names.sh
t/t4020-diff-external.sh
t/t4103-apply-binary.sh
t/t4116-apply-reverse.sh
t/t4200-rerere.sh

index bf387d3db14d8bb66c4fcaad7d077068dc93b942..f03b784ddc2b4dea5e626f031019978bbcf56d7c 100755 (executable)
@@ -15,7 +15,7 @@ do
                        {
                                test -z "$pfx" || echo "$pfx"
                                dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
-                               perl -pe 'y/\000/g/'
+                               tr "\000" "g"
                        } | ./t/helper/test-tool $sha1 $cnt
                )
                if test "$expect" = "$actual"
@@ -61,7 +61,7 @@ do
                {
                        test -z "$pfx" || echo "$pfx"
                        dd if=/dev/zero bs=1048576 count=$cnt 2>/dev/null |
-                       perl -pe 'y/\000/g/'
+                       tr "\000" "g"
                } | sha1sum |
                sed -e 's/ .*//'
        )
index c4606bd4b7f0aa3f64335569cd5c379f6617f59e..12b3c8fcc6a49515d69705a3408f1d79bc02d2f1 100644 (file)
@@ -21,8 +21,8 @@ compare_diff_raw_z () {
     # Also we do not check SHA1 hash generation in this test, which
     # is a job for t0000-basic.sh
 
-    perl -pe 'y/\000/\012/' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
-    perl -pe 'y/\000/\012/' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
+    tr "\000" "\012" <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1
+    tr "\000" "\012" <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2
     test_cmp .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
 }
 
index 502b1572059b3f9212c54e81add5941747d8c0a5..dd0586b0073c20e30b72b78d57c52bc2285c3705 100755 (executable)
@@ -63,14 +63,14 @@ test_expect_success 'ls-files quotes funny filename' '
        test_cmp expected current
 '
 
-test_expect_success PERL_TEST_HELPERS 'ls-files -z does not quote funny filename' '
+test_expect_success 'ls-files -z does not quote funny filename' '
        cat >expected <<-\EOF &&
        just space
        no-funny
        tabs    ," (dq) and spaces
        EOF
        git ls-files -z >ls-files.z &&
-       perl -pe "y/\000/\012/" <ls-files.z >current &&
+       tr "\000" "\012" <ls-files.z >current &&
        test_cmp expected current
 '
 
@@ -101,23 +101,23 @@ test_expect_success 'diff-tree --name-status quotes funny filename' '
        test_cmp expected current
 '
 
-test_expect_success PERL_TEST_HELPERS 'diff-index -z does not quote funny filename' '
+test_expect_success 'diff-index -z does not quote funny filename' '
        cat >expected <<-\EOF &&
        A
        tabs    ," (dq) and spaces
        EOF
        git diff-index -z --name-status $t0 >diff-index.z &&
-       perl -pe "y/\000/\012/" <diff-index.z >current &&
+       tr "\000" "\012" <diff-index.z >current &&
        test_cmp expected current
 '
 
-test_expect_success PERL_TEST_HELPERS 'diff-tree -z does not quote funny filename' '
+test_expect_success 'diff-tree -z does not quote funny filename' '
        cat >expected <<-\EOF &&
        A
        tabs    ," (dq) and spaces
        EOF
        git diff-tree -z --name-status $t0 $t1 >diff-tree.z &&
-       perl -pe y/\\000/\\012/ <diff-tree.z >current &&
+       tr "\000" "\012" <diff-tree.z >current &&
        test_cmp expected current
 '
 
index 189294de7ef8f6b276f0b07784098ea48ce9284f..c8a23d51483e376d2c130a91f3e8706d548fcca1 100755 (executable)
@@ -237,9 +237,9 @@ check_external_diff   0 empty  empty 0 on  --quiet
 check_external_diff   1 empty  empty 1 on  --quiet
 check_external_diff 128 empty  error 2 on  --quiet
 
-echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file
+echo NULZbetweenZwords | tr "Z" "\000" > file
 
-test_expect_success PERL_TEST_HELPERS 'force diff with "diff"' '
+test_expect_success 'force diff with "diff"' '
        after=$(git hash-object file) &&
        after=$(git rev-parse --short $after) &&
        echo >.gitattributes "file diff" &&
@@ -300,7 +300,7 @@ test_expect_success 'external diff with autocrlf = true' '
        test $(wc -l <crlfed.txt) = $(keep_only_cr <crlfed.txt | wc -c)
 '
 
-test_expect_success PERL_TEST_HELPERS 'diff --cached' '
+test_expect_success 'diff --cached' '
        test_config core.autocrlf true &&
        git add file &&
        git update-index --assume-unchanged file &&
index 59d38793ae68a5ac1d88f162c16b04791a5e7eb2..8e302a5a57e82088dffac0ef8b3d042bb4a566c5 100755 (executable)
@@ -11,12 +11,6 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
 
-if ! test_have_prereq PERL_TEST_HELPERS
-then
-       skip_all='skipping apply-binary tests; Perl not available'
-       test_done
-fi
-
 test_expect_success 'setup' '
        cat >file1 <<-\EOF &&
        A quick brown fox jumps over the lazy dog.
@@ -32,10 +26,10 @@ test_expect_success 'setup' '
        git commit -m "Initial Version" 2>/dev/null &&
 
        git checkout -b binary &&
-       perl -pe "y/x/\000/" <file1 >file3 &&
+       tr "x" "\000" <file1 >file3 &&
        cat file3 >file4 &&
        git add file2 &&
-       perl -pe "y/\000/v/" <file3 >file1 &&
+       tr "y" "\000" <file3 >file1 &&
        rm -f file2 &&
        git update-index --add --remove file1 file2 file3 file4 &&
        git commit -m "Second Version" &&
@@ -164,7 +158,7 @@ test_expect_success 'apply binary -p0 diff' '
        test -z "$(git diff --name-status binary -- file3)"
 '
 
-test_expect_success 'reject truncated binary diff' '
+test_expect_success PERL_TEST_HELPERS 'reject truncated binary diff' '
        do_reset &&
 
        # this length is calculated to get us very close to
index 6f414ad27f5fa9f7a222fe711b1da774fb87d1f8..1e7beab0016e04679f95609d0fe99485b3add09f 100755 (executable)
@@ -10,23 +10,17 @@ test_description='git apply in reverse
 
 . ./test-lib.sh
 
-if ! test_have_prereq PERL_TEST_HELPERS
-then
-       skip_all='skipping apply reverse tests; Perl not available'
-       test_done
-fi
-
 test_expect_success setup '
 
        test_write_lines a b c d e f g h i j k l m n >file1 &&
-       perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
+       tr "ijk" "\000\001\002" <file1 >file2 &&
 
        git add file1 file2 &&
        git commit -m initial &&
        git tag initial &&
 
        test_write_lines a b c g h i J K L m o n p q >file1 &&
-       perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
+       tr "mon" "\000\001\002" <file1 >file2 &&
 
        git commit -a -m second &&
        git tag second &&
index 50fe8b0fd05cc9403d4db66c6df681ddf39338dc..7fcca9ddad5e8d43fb291938bcc5a3f19c258218 100755 (executable)
@@ -194,7 +194,7 @@ test_expect_success 'rerere updates postimage timestamp' '
 
 test_expect_success 'rerere clear' '
        mv $rr/postimage .git/post-saved &&
-       echo "$sha1     a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
+       echo "$sha1     a1" | tr "\012" "\000" >.git/MERGE_RR &&
        git rerere clear &&
        ! test -d $rr
 '