list the authordeps in a cpanfile for easier installation
[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
93c35f02 49#subtest "psgi.errors" => sub
50{
2d5279cd 51
52 my $handle = MockHandle->new();
53 my $app = builder {
54
55 enable sub {
56 my $app = shift;
57 sub {
58 my $env = shift;
59 $env->{'psgi.errors'} = $handle;
60 my $res = $app->($env);
61 return $res;
62 };
63 };
64 TestApp->psgi_app;
65 };
66
67
68 test_psgi $app, sub {
69 my $cb = shift;
70 my $res = $cb->(GET "/log/debug");
71 my @logs = $handle->logs;
93c35f02 72 is(scalar(@logs), 1, "psgi.errors: one event output");
73 like($logs[0], qr/debug$/, "psgi.errors: event matches test data");
2d5279cd 74 };
75};
76
93c35f02 77#subtest "psgix.logger" => sub
78{
2d5279cd 79
80 my @logs;
81 my $logger = sub {
82 push(@logs, @_);
83 };
84 my $app = builder {
85 enable sub {
86 my $app = shift;
87 sub {
88 my $env = shift;
89 $env->{'psgix.logger'} = $logger;
90 $app->($env);
91 };
92 };
93 TestApp->psgi_app;
94 };
95
96 test_psgi $app, sub {
97 my $cb = shift;
98 my $res = $cb->(GET "/log/debug");
93c35f02 99 is(scalar(@logs), 1, "psgix.logger: one event logged");
100 is_deeply($logs[0], { level => 'debug', message => "debug" }, "psgix.logger: right stuff");
2d5279cd 101 };
102};
103
104
105
106done_testing;