Skip to content

Commit

Permalink
Add initial support for coverage of Devel::Cover.
Browse files Browse the repository at this point in the history
Use the debugger to get primitive statement coverage of Devel::Cover itself by
setting the environment variable $DEVEL_COVER_SELF.
  • Loading branch information
pjcj committed Aug 10, 2010
1 parent eda125d commit c4bed1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cover
Expand Up @@ -131,7 +131,7 @@ sub mb_test_command

sub main
{
if ($INC{"Devel/Cover.pm"})
if (!$ENV{DEVEL_COVER_SELF} && $INC{"Devel/Cover.pm"})
{
my $err = "$0 shouldn't be run with coverage turned on.\n";
eval
Expand Down
30 changes: 29 additions & 1 deletion lib/Devel/Cover.pm
Expand Up @@ -70,6 +70,7 @@ my $Sub_count; # Count for multiple subs on same line.

my $Coverage; # Raw coverage data.
my $Structure; # Structure of the files.
my $Self_coverage; # Coverage of Devel::Cover

my %Criteria; # Names of coverage criteria.
my %Coverage; # Coverage criteria to collect.
Expand Down Expand Up @@ -161,7 +162,32 @@ if (0 && $Config{useithreads})
BEGIN { @Inc = @Devel::Cover::Inc::Inc; @Ignore = ("/Devel/Cover[./]") }
# BEGIN { $^P = 0x004 | 0x010 | 0x100 | 0x200 }
# BEGIN { $^P = 0x004 | 0x100 | 0x200 }
BEGIN { $^P = 0x004 | 0x100 }
BEGIN { $^P |= 0x004 | 0x100 }
BEGIN
{
if ($ENV{DEVEL_COVER_SELF})
{
@Ignore = ();
$^P = 0x73f;
*DB::DB = sub
{
my (undef, $f, $l) = caller;

# print STDERR "$f:$l\n" if $f =~ /DB/;
return unless $f =~ /Devel\/Cover/;
my $nf = normalised_file($f);
$Self_coverage->{$nf}{$l}++;
return;

no strict "refs";
my $code = \@{"::_<$f"};
my $line = defined $code->[$l] ? $code->[$l] : "";
chomp $line;
print STDERR "$f:$l: $line\n";

};
}
}

{
sub check
Expand Down Expand Up @@ -732,6 +758,8 @@ sub add_statement_cover
$Run{digests}{$File} ||= $Structure->set_file($File);
my $key = get_key($op);
my $val = $Coverage->{statement}{$key} || 0;
$val = $Self_coverage->{$File}{$Line} || 0
if $ENV{DEVEL_COVER_SELF} && exists $Self_coverage->{$File};
my ($n, $new) = $Structure->add_count("statement");
$Structure->add_statement($File, $Line) if $new;
$Run{count}{$File}{statement}[$n] += $val;
Expand Down

0 comments on commit c4bed1b

Please sign in to comment.