tweaking for FCGI stuff
[gitmo/MooseX-Daemonize.git] / t / 02.stdout.t
1 use Test::More no_plan => 1;
2 use Test::Builder;
3 use Test::MooseX::Daemonize;
4 use MooseX::Daemonize;
5
6 my $Test = Test::Builder->new;
7
8 {
9
10     package TestOutput;
11     use Moose;
12     with qw(MooseX::Daemonize);
13     with qw(Test::MooseX::Daemonize::Testable);    # setup our test environment
14
15     after start => sub {
16         my ($self) = @_;
17         $self->output_ok() 
18             if $self->is_daemon;
19     };
20
21     sub output_ok {
22         my ($self) = @_;
23         my $count = 1;
24         for ( 0 .. 3 ) {
25             $Test->ok( $count++, "$count output_ok" );
26             sleep(1);
27         }
28     }
29     no Moose;
30 }
31
32 package main;
33 use Cwd;
34 use strict;
35 use warnings;
36
37 ## Try to make sure we are in the test directory
38 chdir 't' if ( Cwd::cwd() !~ m|/t$| );
39 my $cwd = Cwd::cwd();
40 my $app = TestOutput->new(
41     pidbase     => $cwd,
42     test_output => join( '/', $cwd, 'results' ),
43 );
44 daemonize_ok( $app, 'child forked okay' );
45 sleep(3);    # give ourself a chance to produce some output
46
47 my $warnings = "";
48 {
49         local $SIG{__WARN__} = sub { $warnings .= $_[0]; warn @_ };
50         $app->stop( no_exit => 1 );
51 }
52
53 is($warnings, "", "No warnings from stop");
54
55 check_test_output($app);
56 unlink( $app->test_output );
57 exit;