t: refactor tests depending on Perl for textconv scripts

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>

Patrick Steinhardt committed Apr 3, 2025 at 07:06 UTC 4a7af4edbb800ff8ed0cd131423f45c2c76e1200
3 files changed +13 -36
t/t4030-diff-textconv.sh
+3 -12
@@ -4,12 +4,6 @@ test_description='diff.*.textconv tests'
4
5 . ./test-lib.sh
6
7 -if ! test_have_prereq PERL_TEST_HELPERS
8 -then
9 - skip_all='skipping diff textconv tests; Perl not available'
10 - test_done
11 -fi
12 -
7 find_diff() {
8 sed '1,/^index /d' | sed '/^-- $/,$d'
9 }
@@ -26,13 +20,10 @@ cat >expect.text <<'EOF'
20 +1
21 EOF
22
29 -cat >hexdump <<'EOF'
30 -#!/bin/sh
31 -"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
32 -EOF
33 -chmod +x hexdump
34 -
23 test_expect_success 'setup binary file with history' '
24 + write_script hexdump <<-\EOF &&
25 + tr "\000\001" "01" <"$1"
26 + EOF
27 test_commit --printf one file "\\0\\n" &&
28 test_commit --printf --append two file "\\01\\n"
29 '
t/t4031-diff-rewrite-binary.sh
+7 -12
@@ -57,24 +57,19 @@ test_expect_success 'diff --stat counts binary rewrite as 0 lines' '
57 grep " rewrite file" diff
58 '
59
60 -{
61 - echo "#!$SHELL_PATH"
62 - cat <<'EOF'
63 -"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
64 -EOF
65 -} >dump
66 -chmod +x dump
67 -
60 test_expect_success 'setup textconv' '
61 + write_script dump <<-\EOF &&
62 + test-tool hexdump <"$1"
63 + EOF
64 echo file diff=foo >.gitattributes &&
65 git config diff.foo.textconv "\"$(pwd)\""/dump
66 '
67
73 -test_expect_success PERL_TEST_HELPERS 'rewrite diff respects textconv' '
68 +test_expect_success 'rewrite diff respects textconv' '
69 git diff -B >diff &&
75 - grep "dissimilarity index" diff &&
76 - grep "^-61" diff &&
77 - grep "^-0" diff
70 + test_grep "dissimilarity index" diff &&
71 + test_grep "^-3d 0a 00" diff &&
72 + test_grep "^+3d 0a 01" diff
73 '
74
75 test_done
t/t7815-grep-binary.sh
+3 -12
@@ -4,12 +4,6 @@ test_description='git grep in binary files'
4
5 . ./test-lib.sh
6
7 -if ! test_have_prereq PERL_TEST_HELPERS
8 -then
9 - skip_all='skipping grep binary tests; Perl not available'
10 - test_done
11 -fi
12 -
7 test_expect_success 'setup' "
8 echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
9 git add a &&
@@ -120,13 +114,10 @@ test_expect_success 'grep respects not-binary diff attribute' '
114 test_cmp expect actual
115 '
116
123 -cat >nul_to_q_textconv <<'EOF'
124 -#!/bin/sh
125 -"$PERL_PATH" -pe 'y/\000/Q/' < "$1"
126 -EOF
127 -chmod +x nul_to_q_textconv
128 -
117 test_expect_success 'setup textconv filters' '
118 + write_script nul_to_q_textconv <<-\EOF &&
119 + tr "\000" "Q" <"$1"
120 + EOF
121 echo a diff=foo >.gitattributes &&
122 git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
123 '