File: 04_exceptions_warn.t

package info (click to toggle)
libdancer-perl 1.3521%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,460 kB
  • sloc: perl: 7,436; xml: 2,211; sh: 54; makefile: 32; sql: 5
file content (41 lines) | stat: -rw-r--r-- 1,282 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More import => ['!pass'];

use Dancer::Logger::File;
use Dancer ':syntax';
use Dancer::Test;
use Dancer::Exception ':all';

plan skip_all => "File::Temp 0.22 required"
    unless Dancer::ModuleLoader->load( 'File::Temp', '0.22' );

my $dir = File::Temp::tempdir(CLEANUP => 1, TMPDIR => 1);
my $logfile= "$dir/logs/test.log";

set warnings => 1; # we want to test fatal warnings
set log => 'fatal';
set logger => 'null'; # we'll monkeypatch later
set views => path( 't', '25_exceptions', 'views' );

use vars qw(@log_messages);

{
    no warnings 'redefine';
    local *Dancer::Logger::Null::_log = sub { shift; push @log_messages, $_[1] };
    # raise a (now fatal) warning in the route handler
    get '/raise_in_hook' => sub {
        warn "Boom";
        template 'index', { foo => 'baz5' };
    };
    route_exists [ GET => '/raise_in_hook' ];
    response_status_is( [ GET => '/raise_in_hook' ], 500 => "Internal error due to warning");
    response_content_like( [ GET => '/raise_in_hook' ], qr|Error 500| );
    
    # Now, check that we find the error in the log
    my @error= grep {m!request to GET /raise_in_hook crashed!} @log_messages;
    is 0+@error, 2, "We logged the fatal warning to the logger (two calls)";
}

done_testing();