Commit | Line | Data |
ad9d93fc |
1 | use strict; |
2 | use warnings; |
0d4859fc |
3 | use lib (); |
4c709311 |
4 | use Cwd qw( abs_path ); |
6c84e53e |
5 | use File::Spec::Functions qw( devnull catdir catfile updir rel2abs ); |
6 | use File::Temp qw( tempdir ); |
4ac8e3fd |
7 | use File::Basename qw( dirname ); |
4c709311 |
8 | use Catalyst::Helper; |
9 | use Test::More; |
29ac6b9f |
10 | use Config; |
4c709311 |
11 | |
12 | eval "use IPC::Run3"; |
13 | plan skip_all => 'These tests require IPC::Run3' if $@; |
14 | |
4ac8e3fd |
15 | my $helper_lib = abs_path(catdir(dirname($INC{'Catalyst/Helper.pm'}), updir)); |
16 | |
4c709311 |
17 | my $share_dir = abs_path('share'); |
18 | plan skip_all => "No share dir at $share_dir!" |
19 | unless -d $share_dir; |
20 | |
21 | $ENV{CATALYST_DEVEL_SHAREDIR} = $share_dir; |
62bb1d93 |
22 | my $instdir = tempdir(CLEANUP => 1); |
636c7d94 |
23 | |
e5799f98 |
24 | my $MAKE = $Config{make} || 'make'; |
25 | |
70d67e3c |
26 | my $escaped_path = $instdir; |
27 | $escaped_path =~ s/\\/\\\\/g; |
28 | if ($escaped_path =~ s/ /\\ /g) { |
29 | $escaped_path = qq{"$escaped_path"}; |
30 | } |
31 | |
32 | $ENV{PERL_MM_OPT} = "INSTALL_BASE=$escaped_path"; |
33 | |
636c7d94 |
34 | if ($ENV{MAKEFLAGS}) { |
35 | $ENV{MAKEFLAGS} =~ s/PREFIX=[^\s]+//; |
36 | $ENV{MAKEFLAGS} =~ s/INSTALL_BASE=[^\s]+//; |
37 | } |
99618c49 |
38 | |
0d4859fc |
39 | my $dir = tempdir(CLEANUP => 1); |
6c84e53e |
40 | my $devnull = devnull; |
ad9d93fc |
41 | |
15f460a5 |
42 | diag "Generated app is in $dir"; |
91497b69 |
43 | |
4c709311 |
44 | chdir $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 |
60 | my $app_dir = catdir($dir, 'TestApp'); |
4c709311 |
61 | chdir($app_dir) or die "Cannot chdir to $app_dir: $!"; |
6c84e53e |
62 | lib->import(catdir($dir, 'TestApp', 'lib')); |
ad9d93fc |
63 | |
ad9d93fc |
64 | my @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 |
93 | foreach my $fn (map { catdir(@$_) } map { [ split qr{/}, $_ ] } @files) { |
a73b3971 |
94 | test_fn($fn); |
ad9d93fc |
95 | } |
a73b3971 |
96 | create_ok($_, 'My' . $_) for qw/Model View Controller/; |
ad9d93fc |
97 | |
4c709311 |
98 | command_ok( [ $^X, 'Makefile.PL' ] ); |
15f460a5 |
99 | ok -e "Makefile", "Makefile generated"; |
e5799f98 |
100 | command_ok( [ $MAKE ] ); |
91497b69 |
101 | |
41cebeb1 |
102 | run_generated_component_tests(); |
103 | |
6c84e53e |
104 | my $server_script_file = catdir(qw/script testapp_server.pl/); |
3d3e34a0 |
105 | my $server_script = do { |
5327ff9b |
106 | open(my $fh, '<', $server_script_file) or fail $!; |
3d3e34a0 |
107 | local $/; |
108 | <$fh>; |
109 | }; |
110 | |
15f460a5 |
111 | ok $server_script; |
3d3e34a0 |
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'; |
115 | |
5327ff9b |
116 | { |
117 | open(my $fh, '>', $server_script_file) or fail $!; |
118 | print $fh "MOO\n"; |
119 | } |
120 | my $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 | |
130 | my $server_script_new = do { |
131 | open(my $fh, '<', $server_script_file) or fail $!; |
132 | local $/; |
133 | <$fh>; |
134 | }; |
135 | |
136 | is $server_script, $server_script_new; |
137 | |
62bb1d93 |
138 | diag "Installed app is in $instdir"; |
e5799f98 |
139 | command_ok( [ $MAKE, 'install' ] ); |
62bb1d93 |
140 | |
6c84e53e |
141 | my $inst_app_dir = catdir($instdir); |
62bb1d93 |
142 | chdir($inst_app_dir) or die "Cannot chdir to $inst_app_dir: $!"; |
6c84e53e |
143 | lib->import(catdir($instdir, 'lib', 'perl5')); |
62bb1d93 |
144 | |
145 | my @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 |
166 | foreach 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 |
171 | chdir('/'); |
3d3e34a0 |
172 | done_testing; |
a73b3971 |
173 | |
4c709311 |
174 | sub 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 |
189 | sub runperl { |
190 | my $comment = pop @_; |
4ac8e3fd |
191 | command_ok( [ $^X, '-I', $helper_lib, @_ ], $comment ); |
a73b3971 |
192 | } |
193 | |
41cebeb1 |
194 | my @generated_component_tests; |
195 | |
a73b3971 |
196 | sub 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 | |
213 | sub 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 | |
224 | sub 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 | } |