Fix bug with generated component classes and an issue with the test
[catagits/Catalyst-Devel.git] / t / generated_app.t
CommitLineData
ad9d93fc 1use strict;
2use warnings;
0d4859fc 3use lib ();
99618c49 4use File::Temp qw/ tempdir tmpnam /;
0f89baa1 5use File::Spec;
a73b3971 6use FindBin qw/$Bin/;
3d3e34a0 7use Catalyst::Devel;
99618c49 8
0d4859fc 9my $dir = tempdir(CLEANUP => 1);
165233a4 10my $devnull = File::Spec->devnull;
ad9d93fc 11
12use Test::More;
91497b69 13
15f460a5 14diag "Generated app is in $dir";
91497b69 15
ad9d93fc 16{
91497b69 17 my $exit;
165233a4 18 if ($^O eq 'MSWin32') {
91497b69 19 $exit = system("cd $dir & catalyst TestApp > $devnull 2>&1");
165233a4 20 }
21 else {
91497b69 22 $exit = system("cd $dir; catalyst.pl TestApp > $devnull 2>&1");
165233a4 23 }
91497b69 24 is $exit, 0, 'Exit status ok';
ad9d93fc 25}
0d4859fc 26
27chdir(File::Spec->catdir($dir, 'TestApp'));
28lib->import(File::Spec->catdir($dir, 'TestApp', 'lib'));
ad9d93fc 29
ad9d93fc 30my @files = qw|
31 Makefile.PL
2cb998f9 32 testapp.conf
91497b69 33 lib/TestApp.pm
34 lib/TestApp/Controller/Root.pm
35 README
36 Changes
37 t/01app.t
38 t/02pod.t
39 t/03podcoverage.t
40 root/static/images/catalyst_logo.png
41 root/static/images/btn_120x50_built.png
42 root/static/images/btn_120x50_built_shadow.png
43 root/static/images/btn_120x50_powered.png
44 root/static/images/btn_120x50_powered_shadow.png
45 root/static/images/btn_88x31_built.png
46 root/static/images/btn_88x31_built_shadow.png
47 root/static/images/btn_88x31_powered.png
48 root/static/images/btn_88x31_powered_shadow.png
49 root/favicon.ico
50 Makefile.PL
51 script/testapp_cgi.pl
52 script/testapp_fastcgi.pl
53 script/testapp_server.pl
54 script/testapp_test.pl
55 script/testapp_create.pl
ad9d93fc 56|;
57
a73b3971 58foreach my $fn (map { File::Spec->catdir(@$_) } map { [ split /\// ] } @files) {
59 test_fn($fn);
ad9d93fc 60}
a73b3971 61create_ok($_, 'My' . $_) for qw/Model View Controller/;
ad9d93fc 62
15f460a5 63is system($^X, 'Makefile.PL'), 0, 'Ran Makefile.PL';
64ok -e "Makefile", "Makefile generated";
91497b69 65is system("make"), 0, 'Run make';
66
41cebeb1 67run_generated_component_tests();
68
3d3e34a0 69my $server_script = do {
15f460a5 70 open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!;
3d3e34a0 71 local $/;
72 <$fh>;
73};
74
15f460a5 75ok $server_script;
3d3e34a0 76ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
77 'SCRIPT_GEN found in generated output';
78is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
79
91497b69 80chdir('/');
3d3e34a0 81done_testing;
a73b3971 82
83sub runperl {
84 my $comment = pop @_;
85 is system($^X, '-I', File::Spec->catdir($Bin, '..', 'lib'), @_), 0, $comment;
86}
87
41cebeb1 88my @generated_component_tests;
89
a73b3971 90sub test_fn {
91 local $ENV{TEST_POD} = 1;
92 local $ENV{CATALYST_DEBUG} = 0;
41cebeb1 93
a73b3971 94 my $fn = shift;
95 ok -r $fn, "Have $fn in generated app";
96 if ($fn =~ /script/) {
97 ok -x $fn, "$fn is executable";
98 }
99 if ($fn =~ /\.p[ml]$/) {
100 runperl( '-c', $fn, "$fn compiles" );
101 }
41cebeb1 102 # Save these till later as Catalyst::Test will only be loaded once :-/
103 push @generated_component_tests, $fn
104 if $fn =~ /\.t$/;
105}
106
107sub run_generated_component_tests {
108 foreach my $fn (@generated_component_tests) {
a73b3971 109 subtest "Generated app test: $fn", sub {
110 require $fn;
111 };
112 }
113}
114
115sub create_ok {
116 my ($type, $name) = @_;
117 runperl( File::Spec->catdir('script', 'testapp_create.pl'), $type, $name,
118 "'script/testapp_create.pl $type $name' ok");
119 test_fn(File::Spec->catdir('t', sprintf("%s_%s.t", $type, $name)));
120}