Implicit "done_testing()" in subtests

Ovid on 2009-11-13T17:21:03

Per a previous blog entry, I've submitted a pull request on github to implement an implicit done_testing() on subtests with no plan. This is due to the following:

subtest 'trim' => sub {
    plan tests => 2;
    # snip
};

subtest 'escape' => sub {
    plan tests => 2;
    # snip
};

subtest 'interior sequences' => sub {
    plan tests => 6;
    # snip
};

It was getting awfully annoying having to maintain plans for all of the subtests when I could clearly distinguish when a subtest was finished. If the pull request is accepted, you can just do this:

subtest 'some subtest' => sub {
    isa_ok my $cust = Customer->new({ 
      given  => 'John', 
      family => 'Public' }
    ), 'Customer';
    can_ok $cust, 'given';
    is $cust->given, 'John',

    can_ok $cust, 'family';
    is $cust->family, 'Public';
};

done_testing() will be implicitly called at the end of that (and you can list it explicitly, if you want). This allows you to safely add extra tests to all subtests without worrying about the plan, nor do you have to worry about annoying plan management unless it's really important.