#!perl -T
#
# $Id: a277714b8f94487a2393e5489596a5c161f92b62 $
#
use Test::More tests => 21;
{
# Create a Log::Fine object and a new logger
my $log = Log::Fine->new(no_croak => 1);
isa_ok($log, "Log::Fine");
can_ok($log, "name");
# all objects should have names
ok($log->name() =~ /\w\d+$/);
# first we create a logger object
my $logger = Log::Fine->logger("logger0");
isa_ok($logger, "Log::Fine::Logger");
can_ok($logger, "name");
can_ok($logger, "registerHandle");
ok($logger->name() =~ /\w\d+$/);
# create a handle for the logger and validate
my $handle = Log::Fine::Handle::String->new();
isa_ok($handle, "Log::Fine::Handle");
can_ok($handle, "name");
ok($handle->name() =~ /\w\d+$/);
# now register the handle and validate
my $result = $logger->registerHandle($handle);
isa_ok($result, "Log::Fine::Logger");
can_ok($result, "name");
ok($result->name() =~ /\w\d+$/);
# Log something (won't do anything)
my $loggerrc = $logger->log(DEBG, "This is a test message");
# just make sure the object returned is a Logger object
isa_ok($loggerrc, "Log::Fine::Logger");
# make sure skip is set to our default
my $num = $logger->skip();
ok($num == Log::Fine::Logger->LOG_SKIP_DEFAULT);
# set the skip level to 5
$logger->skip(5);
# check to see if it's okay
$num = $logger->skip();
ok($num == 5);
# okay, now increment and decrement
ok($logger->incrSkip() == 6);
ok($logger->decrSkip() == 5);
SKIP: {
eval "use Test::Output 0.10";
skip
"Test::Output 0.10 or above required for testing Console output",
3
if $@;
# Create a valid logger for testing
my $badlog = $log->logger("badlogger");
$badlog->{no_croak} = 1;
stderr_like(
sub {
my $foo = Log::Fine::Logger->new(no_croak => 1);
},
qr/Loggers need names/,
'logger(): Invoked without name'
);
stderr_like(
sub {
$badlog->log(INFO,
"It was lightning headaches and sweet avalanche"
);
},
qr/No handles defined/,
'log(): Invoke without handle'
);
stderr_like(sub { $badlog->registerHandle() },
qr/must be a valid/,
'registerHandle(): Invoke without handle');
}
}