David Jack Wange Olrik

Tea. Earl Grey. Hot.

Testing With "Latest"

Perl

A few months ago I gave a small talk at the Nordic Perl Workshop 2013, about a clever way of combining cpanm and local::lib to test your CPAN modules with the latest version of its dependencies.

I have a few perl modules on CPAN, which is mostly feature complete, and as such doesn’t need regular attention and updates, but the world around them changes all the time so continuous testing is still needed.

Pick your favorite Continuous Integration1 server and add this small script:

cpanm --local-lib=~/perl5 local::lib # Install local::lib
cpanm --local-lib=~/perl5 -q --showdeps . \ # Get list of depencencies
| perl -F~ -lanE 'say $F[0]' \ # Only use module name
| grep -v '^perl$' \ # Don't install perl
| cpanm --local-lib=~/perl5 # Install the dependencies
perl -Mlocal::lib=~/perl5 Build.PL # Create Build file
./Build test --verbose=1 # Run tests

This script will only test with installed perl, if you wish to test your code on multiple perl versions2, then I suggest you use plenv and then select the proper perl binary with plenv local <version> before installing the dependencies.

plenv local 5.18.2 # Select perl for testing
cpanm --local-lib=~/perl5.18.2 local::lib # Install local::lib
cpanm --local-lib=~/perl5.18.2 -q --showdeps . \ # Get list of depencencies
| perl -F~ -lanE 'say $F[0]' \ # Only use module name
| grep -v '^perl$' \ # Don't install perl
| cpanm --local-lib=~/perl5.18.2 # Install the dependencies
perl --local-lib=~/perl5.18.2 Build.PL # Create Build file
./Build test --verbose=1 # Run tests

You can skip the use of local::lib but using it lets you keep your “test” perls clean so you can use them to test all your CPAN modules in a known environment.

Happy testing!

  1. I picked GitLab CI as it is a lot more light weight than most of the other offerings out there.

  2. …and believe me you definitely want to test with at least the current and the previous stable version!

Comments