summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordoy <doy@tozt.net>2008-12-01 23:24:07 -0500
committerdoy <doy@tozt.net>2008-12-01 23:24:07 -0500
commitde1939e565da64f70c0b2e3f558493fd5df8701c (patch)
treed9e2ccf11ace6b35807188bd0ff2b9711101681d
parent8c6449a2d99ba53b1823d333319c327ee2eb7e7d (diff)
downloadlog-dispatch-channels-de1939e565da64f70c0b2e3f558493fd5df8701c.tar.gz
log-dispatch-channels-de1939e565da64f70c0b2e3f558493fd5df8701c.zip
finish up tests
-rw-r--r--t/002-logging.t16
-rw-r--r--t/003-errors.t29
-rw-r--r--t/004-exceptions.t32
3 files changed, 75 insertions, 2 deletions
diff --git a/t/002-logging.t b/t/002-logging.t
index 816f69f..4032537 100644
--- a/t/002-logging.t
+++ b/t/002-logging.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
use lib 't/lib';
-use Test::More tests => 6;
+use Test::More tests => 9;
use Log::Dispatch::Channels;
use Log::Dispatch::ToString;
@@ -28,10 +28,11 @@ my @messages = (
"debugging 3\n",
"channels 1 and 3\n",
"everywhere\n",
+ "2 specific\n",
);
my %should_get = (
1 => [qw/0 3 4/],
- 2 => [qw/1 4/],
+ 2 => [qw/1 4 5/],
3 => [qw/2 3 4/],
all => [qw/0 1 2 3 3 4 4 4/],
error => [qw/1 2/],
@@ -43,9 +44,20 @@ $logger->log(channels => 2, message => $messages[1], level => 'error');
$logger->log(channels => 3, message => $messages[2], level => 'error');
$logger->log(channels => [qw/1 3/], message => $messages[3], level => 'info');
$logger->log( message => $messages[4], level => 'debug');
+$logger->log_to(name => 2, message => $messages[5], level => 'debug');
for my $output (keys %should_get) {
my $log = join '', map { $messages[$_] } @{ $should_get{$output} };
is($logger->output($output)->get_string, $log,
"output $output received the correct logging calls");
}
+
+ok($logger->would_log('error'),
+ "a logger would log messages at 'error'");
+$logger->remove('all');
+$logger->remove(2);
+$logger->remove(3);
+ok(!$logger->would_log('debug', channels => [qw/2 3/]),
+ "there is no logger left in channel 2 or 3 for debug level messages");
+ok(!$logger->would_log('debug', channels => 2),
+ "no logger is left on channel 2 to log debug level messages");
diff --git a/t/003-errors.t b/t/003-errors.t
new file mode 100644
index 0000000..6c8cc03
--- /dev/null
+++ b/t/003-errors.t
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More tests => 3;
+use Log::Dispatch::Channels;
+use Log::Dispatch::Null;
+
+my $logger = Log::Dispatch::Channels->new;
+for my $channel (1..3) {
+ $logger->add_channel($channel);
+ $logger->add(Log::Dispatch::Null->new(name => $channel,
+ min_level => 'debug'),
+ channels => $channel);
+}
+my $warnings = '';
+$SIG{__WARN__} = sub { $warnings .= $_[0] };
+$logger->add_channel(1);
+like($warnings, qr/^Channel 1 already exists!/,
+ "correct warning when replacing a channel");
+$warnings = '';
+$logger->add(Log::Dispatch::Null->new(name => 1, min_level => 'debug'));
+like($warnings, qr/^Output 1 already exists!/,
+ "correct warning when replacing an output");
+
+$warnings = '';
+$logger->log(channels => 4, message => 'test', level => 'debug');
+like($warnings, qr/^Channel 4 doesn't exist/,
+ "correct warning when forwarding to a nonexistant channel");
diff --git a/t/004-exceptions.t b/t/004-exceptions.t
new file mode 100644
index 0000000..d852fea
--- /dev/null
+++ b/t/004-exceptions.t
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use lib 't/lib';
+use Test::More tests => 4;
+use Test::Exception;
+use Log::Dispatch::Channels;
+use Log::Dispatch::ToString;
+
+my $logger = Log::Dispatch::Channels->new;
+for my $channel (1..3) {
+ $logger->add_channel($channel);
+ $logger->add(Log::Dispatch::ToString->new(name => $channel,
+ min_level => 'debug'),
+ channels => $channel);
+}
+
+throws_ok { $logger->log_and_die(channels => 1,
+ level => 'debug',
+ message => 'log_and_die') }
+ qr/^log_and_die/,
+ "log_and_die dies with the proper message";
+is($logger->output(1)->get_string, "log_and_die",
+ "log_and_die logs the proper message");
+
+throws_ok { $logger->log_and_croak(channels => 2,
+ level => 'debug',
+ message => 'log_and_croak') }
+ qr/^log_and_croak/,
+ "log_and_croak dies with the proper message";
+is($logger->output(2)->get_string, "log_and_croak",
+ "log_and_croak logs the proper message");