Add more tests, kill off the required attributes and start instead building a data...
[catagits/Catalyst-Devel.git] / t / generated_app.t
1 use strict;
2 use warnings;
3 use lib ();
4 use File::Temp qw/ tempdir tmpnam /;
5 use File::Spec;
6 use FindBin qw/$Bin/;
7 use Catalyst::Devel;
8
9 my $dir = tempdir(CLEANUP => 1);
10 my $devnull = File::Spec->devnull;
11
12 use Test::More;
13
14 diag "Generated app is in $dir";
15
16 {
17     my $exit;
18     if ($^O eq 'MSWin32') {
19       $exit = system("cd $dir & catalyst TestApp > $devnull 2>&1");
20     }
21     else {
22       $exit = system("cd $dir; catalyst.pl TestApp > $devnull 2>&1");
23     }
24     is $exit, 0, 'Exit status ok';
25 }
26
27 chdir(File::Spec->catdir($dir, 'TestApp'));
28 lib->import(File::Spec->catdir($dir, 'TestApp', 'lib'));
29
30 my @files = qw|
31     Makefile.PL
32     testapp.conf
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
56 |;
57
58 foreach my $fn (map { File::Spec->catdir(@$_) } map { [ split /\// ] } @files) {
59     test_fn($fn);
60 }
61 create_ok($_, 'My' . $_) for qw/Model View Controller/;
62
63 is system($^X, 'Makefile.PL'), 0, 'Ran Makefile.PL';
64 ok -e "Makefile", "Makefile generated";
65 is system("make"), 0, 'Run make';
66
67 my $server_script = do {
68     open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!;
69     local $/;
70     <$fh>;
71 };
72
73 ok $server_script;
74 ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
75     'SCRIPT_GEN found in generated output';
76 is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
77
78 chdir('/');
79 done_testing;
80
81 sub runperl {
82     my $comment = pop @_;
83     is system($^X, '-I', File::Spec->catdir($Bin, '..', 'lib'), @_), 0, $comment;
84 }
85
86 sub test_fn {
87     local $ENV{TEST_POD} = 1;
88     local $ENV{CATALYST_DEBUG} = 0;
89     
90     my $fn = shift;
91     ok -r $fn, "Have $fn in generated app";
92     if ($fn =~ /script/) {
93         ok -x $fn, "$fn is executable";
94     }
95     if ($fn =~ /\.p[ml]$/) {
96         runperl( '-c', $fn, "$fn compiles" );
97     }
98     if ($fn =~ /\.t$/) {
99         subtest "Generated app test: $fn", sub {
100             require $fn;
101         };
102     }
103 }
104
105 sub create_ok {
106     my ($type, $name) = @_;
107     runperl( File::Spec->catdir('script', 'testapp_create.pl'), $type, $name,
108         "'script/testapp_create.pl $type $name' ok");
109     test_fn(File::Spec->catdir('t', sprintf("%s_%s.t", $type, $name)));
110 }