Run tests only once, running tests more than once just slows down debugging and insta...
[catagits/Catalyst-Runtime.git] / t / live_fork.t
CommitLineData
09274aae 1#!/usr/bin/perl
2# live_fork.t
3# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
4
5=head1 SYNOPSIS
6
7Tests if Catalyst can fork/exec other processes successfully
8
9=cut
10use strict;
11use warnings;
12use Test::More;
13use YAML;
14use FindBin;
15use lib "$FindBin::Bin/lib";
16use Catalyst::Test qw(TestApp);
17
18plan 'skip_all' if !-e '/bin/ls'; # see if /bin/ls exists
31b71f4b 19plan tests => 13; # otherwise
09274aae 20
8d5f3e92 21{
31b71f4b 22 system:
23 ok(my $result = get('/fork/system/%2Fbin%2Fls'), 'system');
8d5f3e92 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');
a147e337 29 is($result_ref->{result}, 0, 'exited OK');
8d5f3e92 30}
09274aae 31
8d5f3e92 32{
33 backticks:
31b71f4b 34 ok(my $result = get('/fork/backticks/%2Fbin%2Fls'), '`backticks`');
8d5f3e92 35 my @result = split /$/m, $result;
36 $result = join q{}, @result[-4..-1];
37
38 my $result_ref = eval { Load($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$');
a147e337 42 like($result_ref->{result}, qr{\n.*\n}m, 'contains two newlines');
8d5f3e92 43}
31b71f4b 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}