Pretty test results, pretty Petals.

osfameron on 2006-02-18T11:42:31

I knocked together some shiny testing results thinking it might help evangelise Test driven development - what do you know, it seems to work! I was surprised to discover that the "developers" list includes the senior Project Manager, when he responded to my announcement of a test page by bounding over enthusiastically to say how great it was seeing all those green boxes.

The helpful chaps on #london.pm had pointed me in the direction of Test::TAP::HTMLMatrix, originally developed for Pugs by the lambdacamels. It uses Test::TAP::Model, a module that reads "TAP" compliant testing output (i.e. what Perl testing modules do anyway) and turns it into something that not only humans, but also machines can read.

The HTML Matrix is lovely, but uses Petal... "Yet Another Templating Language" I groaned, and was only mollified when the installation via CPAN.pm as non-root actually worked (C-code and all!). (Actually HTMLMatrix itself didn't install because of the syntax my __PACKAGE__ $self = shift; which I didn't realize was even valid yet (and more importantly, the version of Perl on dev box doesn't either... Anyway, should be patched, because a) this is a utility module, useful for everyone, even people on older perls, who maybe need to evangelise testing the most (so they can convince all($boss, @sysadmins) that the code will still work on an upgrade), and b) it really doesn't need to use bleeding edge code just 'coz it's trendy, the code works jus'wunnerful without it (though I haven't checked if any tests fail as a result - I'm editing in my own sandbox and still need to set up a working practise for submitting patches to vendor modules - any pointers?).

I wanted to edit the template and looked at the Petal source, first of all recoiling in horror at the fact that it uses XML-like tags (having recently developed an allergy to HTML::Template). But then I decided to refactor to allow pluggable templating engines (on the basis that if I ever get this installed as a non-skunkworks project, they'd probably rather I use the aforementioned so-called templating module as it's the in-house standard).

The first step after separating out Test::TAP::HtmlMatrix::Petal was to implement Test::TAP::HtmlMatrix::TT and convert the template. At which point I had to look more at the TAL syntax. Actually it seems rather sane: it uses XHTML so it can process it very efficiently, and in many cases the resulting source is much more compact and elegant than the TT version, which doesn't know anything about XML.

The only disadvantage for me (apart from the recent doubts about whether it's even worth serving XHTML at all until browsers catch up) is that I actually like the way the [% %] tags stand out against HTML code.

Plugging Test::TAP::Model into TT doesn't quite work unfortunately - when TT processes [% foo.bar %] it's actually implicitly doing [% (stash).foo.bar %], so for each dot operation it checks to see whether the left operand is the root (stash). Unfortunately it does this using eq, and T::TAP::HTMLM is an overloaded package (it stringifies to its HTML representation) but doesn't overload eq. I'm surprised this hasn't come up before (that or my minicpan is very out of date), but patched my copy of TT::Stash to eq the ref's instead of the objects. Again, this seems to work, but as I haven't run test suites for either module, who knows... the alternative would be, I guess, to patch T::TAP::HTMLM to overload eq.