cpan/Test-Simple/t/Legacy/fail_one.t Test::Simple Test
cpan/Test-Simple/t/Legacy/fail.t Test::Simple Test
cpan/Test-Simple/t/Legacy/filehandles.t Test::Simple Test
+cpan/Test-Simple/t/Legacy/fork_die.t Test::Simple Test
cpan/Test-Simple/t/Legacy/fork_in_subtest.t Test::Simple Test
cpan/Test-Simple/t/Legacy/fork.t Test::Simple Test
cpan/Test-Simple/t/Legacy/harness_active.t Test::Simple Test
use strict;
use warnings;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
require Exporter;
our @ISA = qw(Exporter);
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
package Test::Builder::Tester;
use strict;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
use Test::Stream 1.301001 '-internal';
package Test::Builder::Tester::Color;
use strict;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
use Test::Stream 1.301001 '-internal';
use strict;
use warnings;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
use Test::Stream 1.301001 '-internal';
$ctx->clear;
my $todo = $ctx->hide_todo;
+ my $pid = $$;
+
my ($succ, $err) = try {
{
no warnings 'once';
}
};
+ 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
use strict;
use warnings;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
-use Test::Stream 1.301001_075 '-internal';
+use Test::Stream 1.301001_076 '-internal';
use Test::Stream::Toolset;
use Test::Stream::Exporter;
use strict;
use warnings;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
use Test::Stream::Context qw/context/;
my $level = 2 + $add + $tb;
my ($package, $file, $line, $subname) = caller($level);
- return unless $package;
-
- while ($package eq 'Test::Builder') {
- ($package, $file, $line, $subname) = caller(++$level);
+ if ($package) {
+ while ($package eq 'Test::Builder') {
+ ($package, $file, $line, $subname) = caller(++$level);
+ }
+ }
+ else {
+ while (!$package) {
+ ($package, $file, $line, $subname) = caller(--$level);
+ }
}
return unless $package;
}
sub _autoflush {
- my($fh) = shift;
+ my($fh) = pop;
my $old_fh = select $fh;
$| = 1;
select $old_fh;
use vars qw( @ISA @EXPORT $VERSION );
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
@EXPORT = qw( run_tests check_tests check_test cmp_results show_space );
use warnings;
use 5.005;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
use Test::Stream 1.301001 '-internal';
use Test::More 1.301001 ();
use Test::Stream::Carp qw/croak/;
-our $VERSION = '1.301001_075';
+our $VERSION = '1.301001_076';
$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
sub import {
--- /dev/null
+use strict;
+use warnings;
+
+use Config;
+
+BEGIN {
+ my $Can_Fork = $Config{d_fork} ||
+ (($^O eq 'MSWin32' || $^O eq 'NetWare') and
+ $Config{useithreads} and
+ $Config{ccflags} =~ /-DPERL_IMPLICIT_SYS/
+ );
+
+ if( !$Can_Fork ) {
+ require Test::More;
+ Test::More::plan(skip_all => "This system cannot fork");
+ exit 0;
+ }
+ elsif ($^O eq 'MSWin32' && $] == 5.010000) {
+ require Test::More;
+ Test::More::plan('skip_all' => "5.10 has fork/threading issues that break fork on win32");
+ exit 0;
+ }
+}
+
+# The failure case for this test is producing 2 results, 1 pass and 1 fail,
+# both with the same test number. If this test file does anything other than 1
+# (non-indented) result that passes, it has failed in one way or another.
+use Test::More tests => 1;
+use Test::Stream qw/context/;
+
+my $line;
+
+subtest do_it => sub {
+ ok(1, "Pass!");
+
+ my ($read, $write);
+ pipe($read, $write) || die "Could not open pipe";
+
+ my $pid = fork();
+ die "Forking failed!" unless defined $pid;
+
+ unless($pid) {
+ close($read);
+ Test::Stream::IOSets->_autoflush($write);
+ my $ctx = context();
+ my $handles = $ctx->stream->io_sets->init_encoding('legacy');
+ $handles->[0] = $write;
+ $handles->[1] = $write;
+ $handles->[2] = $write;
+ *STDERR = $write;
+ *STDOUT = $write;
+
+ die "This process did something wrong!"; BEGIN { $line = __LINE__ };
+ }
+ close($write);
+
+ waitpid($pid, 0);
+ ok($?, "Process exited with failure");
+
+ {
+ local $SIG{ALRM} = sub { die "Read Timeout\n" };
+ alarm 2;
+ my @output = map {chomp($_); $_} <$read>;
+ alarm 0;
+ is_deeply(
+ \@output,
+ [
+ "Subtest finished with a new PID ($pid vs $$) while forking support was turned off!",
+ 'This is almost certainly not what you wanted. Did you fork and forget to exit?',
+ "This process did something wrong! at t/Legacy/fork_die.t line $line.",
+ ],
+ "Got warning and exception, nothing else"
+ );
+ }
+
+ ok(1, "Pass After!");
+};
+
+done_testing;