Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Test::More and fork

by cees (Curate)
on Jun 23, 2005 at 19:05 UTC ( #469484=note: print w/ replies, xml ) Need Help??


in reply to Re: Test::More and fork
in thread Test::More and fork

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;


Comment on Re^2: Test::More and fork
Download Code
Re^3: Test::More and fork
by adrianh (Chancellor) on Jun 23, 2005 at 23:10 UTC
    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.

    The reason T::H gives an error is that the when T::B figures out it has a bad test count it exits with a non-zero value, which then gets picked up as suspicious by T::H (which is why you got the "Test returned status 1" error from T::H).

    This makes it easier for other things like Aegis to figure out which test script borked automatically.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://469484]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2014-08-30 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls