73bb7f61cdf81f168d4649e1a20713df0fe1d0f7
[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 Catalyst::Devel;
7
8 my $dir = tempdir(CLEANUP => 1);
9 my $devnull = File::Spec->devnull;
10
11 use Test::More;
12
13 diag "In $dir";
14
15 {
16     my $exit;
17     if ($^O eq 'MSWin32') {
18       $exit = system("cd $dir & catalyst TestApp > $devnull 2>&1");
19     }
20     else {
21       $exit = system("cd $dir; catalyst.pl TestApp > $devnull 2>&1");
22     }
23     is $exit, 0, 'Exit status ok';
24 }
25
26 chdir(File::Spec->catdir($dir, 'TestApp'));
27 lib->import(File::Spec->catdir($dir, 'TestApp', 'lib'));
28
29 my @files = qw|
30     Makefile.PL
31     testapp.conf
32     lib/TestApp.pm
33     lib/TestApp/Controller/Root.pm
34     README
35     Changes
36     t/01app.t
37     t/02pod.t
38     t/03podcoverage.t
39     root/static/images/catalyst_logo.png
40     root/static/images/btn_120x50_built.png
41     root/static/images/btn_120x50_built_shadow.png
42     root/static/images/btn_120x50_powered.png
43     root/static/images/btn_120x50_powered_shadow.png
44     root/static/images/btn_88x31_built.png
45     root/static/images/btn_88x31_built_shadow.png
46     root/static/images/btn_88x31_powered.png
47     root/static/images/btn_88x31_powered_shadow.png
48     root/favicon.ico
49     Makefile.PL
50     script/testapp_cgi.pl
51     script/testapp_fastcgi.pl
52     script/testapp_server.pl
53     script/testapp_test.pl
54     script/testapp_create.pl
55 |;
56
57 foreach my $fn (@files) {
58     ok -r $fn, "Have $fn in generated app";
59     if ($fn =~ /script/) {
60         ok -x $fn, "$fn is executable";
61     }
62 }
63
64 ## Makefile stuff
65 my $makefile_status = `$^X Makefile.PL`;
66 ok $makefile_status, "Makefile ran okay";
67 ok -e "Makefile", "Makefile exists";
68
69 is system("make"), 0, 'Run make';
70
71 {
72     local $ENV{TEST_POD} = 1;
73     local $ENV{CATALYST_DEBUG} = 0;
74     foreach my $test (grep { m|^t/| } @files) {
75         subtest "Generated app test: $test", sub {
76             require $test;
77         }
78     }
79 }
80
81 my $server_script = do {
82     open(my $fh, '<', 'script/testapp_server.pl') or die $!;
83     local $/;
84     <$fh>;
85 };
86
87 ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
88     'SCRIPT_GEN found in generated output';
89 is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
90
91 chdir('/');
92 done_testing;