Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Devel-Cover CPAN distribution.

Report information
The Basics
Id: 72819
Status: resolved
Priority: 0/
Queue: Devel-Cover

People
Owner: Nobody in particular
Requestors: RWSTAUNER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.79
Fixed in: (no value)



Subject: 0% branch coverage for methods defined in non-reported files
Download (untitled) / with headers
text/plain 640b
A simple condition like print 1 unless defined $object->attr; reports 0% branch coverage if the "attr" sub is defined by an external file (such as Class::Accessor, etc). changing it to my $attr = $object->attr; print 1 unless defined $attr; reports 100%: line % coverage branch 16 0 T F unless defined $self->foo 20 100 T F unless defined $foo Example files and output can be seen here (also attached): https://gist.github.com/1405707 Overall branch coverage for the file is 50% (average of 0 and 100). Switching the commented lines to define the sub directly instead of using the accessor maker boosts coverage to 100%.
Subject: accessor_maker.pm
Download accessor_maker.pm
text/x-perl 121b
package accessor_maker; sub import { no strict 'refs'; *{ caller() . '::' . 'foo' } = sub { $_[0]->{ 'foo' } }; } 1;
Subject: whole.pl
Download whole.pl
text/x-perl 387b
package cm3; sub new { bless $_[1], $_[0] } # comment/uncomment one or the other: use accessor_maker; #sub foo { $_[0]->{ 'foo' } } package main; sub test { my $self = shift; print 'un' unless defined $self->foo; print "defined\n"; my $foo = $self->foo; print 'un' unless defined $foo; print "defined\n"; } test( cm3->new({}) ); test( cm3->new({foo => 1}) ); 1;
Download (untitled) / with headers
text/plain 207b
Just noticed that using an intermediate variable also solves the problem: unless defined do { my $m = $self->attr; $m } However unless defined do { my $m = $self->attr; } this still doesn't work.
Download (untitled) / with headers
text/plain 1.2k
Here is an example from the project I was working on when I discovered the issue: Coverage: 60.0% line % coverage branch 26 100 T F unless open my $fh, '<', $_ 35 100 T F grep({/\.css$/;} @{$self->files;}) ? : 100 T F unless $self->type 37 0 T F unless defined $self->minify 38 100 T F if $self->minify 48 0 T F $self->type eq 'css' ? : 57 0 T F $self->type eq 'css' ? : 75 100 T F if ($ENV{'PLACK_ENV'} and $ENV{'PLACK_ENV'} eq 'development') 77 0 T F if $self->mtime < (reverse sort @mtime)[0] 84 100 T F if $$env{'PATH_INFO'} eq $url If I add this line to the top of my test scripts: if( $INC{'Devel/Cover.pm'} ){ no warnings 'redefine'; eval "*Plack::Middleware::Assets::$_ = sub { \$_[0]->{$_} = \$_[1] if \@_ > 1; \$_[0]->{$_} };" for qw(mtime minify type); } Then everything goes to 100: Coverage: 100.0% line % coverage branch 26 100 T F unless open my $fh, '<', $_ 35 100 T F grep({/\.css$/;} @{$self->files;}) ? : 100 T F unless $self->type 37 100 T F unless defined $self->minify 38 100 T F if $self->minify 48 100 T F $self->type eq 'css' ? : 57 100 T F $self->type eq 'css' ? : 75 100 T F if ($ENV{'PLACK_ENV'} and $ENV{'PLACK_ENV'} eq 'development') 77 100 T F if $self->mtime < (reverse sort @mtime)[0] 84 100 T F if $$env{'PATH_INFO'} eq $url
Download (untitled) / with headers
text/plain 251b
Thanks very much for this report. I believe that the code is now fixed, and I have added your test case as da274dd to ensure it stays that way. If you see any further problems in this area please reopen the ticket or file a new one. Thanks again,


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.