Paul Johnson wrote:
On Wed, Nov 16, 2005 at 05:46:34PM -0500, David Golden wrote:
I've got a bunch of test files for a distribution that run a script that
comes with the distribution. I'd like to test my coverage against that
script. I figure that I can just pass "-MDevel::Cover" to the execution of
the script if that's also in the HARNESS_PERL_SWITCHES.
I would hope things should work just as you are expecting, that is all
twenty runs should be merged to give combined coverage for the script
and any modules used.
It doesn't appear to work when the test script changes into another
directory before running the script, even when the -db is explicitly specified.
I've attached some shorter test files outside of a Test::Harness structure
that illustrates the issue:
* script.pl -- has simple logic to report whether it's currently in the same
directory as one passed in @ARGV. This simple branch just illustrates the
coverage that I'm trying to confirm for this script.
* test1.pl -- calls script.pl with Devel::Cover flags with an absolute path
to a cover_db (branch 1)
* test2.pl -- changes to a temp directory and then calls script.pl with
Devel::Cover flags with an absolute path to a cover_db (branch 2)
The Devel::Cover output varies depending on the order in which test1 and
test2 are run (output edited down to remove what is ignored, etc.). When
test1 is run first, test2 summary shows all "n/a". When test2 is run first,
they both show a summary. In both cases, running "cover" gives a message
about merging, but shows only one half of the data instead of showing 100%
coverage (even though printed messages confirm both paths are being taken).
CASE 1: test1.pl followed by test2.pl:
$ cover -delete; perl test1.pl; perl test2.pl; cover
Deleting database /home/david/tmp/coverage-test/cover_db
still in original dir
Devel::Cover: Writing coverage database to
/home/david/tmp/coverage-test/cover_db/runs/1132225902.3809.46276
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
script.pl 83.3 50.0 n/a 100.0 n/a 100.0 82.6
Total 83.3 50.0 n/a 100.0 n/a 100.0 82.6
---------------------------- ------ ------ ------ ------ ------ ------ ------
not in original dir
Devel::Cover: Can't find file "blib/lib/Storable.pm": ignored.
Devel::Cover: Writing coverage database to
/home/david/tmp/coverage-test/cover_db/runs/1132225905.3815.31279
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
...p/coverage-test/script.pl n/a n/a n/a n/a n/a n/a n/a
Total n/a n/a n/a n/a n/a n/a n/a
---------------------------- ------ ------ ------ ------ ------ ------ ------
Reading database from /home/david/tmp/coverage-test/cover_db
Devel::Cover: merging data for script.pl into
/home/david/tmp/coverage-test/script.pl
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
...p/coverage-test/script.pl 83.3 50.0 n/a 100.0 n/a 100.0 82.6
Total 83.3 50.0 n/a 100.0 n/a 100.0 82.6
---------------------------- ------ ------ ------ ------ ------ ------ ------
CASE 2: test2.pl followed by test1.pl:
$ cover -delete; perl test2.pl; perl test1.pl; cover
Deleting database /home/david/tmp/coverage-test/cover_db
not in original dir
Devel::Cover: Writing coverage database to
/home/david/tmp/coverage-test/cover_db/runs/1132226001.3823.04804
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
...p/coverage-test/script.pl 83.3 50.0 n/a 100.0 n/a 100.0 82.6
Total 83.3 50.0 n/a 100.0 n/a 100.0 82.6
---------------------------- ------ ------ ------ ------ ------ ------ ------
still in original dir
Devel::Cover: Can't find file "blib/lib/Storable.pm": ignored.
Devel::Cover: Writing coverage database to
/home/david/tmp/coverage-test/cover_db/runs/1132226004.3827.08742
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
script.pl 83.3 50.0 n/a 100.0 n/a 100.0 82.6
Total 83.3 50.0 n/a 100.0 n/a 100.0 82.6
---------------------------- ------ ------ ------ ------ ------ ------ ------
Reading database from /home/david/tmp/coverage-test/cover_db
Devel::Cover: merging data for /home/david/tmp/coverage-test/script.pl into
script.pl
---------------------------- ------ ------ ------ ------ ------ ------ ------
File stmt bran cond sub pod time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
script.pl 83.3 50.0 n/a 100.0 n/a 100.0 82.6
Total 83.3 50.0 n/a 100.0 n/a 100.0 82.6
---------------------------- ------ ------ ------ ------ ------ ------ ------
For reference, this is Devel::Cover 0.55 on Perl 5.8.6 on
linux-i386-thread-multi.
I'm guessing that maybe there's a problem in the file normalization or in
the merging of information, but I'm a bit stumped trying to follow the code.
Any guidance is greatly appreciated.
David Golden
#!/usr/bin/perl
use strict;
use warnings;
use File::pushd;
use Path::Class;
my $cwd = dir->absolute;
my $db = $cwd->subdir("cover_db");
my $prog = file($cwd,"script.pl");
{
my $dir = tempd;
system( $^X, "-MDevel::Cover=-db,$db", $prog, $cwd );
}
#!/usr/bin/perl
use strict;
use warnings;
use Path::Class;
my $cwd = dir()->absolute;
my $old = shift;
if ( $cwd eq $old ) {
print "still in original dir\n";
my $i = 1;
$i++
}
else {
print "not in original dir\n";
my $j = 100;
$j--;
}
#!/usr/bin/perl
use strict;
use warnings;
use Path::Class;
my $cwd = dir()->absolute;
my $db = $cwd->subdir("cover_db");
my $prog = file($cwd,"script.pl");
system($^X, "-MDevel::Cover=-db,$db,-silent,0", $prog, $cwd);