(I reported this on perl.qa a week ago but, surprisingly, have not elicited a single response. So please excuse the double-post.)

I have encountered an anomaly in my use of Devel::Cover.

Suppose that I have two packages, Alpha and Beta, each of which implements a sayhowdy() method, albeit slightly differently from each other.

# in Alpha.pm sub sayhowdy { my $self = shift; my $string = q{}; open my $fh, ">", \$string; print $fh "Howdy, alpha\n"; close $fh; return $string; } # in Beta.pm sub sayhowdy { my $self = shift; my $string = q{}; open my $fh, ">", \$string; print $fh "Howdy, beta\n"; close $fh; return $string; }

(You can play along at home by downloading this tarball.)

The only other non-trivial difference between the two packages is that the final statement in Beta.pm assigns Beta::sayhowdy() to Alpha::sayhowdy() should Alpha::sayhowdy() somehow be (or get) undefined.

*Alpha::sayhowdy = \&sayhowdy if ! defined &Alpha::sayhowdy;

I can write the following test file to demonstrate that this reassignment can actually be made:

use Test::More qw( no_plan); use_ok( q{Alpha} ); my $class = q{Alpha}; my $self = $class->new(); isa_ok($self, $class); can_ok($class, q{sayhowdy} ); is($self->sayhowdy(), qq{Howdy, alpha\n}, "alpha sayhowdy okay"); undef &Alpha::sayhowdy; eval { $self->sayhowdy(); }; like($@, qr/^Undefined subroutine &Alpha::sayhowdy called/, "Alpha::sayhowdy() is now undefined"); require_ok('Beta'); is($self->sayhowdy(), qq{Howdy, beta\n}, "Beta::sayhowdy is now Alpha::sayhowdy");

... which produces:

[Alpha] 539 $ prove -vb t/03_gamma.t t/03_gamma....ok 1 - use Alpha; ok 2 - The object isa Alpha ok 3 - Alpha->can('sayhowdy') ok 4 - alpha sayhowdy okay ok 5 - Alpha::sayhowdy() is now undefined ok 6 - require Beta; ok 7 - Beta::sayhowdy is now Alpha::sayhowdy 1..7 ok All tests successful. Files=1, Tests=7, 0 wallclock secs

So far, so good. But when I run Devel::Cover on this distribution, the coverage report treats the glob assignment line above as if it weren't even there.

$ cover -delete $ make test HARNESS_PERL_SWITCHES=1 $ cover cover_db --report=txt > coverage.txt # in the section of coverage.txt reporting on lib/Beta.pm: # (for simplicity, displaying only statement coverage) blib/lib/Beta.pm line err stmt code 1 package Beta; 2 #$Id# 3 2 use strict; # [snip] 16 2 print $fh "Howdy, beta\n"; 17 2 close $fh; 18 2 return $string; 19 } 20 21 *Alpha::sayhowdy = \&sayhowdy if ! defined &Alpha::sayhowdy; 22 23 1;

The test file above clearly exercises line 21, but Devel::Cover reports nothing at all about that line. Has anyone encountered/can anyone explain this?

Thanks in advance.

Jim Keenan

In reply to Devel::Cover failing to report on tested statement by jkeenan1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.