Makebe fix FAR.. Remove warning suppresssion
[catagits/Catalyst-Devel.git] / t / generated_app.t
CommitLineData
ad9d93fc 1use strict;
2use warnings;
0d4859fc 3use lib ();
4c709311 4use Cwd qw( abs_path );
5use File::Temp qw/ tempdir /;
0f89baa1 6use File::Spec;
a73b3971 7use FindBin qw/$Bin/;
3d3e34a0 8use Catalyst::Devel;
4c709311 9use Catalyst::Helper;
10use Test::More;
29ac6b9f 11use Config;
4c709311 12
13eval "use IPC::Run3";
14plan skip_all => 'These tests require IPC::Run3' if $@;
15
16my $share_dir = abs_path('share');
17plan skip_all => "No share dir at $share_dir!"
18 unless -d $share_dir;
19
20$ENV{CATALYST_DEVEL_SHAREDIR} = $share_dir;
99618c49 21
0d4859fc 22my $dir = tempdir(CLEANUP => 1);
165233a4 23my $devnull = File::Spec->devnull;
ad9d93fc 24
15f460a5 25diag "Generated app is in $dir";
91497b69 26
4c709311 27chdir $dir or die "Cannot chdir to $dir: $!";
28
ad9d93fc 29{
4c709311 30 open my $fh, '>', $devnull or die "Cannot write to $devnull: $!";
31
32 local *STDOUT = $fh;
33
34 my $helper = Catalyst::Helper->new(
35 {
36 name => 'TestApp',
37 }
38 );
39
40 $helper->mk_app('TestApp');
ad9d93fc 41}
0d4859fc 42
4c709311 43my $app_dir = File::Spec->catdir($dir, 'TestApp');
44chdir($app_dir) or die "Cannot chdir to $app_dir: $!";
0d4859fc 45lib->import(File::Spec->catdir($dir, 'TestApp', 'lib'));
ad9d93fc 46
ad9d93fc 47my @files = qw|
48 Makefile.PL
2cb998f9 49 testapp.conf
91497b69 50 lib/TestApp.pm
51 lib/TestApp/Controller/Root.pm
52 README
53 Changes
54 t/01app.t
55 t/02pod.t
56 t/03podcoverage.t
57 root/static/images/catalyst_logo.png
58 root/static/images/btn_120x50_built.png
59 root/static/images/btn_120x50_built_shadow.png
60 root/static/images/btn_120x50_powered.png
61 root/static/images/btn_120x50_powered_shadow.png
62 root/static/images/btn_88x31_built.png
63 root/static/images/btn_88x31_built_shadow.png
64 root/static/images/btn_88x31_powered.png
65 root/static/images/btn_88x31_powered_shadow.png
66 root/favicon.ico
67 Makefile.PL
68 script/testapp_cgi.pl
69 script/testapp_fastcgi.pl
70 script/testapp_server.pl
71 script/testapp_test.pl
72 script/testapp_create.pl
ad9d93fc 73|;
74
a73b3971 75foreach my $fn (map { File::Spec->catdir(@$_) } map { [ split /\// ] } @files) {
76 test_fn($fn);
ad9d93fc 77}
a73b3971 78create_ok($_, 'My' . $_) for qw/Model View Controller/;
ad9d93fc 79
4c709311 80command_ok( [ $^X, 'Makefile.PL' ] );
15f460a5 81ok -e "Makefile", "Makefile generated";
29ac6b9f 82#NOTE: do not assume that 'make' is always 'make' as e.g. Win32/strawberry perl uses 'dmake'
ee2184e2 83my $make = $Config{make} || 'make';
84command_ok( [ $make ], 'Ran make ok' );
85if (eval { require PAR::Packer }) {
86 command_ok([ $make, 'catalyst_par' ], 'Ran make catalyst_par ok');
87 command_ok([ 'parl', ]); # FIXME - Win32?
88}
91497b69 89
41cebeb1 90run_generated_component_tests();
91
3d3e34a0 92my $server_script = do {
15f460a5 93 open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!;
3d3e34a0 94 local $/;
95 <$fh>;
96};
97
15f460a5 98ok $server_script;
3d3e34a0 99ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
100 'SCRIPT_GEN found in generated output';
101is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
102
91497b69 103chdir('/');
3d3e34a0 104done_testing;
a73b3971 105
4c709311 106sub command_ok {
107 my $cmd = shift;
108 my $desc = shift;
109
110 my $stdout;
111 my $stderr;
112 run3( $cmd, \undef, \$stdout, \$stderr );
113
114 $desc ||= "Exit status ok for '@{$cmd}'";
115 unless ( is $? >> 8, 0, $desc ) {
116 diag "STDOUT:\n$stdout" if defined $stdout;
117 diag "STDERR:\n$stderr" if defined $stderr;
118 }
119}
120
a73b3971 121sub runperl {
122 my $comment = pop @_;
4c709311 123 command_ok( [ $^X, '-I', File::Spec->catdir($Bin, '..', 'lib'), @_ ], $comment );
a73b3971 124}
125
41cebeb1 126my @generated_component_tests;
127
a73b3971 128sub test_fn {
a73b3971 129 my $fn = shift;
130 ok -r $fn, "Have $fn in generated app";
131 if ($fn =~ /script/) {
29ac6b9f 132 SKIP: {
133 skip 'Executable file flag test does not make sense on Win32', 1 if ($^O eq 'MSWin32');
134 ok -x $fn, "$fn is executable";
135 }
a73b3971 136 }
137 if ($fn =~ /\.p[ml]$/) {
138 runperl( '-c', $fn, "$fn compiles" );
139 }
41cebeb1 140 # Save these till later as Catalyst::Test will only be loaded once :-/
141 push @generated_component_tests, $fn
142 if $fn =~ /\.t$/;
143}
144
145sub run_generated_component_tests {
e3eb9f88 146 local $ENV{TEST_POD} = 1;
147 local $ENV{CATALYST_DEBUG} = 0;
41cebeb1 148 foreach my $fn (@generated_component_tests) {
a73b3971 149 subtest "Generated app test: $fn", sub {
c632d293 150 do $fn;
a73b3971 151 };
152 }
153}
154
155sub create_ok {
156 my ($type, $name) = @_;
157 runperl( File::Spec->catdir('script', 'testapp_create.pl'), $type, $name,
158 "'script/testapp_create.pl $type $name' ok");
4c709311 159 test_fn(File::Spec->catdir('t', sprintf("%s_%s.t", lc $type, $name)));
a73b3971 160}