#!perl -T
{
my
$basic
= Log::Fine::Formatter::Basic->new();
isa_ok(
$basic
,
"Log::Fine::Formatter::Basic"
);
can_ok(
$basic
,
"name"
);
can_ok(
$basic
,
"timeStamp"
);
ok(
$basic
->name() =~ /\w\d+$/);
ok(
$basic
->timeStamp() eq Log::Fine::Formatter->LOG_TIMESTAMP_FORMAT);
ok(
$basic
->can(
"levelMap"
));
my
$lvls
=
$basic
->levelMap();
isa_ok(
$lvls
,
"Log::Fine::Levels"
);
my
$msg
=
"Stop by this disaster town"
;
my
$log0
=
$basic
->
format
(INFO,
$msg
, 1);
ok(
$log0
=~ /^\[.*?\] \w+
$msg
/);
$basic
->timeStamp(
"%Y%m%d%H%M%S"
);
my
$log1
=
$basic
->
format
(INFO,
$msg
, 1);
ok(
$log1
=~ /^\[\d{14,14}\] \w+
$msg
/);
my
$detailed
= Log::Fine::Formatter::Detailed->new();
isa_ok(
$detailed
,
"Log::Fine::Formatter::Detailed"
);
can_ok(
$detailed
,
"name"
);
can_ok(
$detailed
,
"timeStamp"
);
can_ok(
$detailed
,
"testFormat"
);
ok(
$detailed
->name() =~ /\w\d+$/);
ok(
$detailed
->timeStamp() eq
Log::Fine::Formatter->LOG_TIMESTAMP_FORMAT);
my
$log2
=
$detailed
->
format
(INFO,
$msg
, 1);
ok(
$log2
=~ /^\[.*?\] \w+ \(.*?\)
$msg
/);
my
$log3
= myfunc(
$detailed
,
$msg
);
ok(
$log3
=~ /^\[.*?\] \w+ \(.*?\:\d+\)
$msg
/);
my
$log4
=
$detailed
->testFormat(INFO,
$msg
);
ok(
$log4
=~
/^\[.*?\] \w+ \(Log\:\:Fine\:\:Formatter\:\:testFormat\(\)\:\d+\)
$msg
/
);
my
$syslog
= Log::Fine::Formatter::Syslog->new();
isa_ok(
$syslog
,
"Log::Fine::Formatter::Syslog"
);
can_ok(
$syslog
,
"name"
);
can_ok(
$syslog
,
"timeStamp"
);
ok(
$syslog
->name() =~ /\w\d+$/);
ok(
$syslog
->timeStamp() eq
Log::Fine::Formatter::Syslog->LOG_TIMESTAMP_FORMAT);
my
$log5
=
$syslog
->
format
(INFO,
$msg
, 1);
if
(
$log5
=~
/^\s*([ 1]\d\S+|[^ ]+) [ 0-3][0-9] \d{2}:\d{2}:\d{2} [0-9a-zA-Z\-]+ .*?\[\d+\]:
$msg
/
) {
ok(1);
}
else
{
print
STDERR
"\n----------------------------------------\n"
;
print
STDERR
"Test failed on the following line:\n\n"
;
print
STDERR
"${log5}"
;
print
STDERR
"----------------------------------------\n"
;
ok(0);
}
SKIP: {
eval
"use Test::Output"
;
skip
"Test::Output 0.10 or above required for testing Console output"
,
1
if
$@;
my
$badformatter
= Log::Fine::Formatter->new(
no_croak
=> 1);
stderr_like(
sub
{
$badformatter
->
format
(INFO,
$msg
, 1) },
qr /direct
call to abstract method/,
'Test Direct Abstract Call'
);
}
}
sub
myfunc
{
my
$formatter
=
shift
;
my
$msg
=
shift
;
return
$formatter
->
format
(INFO,
$msg
, 1);
}