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($@); }
|
BEGIN { eval { require 'ddclient'; } or BAIL_OUT($@); }
|
||||||
use parent qw(-norequire ddclient::Logger);
|
use parent qw(-norequire ddclient::Logger);
|
||||||
|
|
||||||
|
{
|
||||||
|
package ddclient::t::LoggerAbort;
|
||||||
|
use overload '""' => qw(stringify);
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, $parent) = @_;
|
my ($class, %args) = @_;
|
||||||
|
return bless(\%args, $class);
|
||||||
|
}
|
||||||
|
sub stringify {
|
||||||
|
return 'logged a FATAL message';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my ($class, $parent, $labelre) = @_;
|
||||||
my $self = $class->SUPER::new(undef, $parent);
|
my $self = $class->SUPER::new(undef, $parent);
|
||||||
$self->{logs} = [];
|
$self->{logs} = [];
|
||||||
|
$self->{_labelre} = $labelre;
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _log {
|
sub _log {
|
||||||
my ($self, $args) = @_;
|
my ($self, $args) = @_;
|
||||||
push(@{$self->{logs}}, $args)
|
my $lre = $self->{_labelre};
|
||||||
if ($args->{label} // '') =~ qr/^(?:WARNING|FATAL|SUCCESS|FAILED)$/;
|
my $lbl = $args->{label};
|
||||||
|
push(@{$self->{logs}}, $args) if !defined($lre) || (defined($lbl) && $lbl =~ $lre);
|
||||||
return $self->SUPER::_log($args);
|
return $self->SUPER::_log($args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub _abort {
|
||||||
|
my ($self) = @_;
|
||||||
|
push(@{$self->{logs}}, 'aborted');
|
||||||
|
die(ddclient::t::LoggerAbort->new());
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -133,7 +133,7 @@ for my $tc (@test_cases) {
|
||||||
diag('==============================================================================');
|
diag('==============================================================================');
|
||||||
local $ddclient::globals{debug} = 1;
|
local $ddclient::globals{debug} = 1;
|
||||||
local $ddclient::globals{verbose} = 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::config = %{$tc->{cfg}};
|
||||||
local %ddclient::recap;
|
local %ddclient::recap;
|
||||||
{
|
{
|
||||||
|
|
|
@ -230,7 +230,7 @@ for my $tc (@test_cases) {
|
||||||
diag('==============================================================================');
|
diag('==============================================================================');
|
||||||
local $ddclient::globals{debug} = 1;
|
local $ddclient::globals{debug} = 1;
|
||||||
local $ddclient::globals{verbose} = 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::config;
|
||||||
local %ddclient::recap;
|
local %ddclient::recap;
|
||||||
$ddclient::config{$_} = {
|
$ddclient::config{$_} = {
|
||||||
|
|
Loading…
Reference in a new issue