pjcj / Devel--Cover

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

Coverage failure with overloading and operator || #152

Open dolmen opened 8 years ago

dolmen commented 8 years ago

My module Term::Chrome does advanced usage of operator overloading. Here is what it overloads:

use overload
    '""' => 'term',
    '+'  => '_plus',
    '${}' => '_deref',
    '&{}' => '_chromizer',
    '.'   => '_concat',
    fallback => 0,
;

Here is a test case that works correctly without Devel::Cover, but fails when I enable Devel::Cover 1.21. The failure: Operation "bool": no method found, argument in overloaded package Term::Chrome::Color.

use strict;
use warnings;

use Term::Chrome qw< Red >;

print <<EOF;
1..1
# perl $^V
# Term::Chrome $Term::Chrome::VERSION $INC{'Term/Chrome.pm'}
EOF

my $c = undef || Red;   # <---- failure here

print "ok 1\n";

Output:

$ perl x.t
1..1
# perl v5.20.2
# Term::Chrome 1.012 /home/dolmen/.plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2/Term/Chrome.pm
ok 1
$ PERL5OPT=-MDevel::Cover perl x.t
1..1
# perl v5.20.2
# Term::Chrome 1.012 /home/dolmen/.plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2/Term/Chrome.pm
Operation "bool": no method found, argument in overloaded package Term::Chrome::Color at x.t line 10.
Devel::Cover: Deleting old coverage for changed file x.t
dolmen commented 8 years ago

See usage of this expression real code: dolmen/angel-PS1 lib/AngelPS1/Plugin/Jobs.pm line 20

dolmen commented 8 years ago

@pjcj Let me know if you need a simpler testcase as we are both at perlqah2016. Note that Term::Chrome on CPAN is now in a higher (2.00) version that overloads bool, so the 1.012 has to be used to show the issue.

dolmen commented 8 years ago

Here are the steps to reproduce:

git clone --no-checkout https://github.com/dolmen/p5-Term-Chrome.git Term-Chrome
cd Term-Chrome
git checkout 07850d7
perl -MDevel::Cover -Ilib t/50-cover-bug.t

Output with Devel::Cover 1.23:

Devel::Cover 0.001: Collecting coverage data for branch, condition, pod, statement, subroutine and time.
Selecting packages matching:
Ignoring packages matching:
    /Devel/Cover[./]
Ignoring packages in:
    /home/dolmen/.plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2/x86_64-linux
    /home/dolmen/.plenv/versions/5.20.2/lib/perl5/site_perl/5.20.2
    /home/dolmen/.plenv/versions/5.20.2/lib/perl5/5.20.2/x86_64-linux
    /home/dolmen/.plenv/versions/5.20.2/lib/perl5/5.20.2
1..1
# perl v5.20.2
# Term::Chrome 1.012 lib/Term/Chrome.pm
Operation "bool": no method found, argument in overloaded package Term::Chrome::Color at t/50-cover-bug.t line 16.
Devel::Cover: Writing coverage database to /home/dolmen/tmp/Term-Chrome/cover_db/runs/1464041221.16197.00019
---------------------------- ------ ------ ------ ------ ------ ------ ------
File                           stmt   bran   cond    sub    pod   time  total
---------------------------- ------ ------ ------ ------ ------ ------ ------
lib/Term/Chrome.pm             47.5    9.0   33.3   47.0   60.0    2.1   34.6
t/50-cover-bug.t               91.6    n/a   50.0  100.0    n/a   97.8   88.2
Total                          54.7    9.0   40.0   55.0   60.0  100.0   40.8
---------------------------- ------ ------ ------ ------ ------ ------ ------