fix psgi_file test without Catalyst installed
[catagits/Catalyst-Runtime.git] / t / aggregate / psgi_file.t
CommitLineData
c234ca55 1use strict;
2use warnings;
3use Test::More;
4use FindBin;
5use lib "$FindBin::Bin/../lib";
6use File::Temp qw/ tempdir /;
7use TestApp;
8use File::Spec;
3d5bcdf4 9use Carp qw/croak/;
7991d6fc 10use IPC::Open3 qw(open3);
c234ca55 11
12my $home = tempdir( CLEANUP => 1 );
13my $path = File::Spec->catfile($home, 'testapp.psgi');
14open(my $psgi, '>', $path)
15 or die;
16print $psgi q{
17use strict;
18use warnings;
19use TestApp;
20
8f076801 21TestApp->psgi_app;
c234ca55 22};
23close($psgi);
3d5bcdf4 24
e60dd0d7 25my @command = ($^X, '-I', "$FindBin::Bin/../lib", '-I', "$FindBin::Bin/../../lib", '-c', $path);
7991d6fc 26open my $stdin, '<', File::Spec->devnull;
e60dd0d7 27my $pid = open3 $stdin, my $stdout, undef, @command;
7991d6fc 28my $output = do { local $/; <$stdout> };
29waitpid $pid, 0;
30
31ok $? == 0, '.psgi compiles'
32 or diag $output;
3d5bcdf4 33
c234ca55 34# NOTE - YOU *CANNOT* do something like:
35#my $psgi_ref = require $path;
36# otherwise this test passes!
37# I don't exactly know why that is yet, however, to be safe for future, that
e6006848 38# is why this test writes out its own .psgi file in a temp directory - so that that
c234ca55 39# path has never been require'd before, and will never be require'd again..
40
41local TestApp->config->{home} = $home;
42
43my $failed = 0;
44eval {
45 # Catch infinite recursion (or anything else)
46 local $SIG{__WARN__} = sub { warn(@_); $failed = 1; die; };
8f076801 47 TestApp->_finalized_psgi_app;
c234ca55 48};
49ok(!$@, 'No exception')
50 or diag $@;
8f076801 51ok(!$failed, 'TestApp->_finalized_psgi_app works');
c234ca55 52
53done_testing;