pjcj / Devel--Cover

Code coverage metrics for Perl
http://www.pjcj.net/perl.html
93 stars 87 forks source link

html_basic report does not work with git annotation #309

Closed wangvisual closed 1 year ago

wangvisual commented 1 year ago

When using 'cover -report html_basic -annotation git', the report is broken: capture

With a few lines of warnings like: Use of uninitialized value $file in hash element at lib/perl5/x86_64-linux/Devel/Cover/DB.pm line 337

This is due to: in Devel/Cover/Report/Html_basic.pm line 446:

for (@{$options->{file}}) {
    $R{file} = $_;
    $R{file_link} = "$R{filenames}{$_}.html";
    $R{file_html} = "$options->{outputdir}/$R{file_link}"; 
    my $show = $options->{show};
    print_file;
    print_branches    if $show->{branch};
    print_conditions  if $show->{condition};
    print_subroutines if $show->{subroutine} || $show->{pod};
} 

Here the default variable '$_' is used for the loop, which is actually an alias for elements in '$options->{file}', and will be as input parameters for print* functions, and finally '$_' will be propagated to Devel/Cover/Annotation/Git.pm : get_annotations

   my $start = 1;
    while (<$c>) {
        # print "[$_]\n";
        if (/^\t/) {
            push @$a, [@a];
            $start = 1;
            next;
        }

        if ($start == 1) {
            $a[0] = substr $1, 0, 8 if /^(\w+)/;
            $start = 0;
        } else {
            $a[1] = $1 if /^author (.*)/;
            $a[2] = localtime $1 if /^author-time (.*)/;
        }
    }

Here, 'while (<$c>)' will also use '$_' and after the loop, $_ will be set to undef, which undef all elements in $options->{file}.

I'll send out pull request later.

pjcj commented 1 year ago

Fixed with #310