test for fork also
[catagits/Catalyst-Runtime.git] / t / live_fork.t
1 #!/usr/bin/perl
2 # live_fork.t 
3 # Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
4
5 =head1 SYNOPSIS
6
7 Tests if Catalyst can fork/exec other processes successfully
8
9 =cut
10 use strict;
11 use warnings;
12 use Test::More;
13 use YAML;
14 use FindBin;
15 use lib "$FindBin::Bin/lib";
16 use Catalyst::Test qw(TestApp);
17
18 plan 'skip_all' if !-e '/bin/ls'; # see if /bin/ls exists
19 plan tests => 13; # otherwise
20
21 {
22   system:
23     ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system');
24     my @result = split /$/m, $result;
25     $result = join q{}, @result[-4..-1];
26     
27     my $result_ref = eval { Load($result) };
28     ok($result_ref, 'is YAML');
29     is($result_ref->{code}, 0, 'exited successfully');
30     like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$');
31 }
32
33
34   backticks:
35     ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`');
36     my @result = split /$/m, $result;
37     $result = join q{}, @result[-4..-1];
38     
39     my $result_ref = eval { Load($result) };
40     ok($result_ref, 'is YAML');
41     is($result_ref->{code}, 0, 'exited successfully');
42     like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$');
43 }
44
45   fork:
46     ok(my $result = get('/fork/fork'), 'fork');
47     my @result = split /$/m, $result;
48     $result = join q{}, @result[-4..-1];
49     
50     my $result_ref = eval { Load($result) };
51     ok($result_ref, 'is YAML');
52     isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0});
53     isnt($result_ref->{pid}, $$, 'fork got a new pid');
54     is($result_ref->{result}, 'ok', 'fork was effective');
55 }