Skip to content

Instantly share code, notes, and snippets.

@schwern
Created November 29, 2011 07:12
Show Gist options
  • Save schwern/1403823 to your computer and use it in GitHub Desktop.
Save schwern/1403823 to your computer and use it in GitHub Desktop.
fork.t
use strict;
use warnings;
use Test::More tests => 4;
pass("Before fork");
my $tb = Test::More->builder;
my $pid = fork;
if( ! defined $pid ) { # failed
die "fork() failed: $!";
}
elsif( $pid ) { # parent
pass("Parent");
}
else { # child
sleep 1;
# Increment the counter to take into account what was
# run by the parent.
$tb->current_test($tb->current_test + 1);
subtest "child" => sub {
pass("Child");
};
exit;
}
# Increment the counter to take into account what was run by the child
$tb->current_test($tb->current_test + 1);
wait;
pass("After fork");
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment