logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Test::Fork - test code which forks

Author

       Michael G Schwern <schwern@pobox.com>

Bugs And Feedback

       Please send all bugs and feature requests to bug-Test-Fork at rt.cpan.org or use the web interface via
       <http://rt.cpan.org>.

       If you use it, please send feedback.  I like getting feedback.

Caveats

       The failure of tests in a child process cannot be detected by the parent.  Therefore, the normal end-of-
       test reporting done by Test::Builder will not notice failed child tests.

       Test::Fork turns off test numbering in order to avoid test counter coordination issues.  It turns it back
       on once the children are done running.

       Test::Fork will wait for all your child processes to complete at the end of the parent process.

Description

THISISALPHACODE!  The implementation is unreliable and the interface is subject to change.

       Because each test has a number associated with it, testing code which forks is problematic.  Coordinating
       the test number amongst the parent and child processes is complicated.  Test::Fork provides a function to
       smooth over the complications.

   Functions
       Each function is exported by default.

       fork_ok

           my $child_pid = fork_ok( $num_tests, sub {
               ...child test code...
           });

       Runs the given child test code in a forked process.  Returns the pid of the forked child process, or
       false if the fork fails.

       $num_tests is the number of tests in your child test code.  Consider it to be a sub-plan.

       fork_ok() itself is a test, if the fork fails it will fail.  fork_ok() test does not count towards your
       $num_tests.

           # This is three tests.
           fork_ok( 2, sub {
               is $foo, $bar;
               ok Something->method;
           });

       The children are automatically reaped.

Name

       Test::Fork - test code which forks

See Also

       Test::MultiFork

Synopsis

           use Test::More tests => 4;
           use Test::Fork;

           fork_ok(2, sub{
               pass("Test in the child process");
               pass("Another test in the child process");
           });

           pass("Test in the parent");

See Also