X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Flive_fork.t;h=3a2dc3c3e9fa752746dbca8c1c419060c818377c;hp=3abe4e29f1f6317357f23a1c178f7db1ae023eb7;hb=82010ea176741c7a4f2baf3f6f27377b1d9f6b15;hpb=15f0ede8ee33bc9b0c002221a8e62f59e8b7b7e2 diff --git a/t/live_fork.t b/t/live_fork.t index 3abe4e2..3a2dc3c 100644 --- a/t/live_fork.t +++ b/t/live_fork.t @@ -1,5 +1,4 @@ -#!/usr/bin/perl -# live_fork.t +# live_fork.t # Copyright (c) 2006 Jonathan Rockway =head1 SYNOPSIS @@ -17,46 +16,52 @@ use Catalyst::Test qw(TestApp); eval 'use YAML'; plan skip_all => 'YAML required' if $@; -plan skip_all => 'Using remote server' - if $ENV{CATALYST_SERVER}; - +plan skip_all => 'Using remote server (and REMOTE_FORK not set)' + if $ENV{CATALYST_SERVER} && !$ENV{REMOTE_FORK}; + plan skip_all => 'Skipping fork tests: no /bin/ls' if !-e '/bin/ls'; # see if /bin/ls exists - -plan tests => 13; # otherwise { - system: ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system'); - my @result = split /$/m, $result; - $result = join q{}, @result[-4..-1]; - - my $result_ref = eval { Load($result) }; - ok($result_ref, 'is YAML'); - is($result_ref->{result}, 0, 'exited OK'); + + if (my $result_ref = result_ok($result)) { + ok($result_ref, 'is YAML'); + is($result_ref->{result}, 0, 'exited OK'); + } } -{ - backticks: +{ ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`'); - my @result = split /$/m, $result; - $result = join q{}, @result[-4..-1]; - - my $result_ref = eval { Load($result) }; - ok($result_ref, 'is YAML'); - is($result_ref->{code}, 0, 'exited successfully'); - like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$'); - like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines'); + + if (my $result_ref = result_ok($result)) { + ok($result_ref, 'is YAML'); + is($result_ref->{code}, 0, 'exited successfully'); + like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$'); + like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines'); + } } -{ - fork: + +{ ok(my $result = get('/fork/fork'), 'fork'); - my @result = split /$/m, $result; - $result = join q{}, @result[-4..-1]; - - my $result_ref = eval { Load($result) }; - ok($result_ref, 'is YAML'); - isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0}); - isnt($result_ref->{pid}, $$, 'fork got a new pid'); - is($result_ref->{result}, 'ok', 'fork was effective'); + + if (my $result_ref = result_ok($result)) { + ok($result_ref, 'is YAML'); + isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0}); + isnt($result_ref->{pid}, $$, 'fork got a new pid'); + is($result_ref->{result}, 'ok', 'fork was effective'); + } } + +sub result_ok { + my $result = shift; + + unlike( $result, qr/FATAL/, 'result is not an error' ) + or return; + + $result =~ s/\r\n|\r/\n/g; + + return eval { Load($result) }; +} + +done_testing;