Wednesday, August 31, 2011

Kwalitee is Job #1

I've been working on a presentation on unit testing for an upcoming Catalyst Developer's Meetup, and on some real-world unit tests for a REST interface. Eventually, I plan to post the whole presentation on slideshare, but there are a couple things worth mentioning here first.

I was flailing around on the 'net the other day, looking for some ideas on better approaches to model testing, when I ran across something unusual - a technical book worth the asking price -  Perl Testing: A Developer's Notebook.
It's a nice how-to kind of book, and well organized, so it would be great for someone new to the subject. But it also contains a few nuggets that I hadn't stumbled on elsewhere yet.

Here's one of those nuggets: Kwalitee

Open-source software is great. I've been using it for a long time. But the quality varies greatly. Sometimes, even when the software itself is great, the packaging really sucks. Installers are missing, broken, or just not intuitive. Ditto for documentation.

Perl packages from CPAN however, are generally packaged up pretty well. This implies nothing about the quality or usefulness of the software itself, but aside from the occasional broken dependency chain, getting software installed from CPAN is relatively uniform and painless, and there's at least some documentation.

This is apparently due, at least in part to CPANTS, the CPAN Testing Service, and its definition of Kwalitee, a series of metrics that check packages for the existence of things like tests and documentation (and many more - read the docs).

Thanks to Test::Kwalitee, it's easy to add those checks to your perl packages. Simply add this test to your t directory:

use Test::More;
eval { require Test::Kwalitee; Test::Kwalitee->import() };
plan( skip_all => 'Test::Kwalitee not installed; skipping' ) if $@;

Run the test:

prove --lib --verbose t/kwalitee.t
t/kwalitee.t ..
1..13
ok 1 - extractable
ok 2 - has_readme
ok 3 - has_manifest
ok 4 - has_meta_yml
ok 5 - has_buildtool
ok 6 - has_changelog
ok 7 - no_symlinks
ok 8 - has_tests
ok 9 - proper_libs
ok 10 - no_pod_errors
ok 11 - use_strict
ok 12 - has_test_pod
ok 13 - has_test_pod_coverage
ok
All tests successful.
Files=1, Tests=13, 1 wallclock secs ( 0.03 usr 0.00 sys + 0.53 cusr 0.04 csys = 0.60 CPU)
Result: PASS

Address any issues found, and you too have achieved Kwalitee.

No comments:

Post a Comment