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; |
11 | |
12 | eval "use IPC::Run3"; |
13 | plan skip_all => 'These tests require IPC::Run3' if $@; |
14 | |
15 | my $share_dir = abs_path('share'); |
16 | plan skip_all => "No share dir at $share_dir!" |
17 | unless -d $share_dir; |
18 | |
19 | $ENV{CATALYST_DEVEL_SHAREDIR} = $share_dir; |
99618c49 |
20 | |
0d4859fc |
21 | my $dir = tempdir(CLEANUP => 1); |
165233a4 |
22 | my $devnull = File::Spec->devnull; |
ad9d93fc |
23 | |
15f460a5 |
24 | diag "Generated app is in $dir"; |
91497b69 |
25 | |
4c709311 |
26 | chdir $dir or die "Cannot chdir to $dir: $!"; |
27 | |
ad9d93fc |
28 | { |
4c709311 |
29 | open my $fh, '>', $devnull or die "Cannot write to $devnull: $!"; |
30 | |
31 | local *STDOUT = $fh; |
32 | |
33 | my $helper = Catalyst::Helper->new( |
34 | { |
35 | name => 'TestApp', |
36 | } |
37 | ); |
38 | |
39 | $helper->mk_app('TestApp'); |
ad9d93fc |
40 | } |
0d4859fc |
41 | |
4c709311 |
42 | my $app_dir = File::Spec->catdir($dir, 'TestApp'); |
43 | chdir($app_dir) or die "Cannot chdir to $app_dir: $!"; |
0d4859fc |
44 | lib->import(File::Spec->catdir($dir, 'TestApp', 'lib')); |
ad9d93fc |
45 | |
ad9d93fc |
46 | my @files = qw| |
47 | Makefile.PL |
2cb998f9 |
48 | testapp.conf |
91497b69 |
49 | lib/TestApp.pm |
50 | lib/TestApp/Controller/Root.pm |
51 | README |
52 | Changes |
53 | t/01app.t |
54 | t/02pod.t |
55 | t/03podcoverage.t |
56 | root/static/images/catalyst_logo.png |
57 | root/static/images/btn_120x50_built.png |
58 | root/static/images/btn_120x50_built_shadow.png |
59 | root/static/images/btn_120x50_powered.png |
60 | root/static/images/btn_120x50_powered_shadow.png |
61 | root/static/images/btn_88x31_built.png |
62 | root/static/images/btn_88x31_built_shadow.png |
63 | root/static/images/btn_88x31_powered.png |
64 | root/static/images/btn_88x31_powered_shadow.png |
65 | root/favicon.ico |
66 | Makefile.PL |
67 | script/testapp_cgi.pl |
68 | script/testapp_fastcgi.pl |
69 | script/testapp_server.pl |
70 | script/testapp_test.pl |
71 | script/testapp_create.pl |
ad9d93fc |
72 | |; |
73 | |
a73b3971 |
74 | foreach my $fn (map { File::Spec->catdir(@$_) } map { [ split /\// ] } @files) { |
75 | test_fn($fn); |
ad9d93fc |
76 | } |
a73b3971 |
77 | create_ok($_, 'My' . $_) for qw/Model View Controller/; |
ad9d93fc |
78 | |
4c709311 |
79 | command_ok( [ $^X, 'Makefile.PL' ] ); |
15f460a5 |
80 | ok -e "Makefile", "Makefile generated"; |
4c709311 |
81 | command_ok( [ 'make' ] ); |
91497b69 |
82 | |
41cebeb1 |
83 | run_generated_component_tests(); |
84 | |
3d3e34a0 |
85 | my $server_script = do { |
15f460a5 |
86 | open(my $fh, '<', File::Spec->catdir(qw/script testapp_server.pl/)) or fail $!; |
3d3e34a0 |
87 | local $/; |
88 | <$fh>; |
89 | }; |
90 | |
15f460a5 |
91 | ok $server_script; |
3d3e34a0 |
92 | ok $server_script =~ qr/CATALYST_SCRIPT_GEN}\s+=\s+(\d+)/, |
93 | 'SCRIPT_GEN found in generated output'; |
94 | is $1, $Catalyst::Devel::CATALYST_SCRIPT_GEN, 'Script gen correct'; |
95 | |
91497b69 |
96 | chdir('/'); |
3d3e34a0 |
97 | done_testing; |
a73b3971 |
98 | |
4c709311 |
99 | sub command_ok { |
100 | my $cmd = shift; |
101 | my $desc = shift; |
102 | |
103 | my $stdout; |
104 | my $stderr; |
105 | run3( $cmd, \undef, \$stdout, \$stderr ); |
106 | |
107 | $desc ||= "Exit status ok for '@{$cmd}'"; |
108 | unless ( is $? >> 8, 0, $desc ) { |
109 | diag "STDOUT:\n$stdout" if defined $stdout; |
110 | diag "STDERR:\n$stderr" if defined $stderr; |
111 | } |
112 | } |
113 | |
a73b3971 |
114 | sub runperl { |
115 | my $comment = pop @_; |
4c709311 |
116 | command_ok( [ $^X, '-I', File::Spec->catdir($Bin, '..', 'lib'), @_ ], $comment ); |
a73b3971 |
117 | } |
118 | |
41cebeb1 |
119 | my @generated_component_tests; |
120 | |
a73b3971 |
121 | sub test_fn { |
a73b3971 |
122 | my $fn = shift; |
123 | ok -r $fn, "Have $fn in generated app"; |
124 | if ($fn =~ /script/) { |
125 | ok -x $fn, "$fn is executable"; |
126 | } |
127 | if ($fn =~ /\.p[ml]$/) { |
128 | runperl( '-c', $fn, "$fn compiles" ); |
129 | } |
41cebeb1 |
130 | # Save these till later as Catalyst::Test will only be loaded once :-/ |
131 | push @generated_component_tests, $fn |
132 | if $fn =~ /\.t$/; |
133 | } |
134 | |
135 | sub run_generated_component_tests { |
e3eb9f88 |
136 | local $ENV{TEST_POD} = 1; |
137 | local $ENV{CATALYST_DEBUG} = 0; |
41cebeb1 |
138 | foreach my $fn (@generated_component_tests) { |
a73b3971 |
139 | subtest "Generated app test: $fn", sub { |
140 | require $fn; |
141 | }; |
142 | } |
143 | } |
144 | |
145 | sub create_ok { |
146 | my ($type, $name) = @_; |
147 | runperl( File::Spec->catdir('script', 'testapp_create.pl'), $type, $name, |
148 | "'script/testapp_create.pl $type $name' ok"); |
4c709311 |
149 | test_fn(File::Spec->catdir('t', sprintf("%s_%s.t", lc $type, $name))); |
a73b3971 |
150 | } |