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