Brilliant! adrianh++
I missed that bit in the docs, but it works like a charm. I guess I was confused that Test::Harness couldn't see the correct number of valid tests either, but it must parse some of the end report that Test::More generates, instead of counting the tests itself.
There is just one limitation (that doesn't affect me), but after the fork, you can't perform any more tests in the parent, because it will mess up the test numbering (since it doesn't see the tests the child has performed). However, you could disable automatic numbering and manage that yourself to get around it. For me it is not a big deal, since I don't need to perform any more tests in the parent after the fork.
In case anyone is intereset why I needed this, I needed to test a CGI file upload, and the following allows me to simulate that perfectly (basic idea stolen from CGI.pm test suite):
my $req = &HTTP::Request::Common::POST(
'/dummy_location',
Content_Type => 'form-data',
Content => [
test => 'name2',
image1 => ["t/image.jpg"],
]
);
$ENV{REQUEST_METHOD} = 'POST';
$ENV{CONTENT_TYPE} = 'multipart/form-data';
$ENV{CONTENT_LENGTH} = $req->content_length;
if ( open( CHILD, "|-" ) ) {
print CHILD $req->content;
close CHILD;
exit 0;
}
# at this point, we're in a new (child) process
# and CGI.pm can read the POST params from STDIN
# as in a real request
my $q = CGI->new;