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 );
11 use IPC::Open3 qw( open3 );
13 my $helper_lib = abs_path(catdir(dirname($INC{'Catalyst/Helper.pm'}), updir));
15 my $share_dir = abs_path('share');
16 plan skip_all => "No share dir at $share_dir!"
19 $ENV{CATALYST_DEVEL_SHAREDIR} = $share_dir;
20 my $instdir = tempdir(CLEANUP => 1);
22 my $MAKE = $Config{make} || 'make';
24 my $escaped_path = $instdir;
25 $escaped_path =~ s/\\/\\\\/g;
26 if ($escaped_path =~ s/ /\\ /g) {
27 $escaped_path = qq{"$escaped_path"};
30 $ENV{PERL_MM_OPT} = "INSTALL_BASE=$escaped_path";
32 if ($ENV{MAKEFLAGS}) {
33 $ENV{MAKEFLAGS} =~ s/PREFIX=[^\s]+//;
34 $ENV{MAKEFLAGS} =~ s/INSTALL_BASE=[^\s]+//;
37 my $dir = tempdir(CLEANUP => 1);
38 my $devnull = devnull;
40 note "Generated app is in $dir";
42 chdir $dir or die "Cannot chdir to $dir: $!";
45 open my $fh, '>', $devnull or die "Cannot write to $devnull: $!";
49 my $helper = Catalyst::Helper->new(
55 $helper->mk_app('TestApp');
58 my $app_dir = catdir($dir, 'TestApp');
59 chdir($app_dir) or die "Cannot chdir to $app_dir: $!";
60 lib->import(catdir($dir, 'TestApp', 'lib'));
67 lib/TestApp/Controller/Root.pm
73 root/static/images/catalyst_logo.png
74 root/static/images/btn_120x50_built.png
75 root/static/images/btn_120x50_built_shadow.png
76 root/static/images/btn_120x50_powered.png
77 root/static/images/btn_120x50_powered_shadow.png
78 root/static/images/btn_88x31_built.png
79 root/static/images/btn_88x31_built_shadow.png
80 root/static/images/btn_88x31_powered.png
81 root/static/images/btn_88x31_powered_shadow.png
85 script/testapp_fastcgi.pl
86 script/testapp_server.pl
87 script/testapp_test.pl
88 script/testapp_create.pl
91 foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @files) {
94 create_ok($_, 'My' . $_) for qw/Model View Controller/;
96 command_ok( [ $^X, 'Makefile.PL' ] );
97 ok -e "Makefile", "Makefile generated";
98 command_ok( [ $MAKE ] );
100 run_generated_component_tests();
102 my $server_script_file = catdir(qw/script testapp_server.pl/);
103 my $server_script = do {
104 open(my $fh, '<', $server_script_file) or fail $!;
110 ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/,
111 'SCRIPT_GEN found in generated output';
112 is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct';
115 open(my $fh, '>', $server_script_file) or fail $!;
118 my $helper = Catalyst::Helper->new(
126 $helper->mk_app( '.' ) or fail;
128 my $server_script_new = do {
129 open(my $fh, '<', $server_script_file) or fail $!;
134 is $server_script, $server_script_new;
136 note "Installed app is in $instdir";
137 command_ok( [ $MAKE, 'install' ] );
139 my $inst_app_dir = catdir($instdir);
140 chdir($inst_app_dir) or die "Cannot chdir to $inst_app_dir: $!";
141 lib->import(catdir($instdir, 'lib', 'perl5'));
143 my @installed_files = qw|
145 lib/perl5/TestApp/testapp.conf
146 lib/perl5/TestApp/Controller/Root.pm
147 lib/perl5/TestApp/root/static/images/catalyst_logo.png
148 lib/perl5/TestApp/root/static/images/btn_120x50_built.png
149 lib/perl5/TestApp/root/static/images/btn_120x50_built_shadow.png
150 lib/perl5/TestApp/root/static/images/btn_120x50_powered.png
151 lib/perl5/TestApp/root/static/images/btn_120x50_powered_shadow.png
152 lib/perl5/TestApp/root/static/images/btn_88x31_built.png
153 lib/perl5/TestApp/root/static/images/btn_88x31_built_shadow.png
154 lib/perl5/TestApp/root/static/images/btn_88x31_powered.png
155 lib/perl5/TestApp/root/static/images/btn_88x31_powered_shadow.png
156 lib/perl5/TestApp/root/favicon.ico
158 bin/testapp_fastcgi.pl
159 bin/testapp_server.pl
161 bin/testapp_create.pl
164 foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @installed_files) {
165 my $ffn = catfile($inst_app_dir, $fn);
166 ok -r $ffn, "'$fn' installed in correct location";
174 my $desc = shift || "Exit status ok for '@{$cmd}'";
176 open my $stdin, '<', $devnull
177 or die "Cannot read $devnull: $!";
179 my $pid = open3( $stdin, my $stdout, undef, @$cmd );
180 my $output = do { local $/; <$stdout> };
183 my $result = is $?, 0, $desc;
185 diag "output:\n$output"
192 my $comment = pop @_;
193 command_ok( [ $^X, '-I', $helper_lib, @_ ], $comment );
196 my @generated_component_tests;
200 ok -r $fn, "Have $fn in generated app";
201 if ($fn =~ /script/) {
203 skip 'Executable file flag test does not make sense on Win32', 1 if ($^O eq 'MSWin32');
204 ok -x $fn, "$fn is executable";
207 if ($fn =~ /\.p[ml]$/) {
208 runperl( '-c', $fn, "$fn compiles" );
210 # Save these till later as Catalyst::Test will only be loaded once :-/
211 push @generated_component_tests, $fn
215 sub run_generated_component_tests {
216 local $ENV{TEST_POD} = 1;
217 local $ENV{CATALYST_DEBUG} = 0;
218 foreach my $fn (@generated_component_tests) {
219 my $full_name = rel2abs($fn);
220 subtest "Generated app test: $fn", sub {
227 my ($type, $name) = @_;
228 runperl( catdir('script', 'testapp_create.pl'), $type, $name,
229 "'script/testapp_create.pl $type $name' ok");
230 test_fn( catdir('t', sprintf("%s_%s.t", lc $type, $name)));