http://qs321.pair.com?node_id=11107005

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

Hello monks.
I'm trying to use MDevel::Cover. I have a few questions about it.
I succeeded to create a coverage report but it contains coverage of used modules like Data or Getopt.
How can I set the exactly dependences I want the coverages to contain?
For example, I ran my code and got coverage that contains main.pl, sub1.pm, sub2.pm, Data.pm and Getopt.pm.
I want to see only main.pl, sub1.pm, sub2.pm. Is it possible to achieve it?
Also, is it possible to somehow "merge" two coverage results (I'm not sure myself what it means but maybe there is a somewhat concept)?
Thank you all

Edit: I run my script with coverage: (with GetOpt options)
/usr/5.26.1/bin/perl -MDevel::Cover main.pl --list 1,2 --values 58

Replies are listed 'Best First'.
Re: Coverage report
by rjt (Curate) on Oct 03, 2019 at 13:25 UTC

    I assume you mean Devel::Cover. If you haven't already, that documentation is really good, and covers some of your questions.

    If you're getting unwanted files in your output, you can use -ignore or +ignore with a regexp. But you normally shouldn't be seeing those included modules. What does your directory structure look like, and how exactly are you invoking cover?

    I use Devel::Cover in my distributions. In that case, I simply run cover -test in the root of my distribution, which runs make test and reports the coverage, and won't report coverage of other external modules. Here's what the output looks like for me:

    pts/6 ryan@pi:~/src/Text-Trim $> cover -test Deleting database /home/ryan/src/Text-Trim/cover_db cover: running make test "OPTIMIZE=-O0 -fprofile-arcs -ftest-coverage" + "OTHERLDFLAGS=-fprofile-arcs -ftest-coverage" PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::H +arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l +ib', 'blib/arch')" t/*.t t/00..load.t ..... 1/? # Testing Text::Trim 1.03, Perl 5.026001, /usr/ +bin/perl t/00..load.t ..... ok t/01..trim.t ..... ok t/02..ltrim.t .... ok t/03..rtrim.t .... ok t/04..unicode.t .. ok t/05..undef.t .... ok t/99..pod.t ...... ok All tests successful. Files=7, Tests=64, 2 wallclock secs ( 0.02 usr 0.00 sys + 1.91 cusr + 0.09 csys = 2.02 CPU) Result: PASS Reading database from /home/ryan/src/Text-Trim/cover_db --------------------- ------ ------ ------ ------ ------ ------ ------ File stmt bran cond sub pod time total --------------------- ------ ------ ------ ------ ------ ------ ------ blib/lib/Text/Trim.pm 100.0 100.0 100.0 100.0 100.0 100.0 100.0 Total 100.0 100.0 100.0 100.0 100.0 100.0 100.0 --------------------- ------ ------ ------ ------ ------ ------ ------ HTML output written to /home/ryan/src/Text-Trim/cover_db/coverage.html done.

    I am not exactly sure what you mean by "merging", but if you can get all of your source code into the same distribution, you can have one report cover the whole thing. If that is not desirable or feasible, then I'm not sure what to suggest, aside from a simple concatenation or pagination of the results.

    use strict; use warnings; omitted for brevity.
      Thank you for your reply. I'll try the ignore flag.
      About the merge part, I'll try to explain myself better.
      I have a tool which runs multi unitest.
      Each one of them creats a coverage report.
      I want somehow to "merge" those reports into one main report.
      I feel like it is a bit novice question, but I'm not sure that I fully understand the coverge idea.
      How can I "merge those reports into one main report so It will look like I ran one unitest and got the report?

        Devel::Cover accumulates all of its results in one database. I use PERL5OPT=-MDevel::Cover prove -l for development tests on a pure-Perl distribution I am writing, followed by simply cover to get the unified report.

Re: Coverage report
by pryrt (Abbot) on Oct 03, 2019 at 13:18 UTC

    Have you followed the Selecting Files to Cover section of the docs? I'm actually surprised that Data and Getopot are being included in the coverage, because they would normally be in the @INC array, which the docs say should prevent the modules from showing coverage.

    Could you show us the sequence you use to run the coverage? And show us perl -V (capital V for the option), to show the @INC you've got?