我在合并数据以覆盖 Perl 脚本和模块时遇到问题。单独运行 Devel::Cover 工作得很好,但是当我尝试合并数据时,我丢失的只是 Perl 脚本而不是模块的统计信息。
让我解释..
我有一个看起来像这样的目录树..
Code_Coverage_Test
|
|---->lib
|
|---->t
|
在根 Code_Coverage_Test 目录中,我有 Build.pl 文件,该文件为模块和脚本构建测试,该脚本启动另外两个脚本,为我自动执行一些命令。
./Build.pl
#!/usr/bin/perl -w
use strict;
use Module::Build;
my $buildTests = Module::Build->new(
module_name => 'testPMCoverage',
license => 'perl',
dist_abstract => 'Perl .pm Test Code Coverage',
dist_author => 'me@myEmail.com',
build_requires => {
'Test::More' => '0.10',
},
);
$buildTests->create_build_script();
./startTests.sh
#!/bin/sh
cd t
./doPMtest.sh
./doPLtest.sh
cd ../
perl Build testcover
在 lib 目录中,我有我试图在其上运行代码覆盖率的文件。
lib/testPLCoverage.pl
#!/usr/bin/perl -w
use strict;
print "Ok!";
库/testPMCoverage.pm
use strict;
use warnings;
package testPMCoverage;
sub hello {
return "Hello";
}
sub bye {
return "Bye";
}
1;
在 t 目录中,我有模块的 .t 测试文件和 2 个为我启动测试的脚本。这两个脚本都由根目录中的 startTests.sh 调用
t/testPMCoverage.t
#!/usr/bin/perl -w
use strict;
use Test::More;
require_ok( 'testPMCoverage' );
my $test = testPMCoverage::hello();
is($test, "Hello", "hello() test");
done_testing();
t/doPLtest.sh
#!/bin/sh
#Test 1
cd ../
cd lib
perl -MDevel::Cover=-db,../cover_db testPLCoverage.pl
t/doPMtest.sh
#!/bin/bash
cd ../
perl Build.pl
perl Build test
我遇到的问题是,当 doPLtests.sh 脚本运行时,我得到了覆盖率数据,没问题..
---------------------------- ------ ------ ------ ------ ------ ------ ------
File STMT Bran Cond Sub pod Time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
testPLCoverage.pl 100.0 n/a n/a 100.0 n/a 100.0 100.0
Total 100.0 n/a n/a 100.0 n/a 100.0 100.0
---------------------------- ------ ------ ------ ------ ------ ------ ------
但是,当 doPMtest.sh 脚本完成并且 startTests.sh 脚本启动 Build testcover 命令时,我会丢失该数据并收到这些消息...
Reading database path/Code_Coverage_Tests/cover_db
Devel::Cover: Warning: can't open testPLCoverage.pl for MD5 digest: No such file or directory
Devel::Cover: Warning: can't locate structure for statement in testPLCoverage.pl
Devel::Cover: Warning: can't locate structure for subroutine in testPLCoverage.pl
Devel::Cover: Warning: can't locate structure for time in testPLCoverage.pl
..不知何故我丢失了数据
---------------------------- ------ ------ ------ ------ ------ ------ ------
File STMT Bran Cond Sub pod Time total
---------------------------- ------ ------ ------ ------ ------ ------ ------
blib/lib/testPMCoverage.pm 87.5 n/a n/a 75.0 0.0 100.0 71.4
testPLCoverage.pl n/a n/a n/a n/a n/a n/a n/a
Total 87.5 n/a n/a 75.0 0.0 100.0 71.4
---------------------------- ------ ------ ------ ------ ------ ------ ------
如何结合 Perl 模块和 Perl 脚本测试以在一个文件中获得有效的代码覆盖率?