In the early days of Git, Perl was used quite prominently throughout the
project. This has changed significantly as almost all of the executables
we ship nowadays have eventually been rewritten in C. Only a handful of
subsystems remain that require Perl:
- gitweb, a read-only web interface.
- A couple of scripts that allow importing repositories from GNU Arch,
CVS and Subversion.
- git-send-email(1), which can be used to send mails.
- git-request-pull(1), which is used to request somebody to pull from
a URL by sending an email.
- git-filter-branch(1), which uses Perl with the `--state-branch`
option. This command is typically recommended against nowadays in
favor of git-filter-repo(1).
- Our Perl bindings for Git.
- The netrc Git credential helper.
None of these subsystems can really be considered to be part of the
"core" of Git, and an installation without them is fully functional.
It is more likely than not that an end user wouldn't even notice that
any features are missing if those tools weren't installed. But while
Perl nowadays very much is an optional dependency of Git, there is a
significant limitation when Perl isn't available: developers cannot run
our test suite.
Preceding commits have started to lift this restriction by removing the
strict dependency on Perl in many central parts of the test library. But
there are still many tests that rely on small Perl helpers to do various
different things.
Introduce a new PERL_TEST_HELPERS prerequisite that guards all tests
that require Perl. This prerequisite is explicitly different than the
preexisting PERL prerequisite:
- PERL records whether or not features depending on the Perl
interpreter are built.
- PERL_TEST_HELPERS records whether or not a Perl interpreter is
available for our tests.
By having these two separate prerequisites we can thus distinguish
between tests that inherently depend on Perl because the underlying
feature does, and those tests that depend on Perl because the test
itself is using Perl.
Adapt all tests to set the PERL_TEST_HELPERS prerequisite as needed.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
155 lines
3.5 KiB
Bash
Executable File
155 lines
3.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
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 &&
|
|
git commit -m.
|
|
"
|
|
|
|
test_expect_success 'git grep ina a' '
|
|
echo Binary file a matches >expect &&
|
|
git grep ina a >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'git grep -ah ina a' '
|
|
git grep -ah ina a >actual &&
|
|
test_cmp a actual
|
|
'
|
|
|
|
test_expect_success 'git grep -I ina a' '
|
|
test_must_fail git grep -I ina a >actual &&
|
|
test_must_be_empty actual
|
|
'
|
|
|
|
test_expect_success 'git grep -c ina a' '
|
|
echo a:1 >expect &&
|
|
git grep -c ina a >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'git grep -l ina a' '
|
|
echo a >expect &&
|
|
git grep -l ina a >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'git grep -L bar a' '
|
|
echo a >expect &&
|
|
git grep -L bar a >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'git grep -q ina a' '
|
|
git grep -q ina a >actual &&
|
|
test_must_be_empty actual
|
|
'
|
|
|
|
test_expect_success 'git grep -F ile a' '
|
|
git grep -F ile a
|
|
'
|
|
|
|
test_expect_success 'git grep -Fi iLE a' '
|
|
git grep -Fi iLE a
|
|
'
|
|
|
|
# This test actually passes on platforms where regexec() supports the
|
|
# flag REG_STARTEND.
|
|
test_expect_success 'git grep ile a' '
|
|
git grep ile a
|
|
'
|
|
|
|
test_expect_failure 'git grep .fi a' '
|
|
git grep .fi a
|
|
'
|
|
|
|
test_expect_success 'grep respects binary diff attribute' '
|
|
echo text >t &&
|
|
git add t &&
|
|
echo t:text >expect &&
|
|
git grep text t >actual &&
|
|
test_cmp expect actual &&
|
|
echo "t -diff" >.gitattributes &&
|
|
echo "Binary file t matches" >expect &&
|
|
git grep text t >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'grep --cached respects binary diff attribute' '
|
|
git grep --cached text t >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'grep --cached respects binary diff attribute (2)' '
|
|
git add .gitattributes &&
|
|
rm .gitattributes &&
|
|
git grep --cached text t >actual &&
|
|
test_when_finished "git rm --cached .gitattributes" &&
|
|
test_when_finished "git checkout .gitattributes" &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'grep revision respects binary diff attribute' '
|
|
git commit -m new &&
|
|
echo "Binary file HEAD:t matches" >expect &&
|
|
git grep text HEAD -- t >actual &&
|
|
test_when_finished "git reset HEAD^" &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'grep respects not-binary diff attribute' '
|
|
echo binQary | q_to_nul >b &&
|
|
git add b &&
|
|
echo "Binary file b matches" >expect &&
|
|
git grep bin b >actual &&
|
|
test_cmp expect actual &&
|
|
echo "b diff" >.gitattributes &&
|
|
echo "b:binQary" >expect &&
|
|
git grep bin b >actual.raw &&
|
|
nul_to_q <actual.raw >actual &&
|
|
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' '
|
|
echo a diff=foo >.gitattributes &&
|
|
git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv
|
|
'
|
|
|
|
test_expect_success 'grep does not honor textconv' '
|
|
test_must_fail git grep Qfile
|
|
'
|
|
|
|
test_expect_success 'grep --textconv honors textconv' '
|
|
echo "a:binaryQfileQm[*]cQ*æQð" >expect &&
|
|
git grep --textconv Qfile >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_expect_success 'grep --no-textconv does not honor textconv' '
|
|
test_must_fail git grep --no-textconv Qfile
|
|
'
|
|
|
|
test_expect_success 'grep --textconv blob honors textconv' '
|
|
echo "HEAD:a:binaryQfileQm[*]cQ*æQð" >expect &&
|
|
git grep --textconv Qfile HEAD:a >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|