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