Test uri_for with path = 0
[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/;
c234ca55 10
11my $home = tempdir( CLEANUP => 1 );
12my $path = File::Spec->catfile($home, 'testapp.psgi');
13open(my $psgi, '>', $path)
14 or die;
15print $psgi q{
16use strict;
17use warnings;
18use TestApp;
19
8f076801 20TestApp->psgi_app;
c234ca55 21};
22close($psgi);
3d5bcdf4 23
24my ($saved_stdout, $saved_stderr);
4c0f8870 25my $stdout = !open( $saved_stdout, '>&'. STDOUT->fileno );
26my $stderr = !open( $saved_stderr, '>&'. STDERR->fileno );
3d5bcdf4 27open( STDOUT, '+>', undef )
28 or croak("Can't reopen stdout to /dev/null");
29open( STDERR, '+>', undef )
30 or croak("Can't reopen stdout to /dev/null");
c234ca55 31# Check we wrote out something that compiles
32system($^X, '-I', "$FindBin::Bin/../lib", '-c', $path)
33 ? fail('.psgi does not compile')
34 : pass('.psgi compiles');
35
4c0f8870 36if ($stdout) {
37 open( STDOUT, '>&'. fileno($saved_stdout) );
38}
39if ($stderr) {
40 open( STDERR, '>&'. fileno($saved_stderr) );
41}
3d5bcdf4 42
c234ca55 43# NOTE - YOU *CANNOT* do something like:
44#my $psgi_ref = require $path;
45# otherwise this test passes!
46# I don't exactly know why that is yet, however, to be safe for future, that
e6006848 47# is why this test writes out its own .psgi file in a temp directory - so that that
c234ca55 48# path has never been require'd before, and will never be require'd again..
49
50local TestApp->config->{home} = $home;
51
52my $failed = 0;
53eval {
54 # Catch infinite recursion (or anything else)
55 local $SIG{__WARN__} = sub { warn(@_); $failed = 1; die; };
8f076801 56 TestApp->_finalized_psgi_app;
c234ca55 57};
58ok(!$@, 'No exception')
59 or diag $@;
8f076801 60ok(!$failed, 'TestApp->_finalized_psgi_app works');
c234ca55 61
62done_testing;