Skip to content

Commit 4a7af4e

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6aec8d3 commit 4a7af4e

File tree

3 files changed

+13
-36
lines changed

3 files changed

+13
-36
lines changed

t/t4030-diff-textconv.sh

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ test_description='diff.*.textconv tests'
44

55
. ./test-lib.sh
66

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-
137
find_diff() {
148
sed '1,/^index /d' | sed '/^-- $/,$d'
159
}
@@ -26,13 +20,10 @@ cat >expect.text <<'EOF'
2620
+1
2721
EOF
2822

29-
cat >hexdump <<'EOF'
30-
#!/bin/sh
31-
"$PERL_PATH" -e '$/ = undef; $_ = <>; s/./ord($&)/ge; print $_' < "$1"
32-
EOF
33-
chmod +x hexdump
34-
3523
test_expect_success 'setup binary file with history' '
24+
write_script hexdump <<-\EOF &&
25+
tr "\000\001" "01" <"$1"
26+
EOF
3627
test_commit --printf one file "\\0\\n" &&
3728
test_commit --printf --append two file "\\01\\n"
3829
'

t/t4031-diff-rewrite-binary.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,19 @@ test_expect_success 'diff --stat counts binary rewrite as 0 lines' '
5757
grep " rewrite file" diff
5858
'
5959

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-
6860
test_expect_success 'setup textconv' '
61+
write_script dump <<-\EOF &&
62+
test-tool hexdump <"$1"
63+
EOF
6964
echo file diff=foo >.gitattributes &&
7065
git config diff.foo.textconv "\"$(pwd)\""/dump
7166
'
7267

73-
test_expect_success PERL_TEST_HELPERS 'rewrite diff respects textconv' '
68+
test_expect_success 'rewrite diff respects textconv' '
7469
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
7873
'
7974

8075
test_done

t/t7815-grep-binary.sh

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ test_description='git grep in binary files'
44

55
. ./test-lib.sh
66

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-
137
test_expect_success 'setup' "
148
echo 'binaryQfileQm[*]cQ*æQð' | q_to_nul >a &&
159
git add a &&
@@ -120,13 +114,10 @@ test_expect_success 'grep respects not-binary diff attribute' '
120114
test_cmp expect actual
121115
'
122116

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-
129117
test_expect_success 'setup textconv filters' '
118+
write_script nul_to_q_textconv <<-\EOF &&
119+
tr "\000" "Q" <"$1"
120+
EOF
130121
echo a diff=foo >.gitattributes &&
131122
git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
132123
'

0 commit comments

Comments
 (0)