Discussion:
Devel::Cover problem: getting analysis of .xs file but not of .pm file
James E Keenan
2012-04-26 01:08:32 UTC
Permalink
Friends,

As an extension of my work on
https://rt.perl.org/rt3/Ticket/Display.html?id=112126, I am trying to
measure the test coverage for Perl 5 core distribution Hash-Util
provided by the Perl 5 test suite. For ease of development, I have
copied ext/Hash-Util/lib/Hash/Util.pm and ext/Hash-Util/t/Util.t into a
typical CPAN distribution setup. I have applied the patches submitted
in RT #112126 and modified t/Util.t to remove all the setup needed to
run it as part of the Perl 5 test suite and instead run it as if it were
a part of a regular CPAN distribution.

So I'm now at a point where I want to perform coverage analysis.
However, try as I might, I cannot get a report of the test coverage of
lib/Hash/Util.pm I want -- and this having used Devel::Cover for nine years!

Please see the attachment in which I show the output of:

perl Makefile.PL && make && cover -test

Note that I *am* getting coverage output for Util.xs, but I'm *not*
getting coverage for lib/Hash/Util.pm. This is most puzzling.

I have Devel::Cover version 0.80 installed and am running this with Perl
5.14.2.

To facilitate getting assistance with this, I have push my
quasi-distribution to Github:

https://github.com/jkeenan/Hash-Util

Can anyone advise as to why I am getting coverage analysis of Util.xs
but not of lib/Hash/Util.pm?

Thank you very much.
Jim Keenan
James E Keenan
2012-04-27 00:54:23 UTC
Permalink
Post by James E Keenan
Friends,
Can anyone advise as to why I am getting coverage analysis of Util.xs
but not of lib/Hash/Util.pm?
Locking %ENV frustrates Devel::Cover.

Starting at approximately line 172 of t/Util.t, we have a test which,
after I've reformatted a few lines, looks like this:

lock_keys(%ENV);
eval { () = $ENV{I_DONT_EXIST} };
like(
$@,
qr/^Attempt to access disallowed key 'I_DONT_EXIST' in a restricted
hash/,
'locked %ENV'
);

I commented out all the tests in Util.t, then worked my way through
un-commenting them and making sure that all tests still passed. Until I
got to the test above, I got favorable results calling:

prove -vb t/Util.t
cover -delete; harness; cover -summary

... where 'harness' simply calls:

HARNESS_PERL_SWITCHES=-MDevel::Cover make test

... and "favorable results" means something like this:

---------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------- ------ ------ ------ ------ ------ ------ ------
Util.xs 88.2 58.3 n/a n/a n/a n/a 70.7
blib/lib/Hash/Util.pm 82.9 59.1 11.1 87.5 92.0 100.0 78.8
Total 83.6 58.7 11.1 87.5 92.0 100.0 77.4
---------------------- ------ ------ ------ ------ ------ ------ ------

But when I extended the uncommented lines to include the 'like' after
lock_keys(%ENV), 'prove' still PASSed all tests but the line for
'blib/lib/Hash/Util.pm' vanished.

When I kept the lock_keys lines commented out, but uncommented the
balance of the file, both prove and cover DWIMmed.

Hence, these few lines were the cause of the problem. So now this
becomes an obscure bug in Devel::Cover: Why does lock_keys(%ENV) cause
reporting on a package to vanish -- but not affect the reporting on the
XS file?

I'll leave that for others (read: pjcj) to ponder. In the meantime, I
hope to add tests to shore up the surprisingly poor coverage of
Hash::Util by its test file.

Thank you very much.
Jim Keenan

Loading...