January PR Challenge: Clone: adding continuous integration and badges

zaki
Sun, 25 Jan 2015 04:36:09 +0000
perl

When I saw the CPAN PR Challenge come up in my feed, I signed up immediately. I love giving back to FOSS and this challenge would push me to make contributions that are outside of the usual software that I contribute to.

For January, I was assigned Clone. I looked at the reverse dependencies and saw 181 packages. I immediately thought to myself, "I'd better be careful. I don't want to break things.". This means that testing is very important for this package.

I e-mailed the maintainer of Clone, Breno G. de Oliveira (garu), about my assignment and he shot me back an lengthy e-mail with all the things I could do. Some of them were easy, such as:

fix typos,

add continuous integration with Travis-CI, code coverage with Coveralls, and adding badges for each of those.

Others were a bit more involved:

benchmarking against other packages such as Clone::PP and Storable,

adding more tests for different types of Perl variables,

go through the bug queue and fixing the open tickets.

I went for the easy ones first. I knew that adding the Travis-CI integration was just a matter of creating a .travis.yml file, but what actually goes in that file can vary quite a deal. I had noticed that haarg had created a set of helper scripts that can grab various pre-built Perl versions and run tests against them all.

I cloned the Clone repository and copied over the example .travis.yml:

language: perl
perl:
  - "5.8"                     # normal preinstalled perl
  - "5.8.4"                   # installs perl 5.8.4
  - "5.8.4-thr"               # installs perl 5.8.4 with threading
  - "5.20"                    # installs latest perl 5.20 (if not already available)
  - "blead"                   # install perl from git
matrix:
  include:
    - perl: 5.18
      env: COVERAGE=1         # enables coverage+coveralls reporting
  allow_failures:
    - perl: "blead"           # ignore failures for blead perl
before_install:
  - git clone git://github.com/travis-perl/helpers ~/travis-perl-helpers
  - source ~/travis-perl-helpers/init
  - build-perl
  - perl -V
  - build-dist
  - cd $BUILD_DIR             # $BUILD_DIR is set by the build-dist command
install:
  - cpan-install --deps       # installs prereqs, including recommends
  - cpan-install --coverage   # installs converage prereqs, if enabled
before_script:
  - coverage-setup
script:
  - prove -l -j$((SYSTEM_CORES + 1)) $(test-dirs)   # parallel testing
after_success:
  - coverage-report

and enabled my fork of Clone in the Travis-CI and Coveralls settings.

After pushing this, the tests ran, but I kept seeing n/a code coverage on Coveralls. I was very confused because the code coverage was working just fine locally. I jumped on IRC and chatted with haarg. He pointed out that I was using prove -l as in the example, but since Clone is a compiled module, I needed to use prove -b.

Oh. Silly me! I had been using prove -b locally, but never changed the .travis.yml file. That serves me right for copying-and-pasting without looking! Something good came out of it though: this ticket for Test::Harness has suggestions that will help catch this error if anyone else makes the same mistake.

haarg also pointed me to an even simpler .travis.yml file that he was working on that just had the lines

before_install:
  - eval $(curl https://travis-perl.github.io/init) --auto

and a list of the Perl versions to test. I used that and ran it through Travis-CI and everything just worked!

Now all I had to do was grab the HTML for the badges and put them in the POD and Markdown. I went to the Travis-CI and Coveralls pages and copied the Markdown for those badges and then went to http://badge.fury.io/for/pl and entered in Clone to get a version badge for Clone on CPAN.

I then made a few grammar fixes and converted the POD into Markdown for the README and I was done!

The pull request with my changes is at https://github.com/garu/Clone/pull/4 and my changes are in Clone v0.38.