even this change is appreciated.
[catagits/Catalyst-Runtime.git] / t / live_fork.t
CommitLineData
158fef48 1# live_fork.t
09274aae 2# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
3
4=head1 SYNOPSIS
5
6Tests if Catalyst can fork/exec other processes successfully
7
8=cut
9use strict;
10use warnings;
11use Test::More;
09274aae 12use FindBin;
13use lib "$FindBin::Bin/lib";
14use Catalyst::Test qw(TestApp);
8a1b06be 15use JSON::MaybeXS qw(decode_json);
15f0ede8 16
158fef48 17plan skip_all => 'Using remote server (and REMOTE_FORK not set)'
18 if $ENV{CATALYST_SERVER} && !$ENV{REMOTE_FORK};
19
08ace8f7 20plan skip_all => 'Skipping fork tests: no /bin/ls'
21 if !-e '/bin/ls'; # see if /bin/ls exists
158fef48 22
8d5f3e92 23{
31b71f4b 24 ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system');
158fef48 25
ba9ee3c8 26 if (my $result_ref = result_ok($result)) {
8a1b06be 27 ok($result_ref, 'is JSON');
ba9ee3c8 28 is($result_ref->{result}, 0, 'exited OK');
29 }
8d5f3e92 30}
09274aae 31
158fef48 32{
31b71f4b 33 ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`');
158fef48 34
ba9ee3c8 35 if (my $result_ref = result_ok($result)) {
8a1b06be 36 ok($result_ref, 'is JSON');
ba9ee3c8 37 is($result_ref->{code}, 0, 'exited successfully');
38 like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$');
39 like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines');
40 }
8d5f3e92 41}
ba9ee3c8 42
158fef48 43{
31b71f4b 44 ok(my $result = get('/fork/fork'), 'fork');
ba9ee3c8 45
46 if (my $result_ref = result_ok($result)) {
8a1b06be 47 ok($result_ref, 'is JSON');
ba9ee3c8 48 isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0});
49 isnt($result_ref->{pid}, $$, 'fork got a new pid');
50 is($result_ref->{result}, 'ok', 'fork was effective');
51 }
52}
53
54sub result_ok {
55 my $result = shift;
56
57 unlike( $result, qr/FATAL/, 'result is not an error' )
58 or return;
59
b7e111a5 60 $result =~ s/\r\n|\r/\n/g;
158fef48 61
8a1b06be 62 return eval { decode_json($result) };
31b71f4b 63}
ba9ee3c8 64
65done_testing;