Fugly test for myapp_test.pl. If someone fancies rewriting the IO redirection to...
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_script_test.t
1 use strict;
2 use warnings;
3
4 use FindBin qw/$Bin/;
5 use lib "$Bin/../lib";
6
7 use Test::More;
8 use Test::Exception;
9
10 use Catalyst::Script::Test;
11 use File::Temp qw/tempfile/;
12 use IO::Handle;
13
14 my ($fh, $fn) = tempfile();
15
16 binmode( $fh );
17 binmode( STDOUT );
18
19 {
20     local @ARGV = ('/');
21     my $i;
22     lives_ok {
23         $i = Catalyst::Script::Test->new_with_options(application_name => 'TestApp');
24     } "new_with_options";
25     ok $i;
26     my $saved;
27     open( $saved, '<&'. STDIN->fileno )
28           or croak("Can't dup stdin: $!");
29     open( STDOUT, '>&='. $fh->fileno )
30         or croak("Can't open stdout: $!");
31     eval { $i->run };
32     ok !$@, 'Ran ok';
33
34     STDOUT->flush
35         or croak("Can't flush stdout: $!");
36
37     open( STDOUT, '>&'. fileno($saved) )
38         or croak("Can't restore stdout: $!");
39 }
40
41 my $data = do { my $fh; open($fh, '<', $fn) or die $!; local $/; <$fh>; };
42 $fh = undef;
43 unlink $fn if -r $fn;
44
45 is $data, "root index\n", 'correct content printed';
46
47 done_testing;
48