got 01.filecreate.t passing ...
[gitmo/MooseX-Daemonize.git] / t / 02.stdout.t
index dcf2706..b506f25 100644 (file)
@@ -1,35 +1,30 @@
 use Test::More no_plan => 1;
 use Test::Builder;
 use Test::MooseX::Daemonize;
+use MooseX::Daemonize;
 
 my $Test = Test::Builder->new;
-chdir 't' if ( Cwd::cwd() !~ m|/t$| );
-my $cwd = Cwd::cwd();
-
-my $file = join( '/', $cwd, 'results' );
 
 {
 
     package TestOutput;
     use Moose;
     with qw(MooseX::Daemonize);
-    with qw(Test::MooseX::Daemonize::Testable); # setup our test environment
-    
-    has max => ( isa => 'Int', is => 'ro', default => sub { 5 } );
-    
+    with qw(Test::MooseX::Daemonize::Testable);    # setup our test environment
+
     after start => sub {
         my ($self) = @_;
-        $self->output_ok(1);
+        $self->output_ok();
     };
 
     sub output_ok {
-        my ( $self, $count ) = @_;
-        $Test->ok( $count, "$count output_ok" );
-        if ( $count++ > $self->max ) {
-            $self->stop();
-            return;
+        my ($self) = @_;
+        my $count = 1;
+        while (1) {
+            $Test->ok( $count++, "$count output_ok" );
+            sleep(1);
         }
-        $self->output_ok($count);
+
     }
     no Moose;
 }
@@ -40,30 +35,13 @@ use Cwd;
 ## Try to make sure we are in the test directory
 chdir 't' if ( Cwd::cwd() !~ m|/t$| );
 my $cwd = Cwd::cwd();
-
-my $daemon = TestOutput->new( pidbase => $cwd, test_output => $file);
-
-daemonize_ok( $daemon, 'child forked okay' );
-
-open (my $stdout_in, '<', 'results');
-while ( my $line = <$stdout_in> ) {
-    $line =~ s/\s+\z//;
-    if ( $line =~ /\A((not\s+)?ok)(?:\s+-)(?:\s+(.*))\z/ ) {
-        my ( $status, $not, $text ) = ( $1, $2, $3 );
-        $text ||= '';
-
-        # We don't just call ok(!$not), because that generates diagnostics of
-        # its own for failures. We only want the diagnostics from the child.
-        my $num = $Test->current_test;
-        $Test->current_test( ++$num );
-        $Test->_print("$status $num - $label: $text\n");
-    }
-    elsif ( $line =~ s/\A#\s?// ) {
-        $Test->diag($line);
-    }
-    else {
-        $Test->_print_diag("$label: $line (unrecognised)\n");
-    }
-}
-
-unlink($file);
\ No newline at end of file
+my $app = TestOutput->new(
+    pidbase     => $cwd,
+    test_output => join( '/', $cwd, 'results' ),
+);
+daemonize_ok( $app, 'child forked okay' );
+sleep(5);    # give ourself a chance to produce some output
+$app->stop( no_exit => 1 );
+
+check_test_output($app);
+unlink( $app->test_output );