5 use lib "$FindBin::Bin/../lib";
6 use File::Temp qw/ tempdir /;
11 my $home = tempdir( CLEANUP => 1 );
12 my $path = File::Spec->catfile($home, 'testapp.psgi');
13 open(my $psgi, '>', $path)
24 my ($saved_stdout, $saved_stderr);
25 open( $saved_stdout, '>&'. STDOUT->fileno )
26 or croak("Can't dup stdout: $!");
27 open( $saved_stderr, '>&'. STDERR->fileno )
28 or croak("Can't dup stderr: $!");
29 open( STDOUT, '+>', undef )
30 or croak("Can't reopen stdout to /dev/null");
31 open( STDERR, '+>', undef )
32 or croak("Can't reopen stdout to /dev/null");
33 # Check we wrote out something that compiles
34 system($^X, '-I', "$FindBin::Bin/../lib", '-c', $path)
35 ? fail('.psgi does not compile')
36 : pass('.psgi compiles');
38 open( STDOUT, '>&'. fileno($saved_stdout) )
39 or croak("Can't restore stdout: $!");
40 open( STDERR, '>&'. fileno($saved_stderr) )
41 or croak("Can't restore stderr: $!");
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
47 # is why this test writes out its own .psgi file in a temp directory - so that that
48 # path has never been require'd before, and will never be require'd again..
50 local TestApp->config->{home} = $home;
54 # Catch infinite recursion (or anything else)
55 local $SIG{__WARN__} = sub { warn(@_); $failed = 1; die; };
56 TestApp->_finalized_psgi_app;
58 ok(!$@, 'No exception')
60 ok(!$failed, 'TestApp->_finalized_psgi_app works');