Commit | Line | Data |
09274aae |
1 | #!/usr/bin/perl |
158fef48 |
2 | # live_fork.t |
09274aae |
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 | |
158fef48 |
20 | plan skip_all => 'Using remote server (and REMOTE_FORK not set)' |
21 | if $ENV{CATALYST_SERVER} && !$ENV{REMOTE_FORK}; |
22 | |
08ace8f7 |
23 | plan skip_all => 'Skipping fork tests: no /bin/ls' |
24 | if !-e '/bin/ls'; # see if /bin/ls exists |
158fef48 |
25 | |
8d5f3e92 |
26 | { |
31b71f4b |
27 | ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system'); |
158fef48 |
28 | |
ba9ee3c8 |
29 | if (my $result_ref = result_ok($result)) { |
30 | ok($result_ref, 'is YAML'); |
31 | is($result_ref->{result}, 0, 'exited OK'); |
32 | } |
8d5f3e92 |
33 | } |
09274aae |
34 | |
158fef48 |
35 | { |
31b71f4b |
36 | ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`'); |
158fef48 |
37 | |
ba9ee3c8 |
38 | if (my $result_ref = result_ok($result)) { |
39 | ok($result_ref, 'is YAML'); |
40 | is($result_ref->{code}, 0, 'exited successfully'); |
41 | like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$'); |
42 | like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines'); |
43 | } |
8d5f3e92 |
44 | } |
ba9ee3c8 |
45 | |
158fef48 |
46 | { |
31b71f4b |
47 | ok(my $result = get('/fork/fork'), 'fork'); |
ba9ee3c8 |
48 | |
49 | if (my $result_ref = result_ok($result)) { |
50 | ok($result_ref, 'is YAML'); |
51 | isnt($result_ref->{pid}, 0, q{fork's "pid" wasn't 0}); |
52 | isnt($result_ref->{pid}, $$, 'fork got a new pid'); |
53 | is($result_ref->{result}, 'ok', 'fork was effective'); |
54 | } |
55 | } |
56 | |
57 | sub result_ok { |
58 | my $result = shift; |
59 | |
60 | unlike( $result, qr/FATAL/, 'result is not an error' ) |
61 | or return; |
62 | |
b7e111a5 |
63 | $result =~ s/\r\n|\r/\n/g; |
158fef48 |
64 | |
ba9ee3c8 |
65 | return eval { Load($result) }; |
31b71f4b |
66 | } |
ba9ee3c8 |
67 | |
68 | done_testing; |