Doc changes to Upgrading and PSGI.
[catagits/Catalyst-Runtime.git] / t / aggregate / psgi_file.t
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
19 TestApp->psgi_app;
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 its 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; };
40     TestApp->_finalized_psgi_app;
41 };
42 ok(!$@, 'No exception')
43     or diag $@;
44 ok(!$failed, 'TestApp->_finalized_psgi_app works');
45
46 done_testing;