http://www.perlmonks.org?node_id=765232


in reply to Results printing multiple times when testcase with fork using Test::more module

Since you fork, you spawn another process from the current process and thus have two results. Why do you fork if you want just one run of the test?

If you want the child to terminate before the evaluation of the last ok() test, your sub should look like:

sub for{ my $pid = fork; if($pid == 0 ){ diag "$$: 0\n"; exit; }else{ diag "$$: 1\n"; waitpid($pid,0); } 1; }

Replies are listed 'Best First'.
Re^2: Results printing multiple times when testcase with fork using Test::more module
by thiagu_mvt (Sexton) on May 21, 2009 at 10:51 UTC
    This is just an example. My actual program calls an API function which is doing the forking through 'open3'. So not my intention or in control.