Subject: | Test::Class doesn't detect early exit from tests |
Sometimes the code you're testing might have embedded somewhere deep within it a call to exit (or, a call to die, and a $SIG{__DIE__} handler that causes it to exit gracefully.)
With Test::More, this will be caught as long as you define a plan or use done_testing:
$ cat test2.pl
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
ok(1);
exit;
ok(2);
done_testing;
$ perl test2.pl
ok 1
# Tests were run but no plan was declared and done_testing() was not seen.
However, with Test::Class, even if you define a plan in your subtests, an early exit can cause the rest of them to run and it seems like everything is okay:
$ cat test.pl
#!/usr/bin/perl
use strict;
use warnings;
package My::Tests;
use base qw(Test::Class);
use Test::More;
sub t01_the_test : Tests(3) {
my ($self) = @_;
ok(1);
exit;
}
sub t02_more_tests : Tests {
ok(1);
}
My::Tests->runtests;
$ perl test.pl
ok 1 - t01 the test
1..1
I think early exits should be caught - at least in the case where a plan is specified, but realistically in both if possible. (I'd like to pretend there's an explicit done_testing at the end of every subtest that doesn't have a plan defined.)
-- Matthew Horsfall (alh)