How to use Devel :: Cover with proof?

I see that there are several similar questions and http://www.perlmonks.org , but I still do not understand. Imagine that I have a project with the directories "lib /" and "t". I run my tests using "prove":

$ cd $PROJECT_ROOT $ prove ./*.t 

I want to get a report in html for one or more files in the lib / directory. I do not need reports for files in the "t" directory. A simple example should be enough. Thanks

+8
perl
source share
2 answers
+6
source share

The right way is to always start with Makefile.PL/Build.PL, just as the selected answer suggests. However, sometimes you are not the one who started, so ...

I used a fake make file:

  % cat Makefile test: prove -Ilib -rt 

Also, the following seems to work (without touching ANY files on the disk):

 cover -t -make 'prove -Ilib -rt; exit $?' 

This only works because of how Perl system / exec handle the argument with metacharacters in it ( ; in this case) and may break in the future if cover decides to quote it more rigirously. Also, it should not work under windows. I wish there was a -prove option on cover .

This object still provides coverage for * .t, as well as CPAN modules in non-standard locations. This behavior can be fixed using the + select / + ignore options (see the Devel :: Cover man page):

 cover -t +select ^lib +ignore ^ 

So the tl command; dr "magic"

 cover -t +select ^lib +ignore ^ -make 'prove -Ilib -rt; exit $?' 

EDIT didn't work for me - it prints only a short summary:

  PERL5OPT="$PERL5OPT -MDevel::Cover" prove -Ilib -rt cover -t +select ^lib +ignore ^ 

Note that prove -MSomething that prove -MSomething is used by Something to prove itself and not pass it (unlike -I).

+5
source share

All Articles