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