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