adding a failing test -- under dev server, fork() doesn't work
Jonathan Rockway [Mon, 20 Nov 2006 00:26:17 +0000 (00:26 +0000)]
t/lib/TestApp/Controller/Fork.pm [new file with mode: 0644]
t/live_fork.t [new file with mode: 0644]

diff --git a/t/lib/TestApp/Controller/Fork.pm b/t/lib/TestApp/Controller/Fork.pm
new file mode 100644 (file)
index 0000000..fb71c7c
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+# Fork.pm 
+# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
+
+package TestApp::Controller::Fork;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+use YAML;
+
+sub fork : Global {
+    my ($self, $c, $ls) = @_;
+    my ($result, $code) = (undef, 1);
+
+    if(!-e $ls || !-x _){ 
+       $result = 'skip';
+       $code = 0;
+    }
+    else {
+       $result = system($ls, $ls, $ls);
+       $code = $?;
+    }
+    
+    $c->response->body(Dump({result => $result, code => $code}));
+}
+
+1;
diff --git a/t/live_fork.t b/t/live_fork.t
new file mode 100644 (file)
index 0000000..4ace65c
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+# live_fork.t 
+# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
+
+=head1 SYNOPSIS
+
+Tests if Catalyst can fork/exec other processes successfully
+
+=cut
+use strict;
+use warnings;
+use Test::More;
+use YAML;
+use FindBin;
+use lib "$FindBin::Bin/lib";
+use Catalyst::Test qw(TestApp);
+
+plan 'skip_all' if !-e '/bin/ls'; # see if /bin/ls exists
+plan tests => 4; # otherwise
+
+ok(my $result = get('/fork/%2Fbin%2Fls'), 'get /fork//bin/ls');
+my @result = split /$/m, $result;
+$result = join "", @result[-4..-1];
+
+my $result_ref = eval { Load($result) };
+ok($result_ref, 'is YAML');
+is($result_ref->{code}, 0, 'exited successfully');
+like($result_ref->{result}, qr{^/bin/ls[^:]}, 'contains ^/bin/ls$');