File: logperl01.t

package info (click to toggle)
liblog-dispatch-perl-perl 0.04-1~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 96 kB
  • sloc: perl: 111; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 1,730 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

BEGIN {				# Magic Perl CORE pragma
    if ($ENV{PERL_CORE}) {
        chdir 't' if -d 't';
        @INC = '../lib';
    }
}

use Test::More tests => 5 + (2*2) + (2*2) + (2*2) + (2*2);
use strict;
use warnings;

use_ok( 'Log::Dispatch::Perl' );
can_ok( 'Log::Dispatch::Perl',qw(
 new
 log_message
) );

my $dispatcher = Log::Dispatch->new;
isa_ok( $dispatcher,'Log::Dispatch' );

my $channel = Log::Dispatch::Perl->new( qw(name default min_level debug) );
isa_ok( $channel,'Log::Dispatch::Perl' );

$dispatcher->add( $channel );
is( $dispatcher->output( 'default' ),$channel,'Check if channel activated' );

my $warn;
$SIG{__WARN__} = sub { $warn .= "@_" };

foreach my $method (qw(debug info)) {
    $warn = '';
    eval { $dispatcher->$method( "This is a '$method' action" ) };
    ok( !$@,"Check if no error in eval for '$method': $@" );
    ok( !$warn,"Check if no warning occurred: $warn" );
}

foreach my $method (qw(notice warning)) {
    $warn = '';
    eval { $dispatcher->$method( "This is a '$method' action" ) };
    ok( !$@,"Check if no error in eval for '$method': $@" );
    is( $warn,"This is a '$method' action\n","Check if warning occurred" );
}

foreach my $method (qw(error critical)) {
    $warn = '';
    eval { $dispatcher->$method( "This is a '$method' action" ) };
    is( $@,"This is a '$method' action\n",
     "Check if no error in eval for '$method'" );
    ok( !$warn,"Check if no warning occurred: $warn" )
}

foreach my $method (qw(alert emergency)) {
    $warn = '';
    eval { $dispatcher->$method( "This is a '$method' action" ) };
    like( $@,qr#eval \{\.\.\.} called at $0 line \d+#,
     "Check if no error in eval for '$method'" );
    ok( !$warn,"Check if no warning occurred: $warn" )
}