加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Devel :: Cover合并Perl脚本和模块的覆盖率数据

发布时间:2020-12-16 06:15:38 所属栏目:大数据 来源:网络整理
导读:我有问题合并数据覆盖Perl脚本和模块..运行Devel :: Cover单独工作正常,但当我尝试组合数据时,我失去统计信息只是Perl脚本而不是模块.. 让我解释.. 我有一个看起来像这样的目录树.. Code_Coverage_Test | |----lib | |----t | 在根Code_Coverage_Test目录中,
我有问题合并数据覆盖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!";

LIB / testPMCoverage.pm

use strict;
use warnings;
package testPMCoverage;

sub hello {
    return "Hello";
}

sub bye {
    return "Bye";
}


1;

在t dir中,我有我的.t测试文件和2个脚本,为我启动测试..两个都由根目录中的startTests.sh调用

吨/ 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();

吨/ doPLtest.sh

#!/bin/sh

#Test 1
cd ../
cd lib
perl -MDevel::Cover=-db,../cover_db testPLCoverage.pl

吨/ 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脚本测试以在一个文件中获得有效的代码覆盖?

解决方法

Perl不存储它使用的文件的完整路径.如果它通过相对路径找到文件,则仅存储相对路径.您可以在perl中显示的路径中显示警告,并在这些文件中显示错误消息.

当Devel :: Cover处理文件时,它使用perl给出的路径.你可以在Devel :: Cover的报告中看到这个,你有testPLCoverage.pl和blib / lib / testPMCoverage.pm.

在实践中,这对您来说意味着无论何时将覆盖范围放入coverage数据库,都应该确保从同一目录中进行覆盖,以便Devel :: Cover可以匹配并定位coverage数据库中的文件.

我认为这是你遇到的问题.

我的建议是在t / doPLtest.sh中你不要进入lib.你可以运行类似的东西:

perl -Mblib -MDevel :: Cover = -db,.. / cover_db lib / testPLCoverage.pl

(顺便说一下,为什么lib中的文件?)

我认为这意味着Devel :: Cover将在每种情况下从项目根运行,因此应该允许它匹配并找到文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读