Files
git/t/t8011-blame-split-file.sh
Patrick Steinhardt 23e21a58d5 t: introduce PERL_TEST_HELPERS prerequisite
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>
2025-04-07 14:47:37 -07:00

119 lines
2.7 KiB
Bash
Executable File

#!/bin/sh
test_description='
The general idea is that we have a single file whose lines come from
multiple other files, and those individual files were modified in the same
commits. That means that we will see the same commit in multiple contexts,
and each one should be attributed to the correct file.
Note that we need to use "blame -C" to find the commit for all lines. We will
not bother testing that the non-C case fails to find it. That is how blame
behaves now, but it is not a property we want to make sure is retained.
'
. ./test-lib.sh
# help avoid typing and reading long strings of similar lines
# in the tests below
generate_expect () {
while read nr data
do
i=0
while test $i -lt $nr
do
echo $data
i=$((i + 1))
done
done
}
test_expect_success 'setup split file case' '
# use lines long enough to trigger content detection
test_seq 1000 1010 >one &&
test_seq 2000 2010 >two &&
git add one two &&
test_commit base &&
sed "6s/^/modified /" <one >one.tmp &&
mv one.tmp one &&
sed "6s/^/modified /" <two >two.tmp &&
mv two.tmp two &&
git add -u &&
test_commit modified &&
cat one two >combined &&
git add combined &&
git rm one two &&
test_commit combined
'
test_expect_success 'setup simulated porcelain' '
# This just reads porcelain-ish output and tries
# to output the value of a given field for each line (either by
# reading the field that accompanies this line, or referencing
# the information found last time the commit was mentioned).
cat >read-porcelain.pl <<-\EOF
my $field = shift;
while (<>) {
if (/^[0-9a-f]{40,} /) {
flush();
$hash = $&;
} elsif (/^$field (.*)/) {
$cache{$hash} = $1;
}
}
flush();
sub flush {
return unless defined $hash;
if (defined $cache{$hash}) {
print "$cache{$hash}\n";
} else {
print "NONE\n";
}
}
EOF
'
for output in porcelain line-porcelain
do
test_expect_success "generate --$output output" '
git blame --root -C --$output combined >output
'
test_expect_success PERL_TEST_HELPERS "$output output finds correct commits" '
generate_expect >expect <<-\EOF &&
5 base
1 modified
10 base
1 modified
5 base
EOF
perl read-porcelain.pl summary <output >actual &&
test_cmp expect actual
'
test_expect_success PERL_TEST_HELPERS "$output output shows correct filenames" '
generate_expect >expect <<-\EOF &&
11 one
11 two
EOF
perl read-porcelain.pl filename <output >actual &&
test_cmp expect actual
'
test_expect_success PERL_TEST_HELPERS "$output output shows correct previous pointer" '
generate_expect >expect <<-EOF &&
5 NONE
1 $(git rev-parse modified^) one
10 NONE
1 $(git rev-parse modified^) two
5 NONE
EOF
perl read-porcelain.pl previous <output >actual &&
test_cmp expect actual
'
done
test_done