Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Test case without done_testing exits with 0. #341

Merged
merged 1 commit into from

3 participants

@tokuhirom

If Have_Plan is false, test script exit with status code 0. It's not expected behaviour i think.

@tokuhirom tokuhirom Test case without done_testing exits with 0.
Failed test script should be return non-zero value.
a5dcee0
@schwern
Owner

Good catch, every failing test should be non-zero. I'll have a closer look at it later, but looks good at a glance.

One question, why'd you pick 254? The specific exit codes don't matter too much any more, just curious.

@tokuhirom

I don't any reason to use 254. There is no code for specific exit code. And one of the reason is 254 is not 255 :panda_face:

@schwern schwern merged commit 8235f3e into Test-More:master
@karenetheridge
Collaborator

This is awesome, BTW. And - bonus! - it doesn't break my tests that fork, although I expected it to -- after digging through the code I discovered that the 'if not have a plan, exit with error' logic doesn't apply if the exiting process doesn't match the one that Test::Builder was constructed under.

@schwern
Owner

Great to hear! Not doing end-of-test actions in a child process has been in since 0.47, I'm glad it continues to just work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 7, 2012
  1. @tokuhirom

    Test case without done_testing exits with 0.

    tokuhirom authored
    Failed test script should be return non-zero value.
This page is out of date. Refresh to see the latest.
View
20 lib/Test/Builder.pm
@@ -2456,6 +2456,26 @@ sub _ending {
if( !$self->{Have_Plan} and $self->{Curr_Test} ) {
$self->is_passing(0);
$self->diag("Tests were run but no plan was declared and done_testing() was not seen.");
+
+ if($real_exit_code) {
+ $self->diag(<<"FAIL");
+Looks like your test exited with $real_exit_code just after $self->{Curr_Test}.
+FAIL
+ $self->is_passing(0);
+ _my_exit($real_exit_code) && return;
+ }
+
+ # But if the tests ran, handle exit code.
+ my $test_results = $self->{Test_Results};
+ if(@$test_results) {
+ my $num_failed = grep !$_->{'ok'}, @{$test_results}[ 0 .. $self->{Curr_Test} - 1 ];
+ if ($num_failed > 0) {
+
+ my $exit_code = $num_failed <= 254 ? $num_failed : 254;
+ _my_exit($exit_code) && return;
+ }
+ }
+ _my_exit(254) && return;
}
# Exit if plan() was never called. This is so "require Test::Simple"
View
2  t/exit.t
@@ -87,6 +87,8 @@ my %Tests = (
'require.plx' => 0,
'death_with_handler.plx' => 255,
'exit.plx' => 1,
+ 'one_fail_without_plan.plx' => 1,
+ 'missing_done_testing.plx' => 254,
);
chdir 't';
View
8 t/lib/Test/Simple/sample_tests/missing_done_testing.plx
@@ -0,0 +1,8 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import();
+ok(1);
View
8 t/lib/Test/Simple/sample_tests/one_fail_without_plan.plx
@@ -0,0 +1,8 @@
+require Test::Simple;
+
+push @INC, 't/lib';
+require Test::Simple::Catch;
+my($out, $err) = Test::Simple::Catch::caught();
+
+Test::Simple->import();
+ok(0);
Something went wrong with that request. Please try again.