Commit | Line | Data |
09274aae |
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; |
09274aae |
13 | use FindBin; |
14 | use lib "$FindBin::Bin/lib"; |
15 | use Catalyst::Test qw(TestApp); |
16 | |
15f0ede8 |
17 | eval 'use YAML'; |
18 | plan skip_all => 'YAML required' if $@; |
19 | |
08ace8f7 |
20 | plan skip_all => 'Using remote server' |
21 | if $ENV{CATALYST_SERVER}; |
22 | |
23 | plan skip_all => 'Skipping fork tests: no /bin/ls' |
24 | if !-e '/bin/ls'; # see if /bin/ls exists |
25 | |
31b71f4b |
26 | plan tests => 13; # otherwise |
09274aae |
27 | |
8d5f3e92 |
28 | { |
31b71f4b |
29 | system: |
30 | ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system'); |
8d5f3e92 |
31 | my @result = split /$/m, $result; |
32 | $result = join q{}, @result[-4..-1]; |
33 | |
34 | my $result_ref = eval { Load($result) }; |
35 | ok($result_ref, 'is YAML'); |
a147e337 |
36 | is($result_ref->{result}, 0, 'exited OK'); |
8d5f3e92 |
37 | } |
09274aae |
38 | |
8d5f3e92 |
39 | { |
40 | backticks: |
31b71f4b |
41 | ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`'); |
8d5f3e92 |
42 | my @result = split /$/m, $result; |
43 | $result = join q{}, @result[-4..-1]; |
44 | |
45 | my $result_ref = eval { Load($result) }; |
46 | ok($result_ref, 'is YAML'); |
47 | is($result_ref->{code}, 0, 'exited successfully'); |
48 | like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$'); |
a147e337 |
49 | like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines'); |
8d5f3e92 |
50 | } |
31b71f4b |
51 | { |
52 | fork: |
53 | ok(my $result = get('/fork/fork'), 'fork'); |
54 | my @result = split /$/m, $result; |
55 | $result = join q{}, @result[-4..-1]; |
56 | |
57 | my $result_ref = eval { Load($result) }; |
58 | ok($result_ref, 'is YAML'); |
59 | isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0}); |
60 | isnt($result_ref->{pid}, $$, 'fork got a new pid'); |
61 | is($result_ref->{result}, 'ok', 'fork was effective'); |
62 | } |