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