lets see if we can silence the error strawberry perl is upchucking
[catagits/Catalyst-Runtime.git] / t / psgi-log.t
CommitLineData
a11b553f 1=head1 PROBLEM
2
3In https://github.com/plack/Plack/commit/cafa5db84921f020183a9c834fd6a4541e5a6b84
4chansen made a change to the FCGI handler in Plack, in which he replaced
5STDERR, STDOUT and STDIN with proper IO::Handle objects.
6
7The side effect of that change is that catalyst outputing logs on STDERR will
8no longer end up by default in the error log of the webserver when running
9under FCGI. This test tries to make sure we use the propper parts of the psgi
10environment when we output things from Catalyst::Log.
11
12There is one more "regression", and that is warnings. By using
13Catalyst::Plugin::LogWarnings, you also get those in the right place if this
14test passes :)
15
16=cut
17
2d5279cd 18use strict;
19use warnings;
20no warnings 'once';
21use FindBin;
22use lib "$FindBin::Bin/lib";
23
24use Test::More;
25
26use File::Spec;
27use File::Temp qw/ tempdir /;
28
29use TestApp;
30
31use Plack::Builder;
32use Plack::Test;
33use HTTP::Request::Common;
34
35{
36 package MockHandle;
37 use Moose;
38
39 has 'log' => (is => 'ro', isa => 'ArrayRef', traits => ['Array'], default => sub { [] },
40 handles => {
41 'logs' => 'elements',
42 'print' => 'push',
43 }
44 );
45
46 no Moose;
47}
48
c13f6e7e 49my $cmp = TestApp->debug ? '>=' : '==';
50
93c35f02 51#subtest "psgi.errors" => sub
52{
2d5279cd 53
54 my $handle = MockHandle->new();
55 my $app = builder {
56
57 enable sub {
58 my $app = shift;
59 sub {
60 my $env = shift;
61 $env->{'psgi.errors'} = $handle;
62 my $res = $app->($env);
63 return $res;
64 };
65 };
66 TestApp->psgi_app;
67 };
68
69
70 test_psgi $app, sub {
71 my $cb = shift;
310c2a39 72 my $res = $cb->(GET "/log/info");
2d5279cd 73 my @logs = $handle->logs;
c13f6e7e 74 cmp_ok(scalar(@logs), $cmp, 1, "psgi.errors: one event output");
501605db 75 like($logs[0], qr/info$/m, "psgi.errors: event matches test data") unless TestApp->debug;
2d5279cd 76 };
77};
78
93c35f02 79#subtest "psgix.logger" => sub
80{
2d5279cd 81
82 my @logs;
83 my $logger = sub {
84 push(@logs, @_);
85 };
86 my $app = builder {
87 enable sub {
88 my $app = shift;
89 sub {
90 my $env = shift;
91 $env->{'psgix.logger'} = $logger;
92 $app->($env);
93 };
94 };
95 TestApp->psgi_app;
96 };
97
98 test_psgi $app, sub {
99 my $cb = shift;
310c2a39 100 my $res = $cb->(GET "/log/info");
c13f6e7e 101 cmp_ok(scalar(@logs), $cmp, 1, "psgix.logger: one event logged");
310c2a39 102 is(scalar(grep { $_->{level} eq 'info' and $_->{message} eq 'info' } @logs),
c13f6e7e 103 1, "psgix.logger: right stuff");
2d5279cd 104 };
105};
106
107
108
109done_testing;