A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label test coverage. Show all posts
Showing posts with label test coverage. Show all posts

Devel::Cover patterns for Perl

One:
cover -delete PERL5OPT=-MDevel::Cover=-ignore,^local/ prove -r t cover -report html_basic

Another:
perl -MDevel::Cover=+ignore,.*,-select,^lib/,-select,^t/,-silent,on t/path/to/test.t cover

Or:

for file in `find t -name '*.t`; do perl -MDevel::Cover=+ignore,.*,-select,^lib/,-select,^t/,-silent,on $file; done

In full:

unset PERL5LIB; unset PERL_LOCAL_LIB_ROOT; eval $(perl -Mlocal::lib=./local)

export PERL5LIB="/home/will/alt/cpan/devel-cover/local/lib/perl5:$PERL5LIB"

PERL5OPT=-MDevel::Cover=-ignore,^local/ prove -I t/lib -lr t

perl -I /home/will/alt/cpan/devel-cover/local/lib/perl5 /home/will/alt/cpan/devel-cover/local/bin/cover

Perl test coverage

Select files to cover and run the tests, capturing coverage data:
perl -MDevel::Cover=,+ignore,.*,-select,^lib t/path/to/test.t

Meaning:
  • ignore all paths...
  • except ones starting with "lib"

After it's run, at the command prompt, type this to generate the HTML report:
cover

And then open this file in your web browser:
cover_db/coverage.html

(docs)

Perl testing/profiling

  • Devel::DProf - subroutine profiler
  • Devel::NYTProf - the best one, apparently
  • Devel::SmallProf - line-by-line profiler
  • Devel::Cover - Test coverage
  • HTML::Mason::Plugin - manual method for Mason components

Test Coverage Vim Mappings

From the vi text editor, see which tests cover the file you're working on, or which modules are covered by the test you're in.

Features on the way: Being able to know which tests cover a particular line of a file!

http://search.cpan.org/dist/Devel-CoverX-Covered/lib/Devel/CoverX/Covered.pm