Properly fix the generated app test. Run tests in the generated app using the new...
[catagits/Catalyst-Devel.git] / t / generated_app.t
CommitLineData
ad9d93fc 1use strict;
2use warnings;
3
99618c49 4use File::Temp qw/ tempdir tmpnam /;
0f89baa1 5use File::Spec;
99618c49 6use Test::WWW::Mechanize;
3d3e34a0 7use Catalyst::Devel;
99618c49 8
91497b69 9my $dir = tempdir();
165233a4 10my $devnull = File::Spec->devnull;
ad9d93fc 11
12use Test::More;
91497b69 13
14diag "In $dir";
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}
91497b69 26# FIXME paths / nl work on win32
ad9d93fc 27chdir("$dir/TestApp/");
ad9d93fc 28
ad9d93fc 29my @files = qw|
30 Makefile.PL
2cb998f9 31 testapp.conf
91497b69 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
ad9d93fc 55|;
56
ad9d93fc 57foreach my $fn (@files) {
58 ok -r $fn, "Have $fn in generated app";
3d3e34a0 59 if ($fn =~ /script/) {
60 ok -x $fn, "$fn is executable";
61 }
ad9d93fc 62}
63
20859489 64## Makefile stuff
65my $makefile_status = `$^X Makefile.PL`;
66ok $makefile_status, "Makefile ran okay";
67ok -e "Makefile", "Makefile exists";
91497b69 68
69is system("make"), 0, 'Run make';
70
71{
72 local $ENV{TEST_POD} = 1;
73
74 foreach my $test (grep { m|^t/| } @files) {
75 subtest "Generated app test: $test", sub {
76 require $test;
77 }
78 }
79}
20859489 80
99618c49 81## Moosey server tests - kmx++
0f89baa1 82my $server_path = File::Spec->catfile('script', 'testapp_server.pl');
165233a4 83my $port = int(rand(10000)) + 40000; # get random port between 40000-50000
99618c49 84
165233a4 85my $childpid = fork();
86die "fork() error, cannot continue" unless defined($childpid);
99618c49 87
88if ($childpid == 0) {
165233a4 89 system("$^X $server_path -p $port > $devnull 2>&1");
90 exit; # just for sure; we should never got here
99618c49 91}
92
93sleep 10; #wait for catalyst application to start
94my $mech = Test::WWW::Mechanize->new;
95$mech->get_ok( "http://localhost:" . $port );
96
97kill 'KILL', $childpid;
165233a4 98
3d3e34a0 99my $server_script = do {
100 open(my $fh, '<', 'script/testapp_server.pl') or die $!;
101 local $/;
102 <$fh>;
103};
104
105ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
106 'SCRIPT_GEN found in generated output';
107is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
108
91497b69 109chdir('/');
110
3d3e34a0 111done_testing;
0f89baa1 112