dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

I just started using Devel::Cover and it immediately reported that I wasn't testing a given subroutine. So, I add a .t for that subroutine, and the tests pass nicely. But, it still isn't marking that subroutine as tested! I pulled it out and it looks as if it's not even seeing the module. Before I open a ticket, I wanted to make sure I wasn't doing anything stupid/documented/etc.

I've included the code below:

package abcd; use strict; use warnings; $|++; sub log { my $method = shift; my $time = localtime(time); my $args = @_ ? (' ' . join(', ', @_) . ' ') : ''; warn "$time: $method($args)\n"; } ----------------- # t/001_log.t # - verify log() works use strict; use warnings; $|++; use Test::More; use IO::Scalar; plan tests => 4; my $CLASS = 'abcd'; use_ok( $CLASS ); my $log; close STDERR; tie *STDERR, 'IO::Scalar', \$log; my $ref = \&abcd::log; $log = ''; $ref->( 'foo' ); like( "$log", qr!^\w{3} \w{3} \d\d \d\d:\d\d:\d\d \d{4}: foo\(\)\n$! ) +; $log = ''; $ref->( 'foo', 'bar' ); like( "$log", qr!^\w{3} \w{3} \d\d \d\d:\d\d:\d\d \d{4}: foo\( bar \)\ +n$! ); $log = ''; $ref->( 'foo', 'bar', 'baz' ); like( "$log", qr!^\w{3} \w{3} \d\d \d\d:\d\d:\d\d \d{4}: foo\( bar, ba +z \)\n$! ) ;

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

Replies are listed 'Best First'.
Re: Devel::Cover not finding a test?
by stvn (Monsignor) on Aug 13, 2004 at 18:15 UTC

    A few possibilities off the top of my head...

    1. I am pretty sure that Devel::Cover will not report modules that are within the @INC path.
    2. Any values in that are in PERL5LIB will be also ignored by Devel::Cover. And I know in older versions, the value of PERL5LIB was taken at the time you compiled Devel::Cover, and was not updated if PERL5LIB changed.
    3. The last possibility might have something to do with your line (my $ref = \&abcd::log;) and how Devel::Cover deals with such things.
    If 1 or 2 are not the case, then I would suggest emailing the author (or the perl-qa list, where he has been known to hang out) before you submit a bug, since it might not actually be one (#3).

    -stvn
Re: Devel::Cover not finding a test?
by pbeckingham (Parson) on Aug 14, 2004 at 01:02 UTC

    When I ran your code, using Devel::Cover, I got the following on Devel::Cover 0.40, Perl 5.8.1 rc3, on OS X 10.3.5. What do you see?

    % perl -MDevel::Cover 1.t Devel::Cover 0.40: Collecting coverage data for branch, condition, sta +tement, subroutine and time. Pod coverage is unvailable. Please install Pod::Coverage from CPAN. Selecting packages matching: Ignoring packages matching: Ignoring packages in: . /Library/Perl /Library/Perl/5.8.1 /Library/Perl/5.8.1/darwin-thread-multi-2level /Network/Library/Perl /Network/Library/Perl/5.8.1 /Network/Library/Perl/5.8.1/darwin-thread-multi-2level /System/Library/Perl/5.8.1 /System/Library/Perl/5.8.1/darwin-thread-multi-2level /sw/lib/perl5 1..4 ok 1 - use abcd; ok 2 ok 3 ok 4 Devel::Cover: Writing coverage database to /Users/paul/monks/cover_db/ +runs/1092444838.2071.64541 ----------------------------------- ------ ------ ------ ------ ------ + ------ File stmt branch cond sub time + total ----------------------------------- ------ ------ ------ ------ ------ + ------ 1.t 100.0 n/a n/a n/a 90.9 + 100.0 abcd.pm 100.0 100.0 n/a 100.0 100.0 + 100.0 Total 100.0 100.0 n/a 100.0 100.0 + 100.0 ----------------------------------- ------ ------ ------ ------ ------ + ------



    pbeckingham - typist, perishable vertebrate.