]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: refactor tests depending on Perl for textconv scripts
authorPatrick Steinhardt <ps@pks.im>
Thu, 3 Apr 2025 05:06:04 +0000 (07:06 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Apr 2025 21:47:39 +0000 (14:47 -0700)
We have a couple of tests that depend on Perl for textconv scripts.
Refactor these tests to instead be implemented via shell utilities so
that we can drop a couple of PERL_TEST_HELPERS prerequisites.

Note that the conversion in t4030 is not a one-to-one equivalent to the
previous textconv script. Before this change we used to essentially do a
hexdump via Perl. The obvious conversion here would be to use `test-tool
hexdump` like we do for the other tests. But this would lead to a ripple
effect where we would have to adapt a bunch of other tests with a bunch
of seemingly unrelated changes, which would be somewhat awkward.

Instead, we're going with the minimum viable change: the test files we
write contain "\001" and "\000", and the test's expectation is that
those get translated into proper ASCII characters. So instead of doing a
full hexdump, we simply use tr(1) to translate these specific bytes.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4030-diff-textconv.sh
t/t4031-diff-rewrite-binary.sh
t/t7815-grep-binary.sh

index c7d8eb124535a1ce28f8dbd5b2155a6395f859fe..f904fc19f69c615dc3c2a33b2b28dbfb203988c3 100755 (executable)
@@ -4,12 +4,6 @@ test_description='diff.*.textconv tests'
 
 . ./test-lib.sh
 
-if ! test_have_prereq PERL_TEST_HELPERS
-then
-       skip_all='skipping diff textconv tests; Perl not available'
-       test_done
-fi
-
 find_diff() {
        sed '1,/^index /d' | sed '/^-- $/,$d'
 }
@@ -26,13 +20,10 @@ cat >expect.text <<'EOF'
 +1
 EOF
 
-cat >hexdump <<'EOF'
-#!/bin/sh
-"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
-EOF
-chmod +x hexdump
-
 test_expect_success 'setup binary file with history' '
+       write_script hexdump <<-\EOF &&
+       tr "\000\001" "01" <"$1"
+       EOF
        test_commit --printf one file "\\0\\n" &&
        test_commit --printf --append two file "\\01\\n"
 '
index cbe50b15772fd2884aac1d6613183e08ecace00a..15e012ccc7c02e8410daffc8990b7540f44bffe2 100755 (executable)
@@ -57,24 +57,19 @@ test_expect_success 'diff --stat counts binary rewrite as 0 lines' '
        grep " rewrite file" diff
 '
 
-{
-       echo "#!$SHELL_PATH"
-       cat <<'EOF'
-"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
-EOF
-} >dump
-chmod +x dump
-
 test_expect_success 'setup textconv' '
+       write_script dump <<-\EOF &&
+       test-tool hexdump <"$1"
+       EOF
        echo file diff=foo >.gitattributes &&
        git config diff.foo.textconv "\"$(pwd)\""/dump
 '
 
-test_expect_success PERL_TEST_HELPERS 'rewrite diff respects textconv' '
+test_expect_success 'rewrite diff respects textconv' '
        git diff -B >diff &&
-       grep "dissimilarity index" diff &&
-       grep "^-61" diff &&
-       grep "^-0" diff
+       test_grep "dissimilarity index" diff &&
+       test_grep "^-3d 0a 00" diff &&
+       test_grep "^+3d 0a 01" diff
 '
 
 test_done
index b2730d200c8583e9ca08af67794dd435ea2fb8ef..3bd91da97075a6f8650b607ed77fe45827f2e348 100755 (executable)
@@ -4,12 +4,6 @@ test_description='git grep in binary files'
 
 . ./test-lib.sh
 
-if ! test_have_prereq PERL_TEST_HELPERS
-then
-       skip_all='skipping grep binary tests; Perl not available'
-       test_done
-fi
-
 test_expect_success 'setup' "
        echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
        git add a &&
@@ -120,13 +114,10 @@ test_expect_success 'grep respects not-binary diff attribute' '
        test_cmp expect actual
 '
 
-cat >nul_to_q_textconv <<'EOF'
-#!/bin/sh
-"$PERL_PATH" -pe 'y/\000/Q/' < "$1"
-EOF
-chmod +x nul_to_q_textconv
-
 test_expect_success 'setup textconv filters' '
+       write_script nul_to_q_textconv <<-\EOF &&
+       tr "\000" "Q" <"$1"
+       EOF
        echo a diff=foo >.gitattributes &&
        git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
 '