tests: Option to select which log messages to capture
This commit is contained in:
parent
009033d476
commit
115f23dead
3 changed files with 25 additions and 5 deletions
|
@ -2,18 +2,38 @@ package ddclient::t::Logger;
|
|||
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
||||
use parent qw(-norequire ddclient::Logger);
|
||||
|
||||
{
|
||||
package ddclient::t::LoggerAbort;
|
||||
use overload '""' => qw(stringify);
|
||||
sub new {
|
||||
my ($class, %args) = @_;
|
||||
return bless(\%args, $class);
|
||||
}
|
||||
sub stringify {
|
||||
return 'logged a FATAL message';
|
||||
}
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, $parent) = @_;
|
||||
my ($class, $parent, $labelre) = @_;
|
||||
my $self = $class->SUPER::new(undef, $parent);
|
||||
$self->{logs} = [];
|
||||
$self->{_labelre} = $labelre;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub _log {
|
||||
my ($self, $args) = @_;
|
||||
push(@{$self->{logs}}, $args)
|
||||
if ($args->{label} // '') =~ qr/^(?:WARNING|FATAL|SUCCESS|FAILED)$/;
|
||||
my $lre = $self->{_labelre};
|
||||
my $lbl = $args->{label};
|
||||
push(@{$self->{logs}}, $args) if !defined($lre) || (defined($lbl) && $lbl =~ $lre);
|
||||
return $self->SUPER::_log($args);
|
||||
}
|
||||
|
||||
sub _abort {
|
||||
my ($self) = @_;
|
||||
push(@{$self->{logs}}, 'aborted');
|
||||
die(ddclient::t::LoggerAbort->new());
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -133,7 +133,7 @@ for my $tc (@test_cases) {
|
|||
diag('==============================================================================');
|
||||
local $ddclient::globals{debug} = 1;
|
||||
local $ddclient::globals{verbose} = 1;
|
||||
my $l = ddclient::t::Logger->new($ddclient::_l);
|
||||
my $l = ddclient::t::Logger->new($ddclient::_l, qr/^(?:WARNING|FATAL|SUCCESS|FAILED)$/);
|
||||
local %ddclient::config = %{$tc->{cfg}};
|
||||
local %ddclient::recap;
|
||||
{
|
||||
|
|
|
@ -230,7 +230,7 @@ for my $tc (@test_cases) {
|
|||
diag('==============================================================================');
|
||||
local $ddclient::globals{debug} = 1;
|
||||
local $ddclient::globals{verbose} = 1;
|
||||
my $l = ddclient::t::Logger->new($ddclient::_l);
|
||||
my $l = ddclient::t::Logger->new($ddclient::_l, qr/^(?:WARNING|FATAL|SUCCESS|FAILED)$/);
|
||||
local %ddclient::config;
|
||||
local %ddclient::recap;
|
||||
$ddclient::config{$_} = {
|
||||
|
|
Loading…
Reference in a new issue