Merge branch '104-path_empty_brackets' of https://github.com/grim8634/catalyst-runtim...
[catagits/Catalyst-Runtime.git] / t / unit_core_script_test.t
CommitLineData
718e995d 1use strict;
2use warnings;
3
99d30e96 4use Carp qw(croak);
718e995d 5use FindBin qw/$Bin/;
6b665c03 6use lib "$Bin/lib";
718e995d 7
8use Test::More;
2a56ace9 9use Test::Fatal;
718e995d 10
11use Catalyst::Script::Test;
12use File::Temp qw/tempfile/;
13use IO::Handle;
14
95389116 15is run_test('/'), "root index\n", 'correct content printed';
16is run_test('/moose/get_attribute'), "42\n", 'Correct content printed for non root action';
718e995d 17
18done_testing;
19
95389116 20sub run_test {
21 my $url = shift;
22
23 my ($fh, $fn) = tempfile();
24
25 binmode( $fh );
26 binmode( STDOUT );
27
28 {
29 local @ARGV = ($url);
30 my $i;
2a56ace9 31 is exception {
95389116 32 $i = Catalyst::Script::Test->new_with_options(application_name => 'TestApp');
2a56ace9 33 }, undef, "new_with_options";
95389116 34 ok $i;
35 my $saved;
b50712ce 36 open( $saved, '>&'. STDOUT->fileno )
37 or croak("Can't dup stdout: $!");
95389116 38 open( STDOUT, '>&='. $fh->fileno )
39 or croak("Can't open stdout: $!");
40 eval { $i->run };
41 ok !$@, 'Ran ok';
42
43 STDOUT->flush
44 or croak("Can't flush stdout: $!");
45
46 open( STDOUT, '>&'. fileno($saved) )
47 or croak("Can't restore stdout: $!");
48 }
49
50 my $data = do { my $fh; open($fh, '<', $fn) or die $!; local $/; <$fh>; };
51 $fh = undef;
52 unlink $fn if -r $fn;
53
54 return $data;
55}