4 use Cwd qw( abs_path );
5 use File::Spec::Functions qw( devnull catdir catfile updir rel2abs );
6 use File::Temp qw( tempdir );
7 use File::Basename qw( dirname );
13 plan skip_all => 'These tests require IPC::Run3' if $@;
15 my $helper_lib = abs_path(catdir(dirname($INC{'Catalyst/Helper.pm'}), updir));
17 my $share_dir = abs_path('share');
18 plan skip_all => "No share dir at $share_dir!"
21 $ENV{CATALYST_DEVEL_SHAREDIR} = $share_dir;
22 my $instdir = tempdir(CLEANUP => 1);
24 my $MAKE = $Config{make} || 'make';
26 my $escaped_path = $instdir;
27 $escaped_path =~ s/\\/\\\\/g;
28 if ($escaped_path =~ s/ /\\ /g) {
29 $escaped_path = qq{"$escaped_path"};
32 $ENV{PERL_MM_OPT} = "INSTALL_BASE=$escaped_path";
34 if ($ENV{MAKEFLAGS}) {
35 $ENV{MAKEFLAGS} =~ s/PREFIX=[^\s]+//;
36 $ENV{MAKEFLAGS} =~ s/INSTALL_BASE=[^\s]+//;
39 my $dir = tempdir(CLEANUP => 1);
40 my $devnull = devnull;
42 note "Generated app is in $dir";
44 chdir $dir or die "Cannot chdir to $dir: $!";
47 open my $fh, '>', $devnull or die "Cannot write to $devnull: $!";
51 my $helper = Catalyst::Helper->new(
57 $helper->mk_app('TestApp');
60 my $app_dir = catdir($dir, 'TestApp');
61 chdir($app_dir) or die "Cannot chdir to $app_dir: $!";
62 lib->import(catdir($dir, 'TestApp', 'lib'));
69 lib/TestApp/Controller/Root.pm
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
87 script/testapp_fastcgi.pl
88 script/testapp_server.pl
89 script/testapp_test.pl
90 script/testapp_create.pl
93 foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @files) {
96 create_ok($_, 'My' . $_) for qw/Model View Controller/;
98 command_ok( [ $^X, 'Makefile.PL' ] );
99 ok -e "Makefile", "Makefile generated";
100 command_ok( [ $MAKE ] );
102 run_generated_component_tests();
104 my $server_script_file = catdir(qw/script testapp_server.pl/);
105 my $server_script = do {
106 open(my $fh, '<', $server_script_file) or fail $!;
112 ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
113 'SCRIPT_GEN found in generated output';
114 is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
117 open(my $fh, '>', $server_script_file) or fail $!;
120 my $helper = Catalyst::Helper->new(
128 $helper->mk_app( '.' ) or fail;
130 my $server_script_new = do {
131 open(my $fh, '<', $server_script_file) or fail $!;
136 is $server_script, $server_script_new;
138 note "Installed app is in $instdir";
139 command_ok( [ $MAKE, 'install' ] );
141 my $inst_app_dir = catdir($instdir);
142 chdir($inst_app_dir) or die "Cannot chdir to $inst_app_dir: $!";
143 lib->import(catdir($instdir, 'lib', 'perl5'));
145 my @installed_files = qw|
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
160 bin/testapp_fastcgi.pl
161 bin/testapp_server.pl
163 bin/testapp_create.pl
166 foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @installed_files) {
167 my $ffn = catfile($inst_app_dir, $fn);
168 ok -r $ffn, "'$fn' installed in correct location";
180 run3( $cmd, \undef, \$stdout, \$stderr );
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;
190 my $comment = pop @_;
191 command_ok( [ $^X, '-I', $helper_lib, @_ ], $comment );
194 my @generated_component_tests;
198 ok -r $fn, "Have $fn in generated app";
199 if ($fn =~ /script/) {
201 skip 'Executable file flag test does not make sense on Win32', 1 if ($^O eq 'MSWin32');
202 ok -x $fn, "$fn is executable";
205 if ($fn =~ /\.p[ml]$/) {
206 runperl( '-c', $fn, "$fn compiles" );
208 # Save these till later as Catalyst::Test will only be loaded once :-/
209 push @generated_component_tests, $fn
213 sub run_generated_component_tests {
214 local $ENV{TEST_POD} = 1;
215 local $ENV{CATALYST_DEBUG} = 0;
216 foreach my $fn (@generated_component_tests) {
217 my $full_name = rel2abs($fn);
218 subtest "Generated app test: $fn", sub {
225 my ($type, $name) = @_;
226 runperl( catdir('script', 'testapp_create.pl'), $type, $name,
227 "'script/testapp_create.pl $type $name' ok");
228 test_fn( catdir('t', sprintf("%s_%s.t", lc $type, $name)));