This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Test-Simple to alpha 076
[perl5.git] / cpan / Test-Simple / lib / Test / More / Tools.pm
index 7357f35..98027cc 100644 (file)
@@ -334,6 +334,8 @@ sub subtest {
     $ctx->clear;
     my $todo = $ctx->hide_todo;
 
+    my $pid = $$;
+
     my ($succ, $err) = try {
         {
             no warnings 'once';
@@ -352,6 +354,19 @@ sub subtest {
         }
     };
 
+    if ($$ != $pid && !$ctx->stream->_use_fork) {
+        warn <<"        EOT";
+Subtest finished with a new PID ($$ vs $pid) while forking support was turned off!
+This is almost certainly not what you wanted. Did you fork and forget to exit?
+        EOT
+
+        # Did the forked process try to exit via die?
+        die $err unless $succ;
+    }
+
+    # If a subtest forked, then threw an exception, we need to propogate that right away.
+    die $err unless $succ || $$ == $pid || $err->isa('Test::Stream::Event');
+
     $ctx->set;
     $ctx->restore_todo($todo);
     # This sends the subtest event