Log-Mini/t/04_LoggerSTDERR.t

59 lines
1.2 KiB
Perl
Raw Permalink 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);
2023-03-17 18:29:38 +03:00
use Log::Mini::Logger::STDERR;
2019-02-21 22:30:49 +03:00
subtest 'creates correct object' => sub {
2023-03-17 18:29:38 +03:00
isa_ok(Log::Mini::Logger::STDERR->new, 'Log::Mini::Logger::STDERR');
2019-02-21 22:30:49 +03:00
};
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 {
2023-03-17 18:29:38 +03:00
my $logger = Log::Mini::Logger::STDERR->new;
2019-02-21 22:30:49 +03:00
$logger->set_level('debug');
return $logger;
}
done_testing;