Howto: XS Coverage Reports on coveralls.io
The excellent Travis Perl helpers make it easy submit automated coverage reports to Coveralls whenever you commit to GitHub. All that's needed is to set the COVERAGE environment variable.
Unfortunately, this doesn't include the XS portions of a module. But since Devel::Cover already supports XS modules out of the box, only a slight change is needed to make it work. Simply make the Travis Perl helpers compile and link your XS code with the GCC --coverage option. (You often see the equivalent -fprofile-arcs -ftest-coverage used instead, but GCC supports --coverage since version 4.1.0.)
Here's a quick fix that enables XS coverage reports for EU:MM based modules.
Coverage reports for XS code often contain unwanted header files in Perl's CORE directory that you might want to ignore. This commit passes options from the COVERAGE_OPTS environment variable to the cover tool. For example, you could set the variable like this:
COVERAGE_OPTS='-ignore_re /CORE/\w+\.h$'
These patches currently live in my fork of the Travis Perl helpers. See the .travis.yml of my CommonMark module for how to load them. Here's what a coverage report looks like. I hope to get these patches integrated into the official version of the helpers.
For XS modules based on Module::Build, the GCC coverage options should probably be added via --extra-compiler-flags and --extra-linker-flags when the Build script is run. If anyone has such a module, it would be great if they could test whether this works.
Leave a comment