escape INSTALL_BASE properly for EUMM to parse
[catagits/Catalyst-Devel.git] / t / generated_app.t
CommitLineData
ad9d93fc 1use strict;
2use warnings;
0d4859fc 3use lib ();
4c709311 4use Cwd qw( abs_path );
6c84e53e 5use File::Spec::Functions qw( devnull catdir catfile updir rel2abs );
6use File::Temp qw( tempdir );
4ac8e3fd 7use File::Basename qw( dirname );
4c709311 8use Catalyst::Helper;
9use Test::More;
29ac6b9f 10use Config;
4c709311 11
12eval "use IPC::Run3";
13plan skip_all => 'These tests require IPC::Run3' if $@;
14
4ac8e3fd 15my $helper_lib = abs_path(catdir(dirname($INC{'Catalyst/Helper.pm'}), updir));
16
4c709311 17my $share_dir = abs_path('share');
18plan skip_all => "No share dir at $share_dir!"
19 unless -d $share_dir;
20
21$ENV{CATALYST_DEVEL_SHAREDIR} = $share_dir;
62bb1d93 22my $instdir = tempdir(CLEANUP => 1);
636c7d94 23
e5799f98 24my $MAKE = $Config{make} || 'make';
25
70d67e3c 26my $escaped_path = $instdir;
27$escaped_path =~ s/\\/\\\\/g;
28if ($escaped_path =~ s/ /\\ /g) {
29 $escaped_path = qq{"$escaped_path"};
30}
31
32$ENV{PERL_MM_OPT} = "INSTALL_BASE=$escaped_path";
33
636c7d94 34if ($ENV{MAKEFLAGS}) {
35 $ENV{MAKEFLAGS} =~ s/PREFIX=[^\s]+//;
36 $ENV{MAKEFLAGS} =~ s/INSTALL_BASE=[^\s]+//;
37}
99618c49 38
0d4859fc 39my $dir = tempdir(CLEANUP => 1);
6c84e53e 40my $devnull = devnull;
ad9d93fc 41
15f460a5 42diag "Generated app is in $dir";
91497b69 43
4c709311 44chdir $dir or die "Cannot chdir to $dir: $!";
45
ad9d93fc 46{
4c709311 47 open my $fh, '>', $devnull or die "Cannot write to $devnull: $!";
48
49 local *STDOUT = $fh;
50
51 my $helper = Catalyst::Helper->new(
52 {
53 name => 'TestApp',
54 }
55 );
56
57 $helper->mk_app('TestApp');
ad9d93fc 58}
0d4859fc 59
6c84e53e 60my $app_dir = catdir($dir, 'TestApp');
4c709311 61chdir($app_dir) or die "Cannot chdir to $app_dir: $!";
6c84e53e 62lib->import(catdir($dir, 'TestApp', 'lib'));
ad9d93fc 63
ad9d93fc 64my @files = qw|
65 Makefile.PL
2cb998f9 66 testapp.conf
b769c101 67 testapp.psgi
91497b69 68 lib/TestApp.pm
69 lib/TestApp/Controller/Root.pm
70 README
71 Changes
72 t/01app.t
73 t/02pod.t
74 t/03podcoverage.t
75 root/static/images/catalyst_logo.png
76 root/static/images/btn_120x50_built.png
77 root/static/images/btn_120x50_built_shadow.png
78 root/static/images/btn_120x50_powered.png
79 root/static/images/btn_120x50_powered_shadow.png
80 root/static/images/btn_88x31_built.png
81 root/static/images/btn_88x31_built_shadow.png
82 root/static/images/btn_88x31_powered.png
83 root/static/images/btn_88x31_powered_shadow.png
84 root/favicon.ico
85 Makefile.PL
86 script/testapp_cgi.pl
87 script/testapp_fastcgi.pl
88 script/testapp_server.pl
89 script/testapp_test.pl
90 script/testapp_create.pl
ad9d93fc 91|;
92
6c84e53e 93foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @files) {
a73b3971 94 test_fn($fn);
ad9d93fc 95}
a73b3971 96create_ok($_, 'My' . $_) for qw/Model View Controller/;
ad9d93fc 97
4c709311 98command_ok( [ $^X, 'Makefile.PL' ] );
15f460a5 99ok -e "Makefile", "Makefile generated";
e5799f98 100command_ok( [ $MAKE ] );
91497b69 101
41cebeb1 102run_generated_component_tests();
103
6c84e53e 104my $server_script_file = catdir(qw/script testapp_server.pl/);
3d3e34a0 105my $server_script = do {
5327ff9b 106 open(my $fh, '<', $server_script_file) or fail $!;
3d3e34a0 107 local $/;
108 <$fh>;
109};
110
15f460a5 111ok $server_script;
3d3e34a0 112ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
113 'SCRIPT_GEN found in generated output';
114is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
115
5327ff9b 116{
117 open(my $fh, '>', $server_script_file) or fail $!;
118 print $fh "MOO\n";
119}
120my $helper = Catalyst::Helper->new(
121 {
122 '.newfiles' => 0,
123 'makefile' => 0,
124 'scripts' => 1,
125 name => '.',
126 }
127);
128$helper->mk_app( '.' ) or fail;
129
130my $server_script_new = do {
131 open(my $fh, '<', $server_script_file) or fail $!;
132 local $/;
133 <$fh>;
134};
135
136is $server_script, $server_script_new;
137
62bb1d93 138diag "Installed app is in $instdir";
e5799f98 139command_ok( [ $MAKE, 'install' ] );
62bb1d93 140
6c84e53e 141my $inst_app_dir = catdir($instdir);
62bb1d93 142chdir($inst_app_dir) or die "Cannot chdir to $inst_app_dir: $!";
6c84e53e 143lib->import(catdir($instdir, 'lib', 'perl5'));
62bb1d93 144
145my @installed_files = qw|
146 lib/perl5/TestApp.pm
147 lib/perl5/TestApp/testapp.conf
148 lib/perl5/TestApp/Controller/Root.pm
149 lib/perl5/TestApp/root/static/images/catalyst_logo.png
150 lib/perl5/TestApp/root/static/images/btn_120x50_built.png
151 lib/perl5/TestApp/root/static/images/btn_120x50_built_shadow.png
152 lib/perl5/TestApp/root/static/images/btn_120x50_powered.png
153 lib/perl5/TestApp/root/static/images/btn_120x50_powered_shadow.png
154 lib/perl5/TestApp/root/static/images/btn_88x31_built.png
155 lib/perl5/TestApp/root/static/images/btn_88x31_built_shadow.png
156 lib/perl5/TestApp/root/static/images/btn_88x31_powered.png
157 lib/perl5/TestApp/root/static/images/btn_88x31_powered_shadow.png
158 lib/perl5/TestApp/root/favicon.ico
159 bin/testapp_cgi.pl
160 bin/testapp_fastcgi.pl
161 bin/testapp_server.pl
162 bin/testapp_test.pl
163 bin/testapp_create.pl
164|;
165
6c84e53e 166foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @installed_files) {
167 my $ffn = catfile($inst_app_dir, $fn);
62bb1d93 168 ok -r $ffn, "'$fn' installed in correct location";
169}
170
91497b69 171chdir('/');
3d3e34a0 172done_testing;
a73b3971 173
4c709311 174sub command_ok {
175 my $cmd = shift;
176 my $desc = shift;
177
178 my $stdout;
179 my $stderr;
180 run3( $cmd, \undef, \$stdout, \$stderr );
181
182 $desc ||= "Exit status ok for '@{$cmd}'";
183 unless ( is $? >> 8, 0, $desc ) {
184 diag "STDOUT:\n$stdout" if defined $stdout;
185 diag "STDERR:\n$stderr" if defined $stderr;
186 }
187}
188
a73b3971 189sub runperl {
190 my $comment = pop @_;
4ac8e3fd 191 command_ok( [ $^X, '-I', $helper_lib, @_ ], $comment );
a73b3971 192}
193
41cebeb1 194my @generated_component_tests;
195
a73b3971 196sub test_fn {
a73b3971 197 my $fn = shift;
198 ok -r $fn, "Have $fn in generated app";
199 if ($fn =~ /script/) {
29ac6b9f 200 SKIP: {
201 skip 'Executable file flag test does not make sense on Win32', 1 if ($^O eq 'MSWin32');
202 ok -x $fn, "$fn is executable";
203 }
a73b3971 204 }
205 if ($fn =~ /\.p[ml]$/) {
206 runperl( '-c', $fn, "$fn compiles" );
207 }
41cebeb1 208 # Save these till later as Catalyst::Test will only be loaded once :-/
209 push @generated_component_tests, $fn
210 if $fn =~ /\.t$/;
211}
212
213sub run_generated_component_tests {
e3eb9f88 214 local $ENV{TEST_POD} = 1;
215 local $ENV{CATALYST_DEBUG} = 0;
41cebeb1 216 foreach my $fn (@generated_component_tests) {
6c84e53e 217 my $full_name = rel2abs($fn);
a73b3971 218 subtest "Generated app test: $fn", sub {
6c84e53e 219 do $full_name;
a73b3971 220 };
221 }
222}
223
224sub create_ok {
225 my ($type, $name) = @_;
6c84e53e 226 runperl( catdir('script', 'testapp_create.pl'), $type, $name,
a73b3971 227 "'script/testapp_create.pl $type $name' ok");
6c84e53e 228 test_fn( catdir('t', sprintf("%s_%s.t", lc $type, $name)));
a73b3971 229}