Log-Mini/t/04_LoggerSTDERR.t

58 lines
1.2 KiB
Perl
Raw Normal View History

2019-02-21 22:30:49 +03:00
use lib 'lib';
use strict;
use warnings;
use Test::More;
use Test::Fatal;
use Capture::Tiny qw(capture_stderr);
use Log::Mini::LoggerSTDERR;
subtest 'creates correct object' => sub {
isa_ok(Log::Mini::LoggerSTDERR->new, 'Log::Mini::LoggerSTDERR');
};
subtest 'prints to stderr' => sub {
my $log = _build_logger();
for my $level (qw/error warn debug/) {
my $stderr = capture_stderr {
$log->$level('message');
};
ok $stderr;
}
};
subtest 'prints to stderr with \n' => sub {
my $log = _build_logger();
for my $level (qw/error warn debug/) {
my $stderr = capture_stderr {
$log->$level('message');
};
like $stderr, qr/\n$/;
}
};
2019-03-19 14:57:41 +03:00
subtest 'prints sprintf formatted line' => sub {
my $output = [];
my $log = _build_logger(output => $output);
for my $level (qw/error warn debug/) {
my $stderr = capture_stderr {
$log->$level('message %s', 'formatted');
};
like $stderr,
qr/^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d.\d{3} \[$level\] message formatted$/;
}
};
2019-02-21 22:30:49 +03:00
sub _build_logger {
my $logger = Log::Mini::LoggerSTDERR->new;
$logger->set_level('debug');
return $logger;
}
done_testing;