File: psgi_file.t

package info (click to toggle)
libcatalyst-perl 5.90124-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,992 kB
  • sloc: perl: 11,123; makefile: 7
file content (62 lines) | stat: -rw-r--r-- 1,676 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;
use Test::More;
use FindBin;
use lib "$FindBin::Bin/../lib";
use File::Temp qw/ tempdir /;
use TestApp;
use File::Spec;
use Carp qw/croak/;

my $home = tempdir( CLEANUP => 1 );
my $path = File::Spec->catfile($home, 'testapp.psgi');
open(my $psgi, '>', $path)
    or die;
print $psgi q{
use strict;
use warnings;
use TestApp;

TestApp->psgi_app;
};
close($psgi);

my ($saved_stdout, $saved_stderr);
my $stdout = !open( $saved_stdout, '>&'. STDOUT->fileno );
my $stderr = !open( $saved_stderr, '>&'. STDERR->fileno );
open( STDOUT, '+>', undef )
            or croak("Can't reopen stdout to /dev/null");
open( STDERR, '+>', undef )
            or croak("Can't reopen stdout to /dev/null");
# Check we wrote out something that compiles
system($^X, '-I', "$FindBin::Bin/../lib", '-c', $path)
    ? fail('.psgi does not compile')
    : pass('.psgi compiles');

if ($stdout) {
    open( STDOUT, '>&'. fileno($saved_stdout) );
}
if ($stderr) {
    open( STDERR, '>&'. fileno($saved_stderr) );
}

# NOTE - YOU *CANNOT* do something like:
#my $psgi_ref = require $path;
# otherwise this test passes!
# I don't exactly know why that is yet, however, to be safe for future, that
# is why this test writes out its own .psgi file in a temp directory - so that that
# path has never been require'd before, and will never be require'd again..

local TestApp->config->{home} = $home;

my $failed = 0;
eval {
    # Catch infinite recursion (or anything else)
    local $SIG{__WARN__} = sub { warn(@_); $failed = 1; die; };
    TestApp->_finalized_psgi_app;
};
ok(!$@, 'No exception')
    or diag $@;
ok(!$failed, 'TestApp->_finalized_psgi_app works');

done_testing;