Commit | Line | Data |
c234ca55 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | use FindBin; |
5 | use lib "$FindBin::Bin/../lib"; |
6 | use File::Temp qw/ tempdir /; |
7 | use TestApp; |
8 | use File::Spec; |
9 | |
10 | my $home = tempdir( CLEANUP => 1 ); |
11 | my $path = File::Spec->catfile($home, 'testapp.psgi'); |
12 | open(my $psgi, '>', $path) |
13 | or die; |
14 | print $psgi q{ |
15 | use strict; |
16 | use warnings; |
17 | use TestApp; |
18 | |
8f076801 |
19 | TestApp->psgi_app; |
c234ca55 |
20 | }; |
21 | close($psgi); |
22 | # Check we wrote out something that compiles |
23 | system($^X, '-I', "$FindBin::Bin/../lib", '-c', $path) |
24 | ? fail('.psgi does not compile') |
25 | : pass('.psgi compiles'); |
26 | |
27 | # NOTE - YOU *CANNOT* do something like: |
28 | #my $psgi_ref = require $path; |
29 | # otherwise this test passes! |
30 | # I don't exactly know why that is yet, however, to be safe for future, that |
31 | # is why this test writes out it's own .psgi file in a temp directory - so that that |
32 | # path has never been require'd before, and will never be require'd again.. |
33 | |
34 | local TestApp->config->{home} = $home; |
35 | |
36 | my $failed = 0; |
37 | eval { |
38 | # Catch infinite recursion (or anything else) |
39 | local $SIG{__WARN__} = sub { warn(@_); $failed = 1; die; }; |
8f076801 |
40 | TestApp->_finalized_psgi_app; |
c234ca55 |
41 | }; |
42 | ok(!$@, 'No exception') |
43 | or diag $@; |
8f076801 |
44 | ok(!$failed, 'TestApp->_finalized_psgi_app works'); |
c234ca55 |
45 | |
46 | done_testing; |