Bigger than the current version
[catagits/Catalyst-Devel.git] / t / generated_app.t
1 use strict;
2 use warnings;
3
4 use File::Temp qw/ tempdir tmpnam /;
5 use File::Spec;
6 use Test::WWW::Mechanize;
7
8 my $dir = tempdir(); # CLEANUP => 1 );
9 my $devnull = File::Spec->devnull;
10
11 use Test::More;
12 {
13     # Check exit status here
14     if ($^O eq 'MSWin32') {
15       system("cd $dir & catalyst TestApp > $devnull 2>&1");
16     }
17     else {
18       system("cd $dir; catalyst.pl TestApp > $devnull 2>&1");
19     }
20 }
21 # Fix paths / nl work on win32
22 chdir("$dir/TestApp/");
23
24 # Ok, this is lame.. Also, check +x permissions?
25 my @files = qw|
26     Makefile.PL
27     testapp.conf
28 lib/TestApp.pm
29 lib/TestApp/Controller/Root.pm
30 README
31 Changes
32 t/01app.t
33 t/02pod.t
34 t/03podcoverage.t
35 root/static/images/catalyst_logo.png
36 root/static/images/btn_120x50_built.png
37 root/static/images/btn_120x50_built_shadow.png
38 root/static/images/btn_120x50_powered.png
39 root/static/images/btn_120x50_powered_shadow.png
40 root/static/images/btn_88x31_built.png
41 root/static/images/btn_88x31_built_shadow.png
42 root/static/images/btn_88x31_powered.png
43 root/static/images/btn_88x31_powered_shadow.png
44 root/favicon.ico
45 Makefile.PL
46 script/testapp_cgi.pl
47 script/testapp_fastcgi.pl
48 script/testapp_server.pl
49 script/testapp_test.pl
50 script/testapp_create.pl
51 |;
52
53 plan 'tests' => scalar @files + 4;
54
55 foreach my $fn (@files) {
56     ok -r $fn, "Have $fn in generated app";
57 }
58
59 ## Makefile stuff
60 my $makefile_status = `$^X Makefile.PL`;
61 ok $makefile_status, "Makefile ran okay";
62 ok -e "Makefile", "Makefile exists";
63 my $newapp_test_status = `prove -l t/ 2> $devnull`;
64 ok $newapp_test_status, "Tests ran okay";
65 #is $newapp_test_status, ;
66
67 ## Moosey server tests - kmx++
68 my $server_path   = File::Spec->catfile('script', 'testapp_server.pl');
69 my $port = int(rand(10000)) + 40000; # get random port between 40000-50000
70
71 my $childpid = fork();
72 die "fork() error, cannot continue" unless defined($childpid);
73
74 if ($childpid == 0) {
75   system("$^X $server_path -p $port > $devnull 2>&1");
76   exit; # just for sure; we should never got here
77 }
78
79 sleep 10; #wait for catalyst application to start
80 my $mech = Test::WWW::Mechanize->new;
81 $mech->get_ok( "http://localhost:" . $port );
82
83 kill 'KILL', $childpid;
84
85