Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create fail_if_returned_late, behavior is similar to fail_if_returned_early #23

Merged
merged 1 commit into from Apr 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 26 additions & 1 deletion lib/Test/Class.pm
Expand Up @@ -298,7 +298,11 @@ sub _run_method {
if $exception;
} elsif ($num_done > $num_expected) {
my $class = ref $self;
$Builder->diag("expected $num_expected test(s) in $class\::$method, $num_done completed\n");
if ($self->fail_if_returned_late) {
$Builder->ok(0, "($class\::$method returned before plan complete)");
jgoodman marked this conversation as resolved.
Show resolved Hide resolved
} else {
$Builder->diag("expected $num_expected test(s) in $class\::$method, $num_done completed\n");
}
} else {
until (($Builder->current_test - $num_start) >= $num_expected) {
if ($exception) {
Expand All @@ -319,6 +323,7 @@ sub _run_method {
}

sub fail_if_returned_early { 0 }
sub fail_if_returned_late { 0 }

sub _show_header {
my ($self, @tests) = @_;
Expand Down Expand Up @@ -939,6 +944,22 @@ However, if the class's C<fail_if_returned_early> method returns true, then the
}


=head1 RETURNING LATE

If a test method runs too many tests, by default the test plan succeeds.

However, if the class's C<fail_if_returned_late> method returns true, then the extra tests will trigger a failure. For example,

package MyClass;
use base 'Test::Class';
sub fail_if_returned_late { 1 }

sub oops : Tests(1) {
ok 1, "just a simple test";
ok 1, "just a simple test"; #oops I copied and pasted too many tests
}


=head1 SKIPPED TESTS

You can skip the rest of the tests in a method by returning from the method before all the test have finished running (but see L<"Returning Early"> for how to change this). The value returned is used as the reason for the tests being skipped.
Expand Down Expand Up @@ -1567,6 +1588,10 @@ See the section on the L</"GENERAL FILTERING OF TESTS"> for more information.

Controls what happens if a method returns before it has run all of its tests. It is called with no arguments in boolean context; if it returns true, then the missing tests fail, otherwise, they skip. See L<"Returning Early"> and L<"Skipped Tests">.

=item B<fail_if_returned_late>

Controls what happens if a method returns after running too many tests. It is called with no arguments in boolean context; if it returns true, then the extra tests trigger a failure test. See L<"Returning Late"> and L<"Skipped Tests">.


=back

Expand Down