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