Planless testing in Perl 6
In #perl6, our eyes were caught by a post on Matt Trout’s blog concerning the problems which arise from the traditional Perl way of test modules which require you to state at the start of your test file how many tests you’ll be running. I’m not going to repeat his arguments because they’re good ones. It didn’t take a great deal for people to agree that we should have a planless testing module for Rakudo.
Rakudo already ships with a fairly basic Test.pm which already had some support for planless testing, although you still had to explicitly tell it that’s what you wanted:
plan *;
Whereas we’d rather like it if you could just leave out the call to plan when you weren’t planning (hah!) to use a plan. We also decided to use the done_testing idea, so that you call this in planless mode after your tests are complete to mark explicitly that you’ve run as many as you wanted to.
I was able to put together a new version of Test.pm which contains all these enhancements for planless testing, while at the same time operating transparently in planned mode for all the test modules already out there. I for one didn’t want to go through the Perl 6 spectest suite and change all those…
The patch is submitted to RT, so hopefully it will land in Rakudo before too long (assuming nobody finds any screaming bugs in it). Then your test modules can look like this:
use Test; use MyModule; ok(MyModule::do-something(), "Doing something"); done_testing;