Dist::Zilla Do Kwallitee Test

Playing with tests in the Dist-Pen today.

On part of Dist::Zilla that I do find intriguing is the way it does its testing. As I discovered in my last post some things only work at release time and that is true of testing as well. Dist:Zilla take the newer extended testing model as a default. In the old days we would call these optional tests and usually hide them in a folder someplace, but the more common usage today is to put them in an '\xt' directory on their own.

One can see the logic behind this as I remember a few times having to do a force install of a CPAN mod as the author had some sort of non-functional test in '\t' that would not pass on my perl.

Dist::Zilla this concept a little further and splits it into four types;

  1. release
  2. automated
  3. extended
  4. author

and of course the regular tests you would find in your '/t'. So how does one use these new testing tools? Well like allot of Dist::Zilla plug-ins the documentation is rather sparse and disjointed, it is all there though. I did have to a little blundering about to find everything I needed and in the end I have managed to put a few things together that work.

So the first thing to do is decide what you want these extened tests to do. Taking the simplest path I am going to try and add 'Dist::Zilla::Plugin::Test::Kwalitee' test to my '.ini'. This plug-in will do a 'release' test using a favorite of mine Test::Kwalitee. This is also a good example test.pm that some like, and others loath, as a fail this test at 175.89% does not mean the module will not work, just that the CPAN author is lazy or it is an old module. So a good candidate for something that does not go in my '/t' dir but I as the Author would like to run.

First I add in the plug-in to my '.ini' file



[Readme::Brief]
installer = mb
installer = eumm
[Git::Check]
++[Test::Kwalitee]

Now the above will not do anything as I still need to add in a 'kwalitee.t' test case. A default one like this


use Test::More;
use strict;
use warnings;
BEGIN {
plan skip_all => 'these tests are for release candidate testing'
unless $ENV{RELEASE_TESTING};
}

use Test::Kwalitee 'kwalitee_ok';
kwalitee_ok();
done_testing;


should do nicely. This I add into the /xt/release' dir and I should be able to give it my first try. At this point if I was to attempt to run 'dzil build' or 'dzil tst' I would get a error like this

attempt to add xt/release/kwalitee.t multiple times; added by: filename set by GatherDir (Dist::Zilla::Plugin::GatherDir line 225); encoded_content added by GatherDir (Dist::Zilla::Plugin::GatherDir line 226); content added by Test::Kwalitee (Dist::Zilla::Plugin::Test::Kwalitee line 91)
aborting; duplicate files would be produced at /usr/local/share/perl/5.18.2/Dist/Zilla/App/Command/build.pm line 107.

as both the Test::Kwalitee plug-in and the 'GatherDir' plug-in are trying to play with the same file so I have to make this change to my '.ini' as well before I build or test;

...
[GatherDir]
++exclude_filename=xt/release/kwalitee.t
...

to tell GatherDir to skip the test. At this point my 'dizl build' will work and if I was to 'dizl test' all my tests in '/t' would run but not that new 'kwalitee.t' one as that is a release test. One can get around that by installing Dist::Zilla::App::Command::xtest and then doing this

dzil xtest

and I get

Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Database::Accessor
Writing MYMETA.yml and MYMETA.json
cp lib/Database/Accessor/Types.pm blib/lib/Database/Accessor/Types.pm
cp README.pod blib/lib/Database/README.pod
cp lib/Database/Accessor/Constants.pm blib/lib/Database/Accessor/Constants.pm
cp lib/Database/Accessor.pm blib/lib/Database/Accessor.pm
Created MYMETA.yml and MYMETA.json
Creating new 'Build' script for 'Database-Accessor' version '0.01'
Building Database-Accessor
xt/release/kwalitee.t .. ok
All tests successful.
Files=1, Tests=17, 2 wallclock secs ( 0.06 usr 0.01 sys + 1.61 cusr 0.08 csys = 1.76 CPU)
Result: PASS
all's well; removing .build/xSjKzPWjFL

There I passed the basic Kwallitee test case.


gz2.jpg


Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations