File: 055AppDestroy.t

package info (click to toggle)
liblog-log4perl-perl 1.48-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,900 kB
  • sloc: perl: 6,449; makefile: 9
file content (53 lines) | stat: -rwxr-xr-x 1,065 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
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/perl
###################################################################
# Check if a custom appender with a destroy handler gets its 
# warning through
###################################################################

BEGIN { 
    if($ENV{INTERNAL_DEBUG}) {
        require Log::Log4perl::InternalDebug;
        Log::Log4perl::InternalDebug->enable();
    }
}

package SomeAppender;
our @ISA = qw(Log::Log4perl::Appender);
sub new {
    bless {}, shift;
}
sub log {}
sub DESTROY {
    warn "Horrible Warning!";
}

package main;
use warnings;
use strict;
use Test::More;
use Log::Log4perl qw(:easy);

my $warnings;

$SIG{__WARN__} = sub {
    $warnings .= $_[0];
};

my $conf = q(
log4perl.category       = DEBUG, SomeA
log4perl.appender.SomeA = SomeAppender
log4perl.appender.SomeA.layout = Log::Log4perl::Layout::SimpleLayout
);

Log::Log4perl->init(\$conf);

plan tests => 1;

my $logger = get_logger();
$logger->debug("foo");

Log::Log4perl::Logger->cleanup();

END {
    like $warnings, qr/Horrible Warning!/, "app destruction warning caught";
}