Test-Smoke
view release on metacpan or search on metacpan
lib/Test/Smoke/Reporter.pm view on Meta::CPAN
$self->log_info("Writing report to '%s'", $name);
local *RPT;
open RPT, "> $name" or do {
require Carp;
Carp::carp( "Error creating '$name': $!" );
return;
};
print RPT $self->report;
close RPT or do {
require Carp;
Carp::carp( "Error writing to '$name': $!" );
return;
};
$self->log_info("'%s' written OK", $name);
return 1;
}
=head2 $reporter->smokedb_data()
Transport the report to the gateway. The transported data will also be stored
locally in the file mktest.jsn
=cut
sub smokedb_data {
my $self = shift;
$self->log_info("Gathering CoreSmokeDB information...");
my %rpt = map { $_ => $self->{$_} } keys %$self;
$rpt{manifest_msgs} = delete $rpt{_mani};
$rpt{applied_patches} = [$self->registered_patches];
$rpt{sysinfo} = do {
my %Conf = get_smoked_Config($self->{ddir} => qw( version lfile ));
my $si = System::Info->new;
my ($osname, $osversion) = split m/ - / => $si->os, 2;
(my $ncpu = $si->ncpu || "?") =~ s/^\s*(\d+)\s*/$1/;
(my $user_note = $self->{user_note} || "") =~ s/(\S)[\s\r\n]*\z/$1\n/;
{
architecture => lc $si->cpu_type,
config_count => $self->{_rpt}{count},
cpu_count => $ncpu,
cpu_description => $si->cpu,
duration => $self->{_rpt}{secs},
git_describe => $self->{_rpt}{patchdescr},
git_id => $self->{_rpt}{patch},
smoke_branch => $self->{_rpt}{smokebranch},
hostname => $self->{hostname} || $si->host,
lang => $ENV{LANG},
lc_all => $ENV{LC_ALL},
osname => $osname,
osversion => $osversion,
perl_id => $Conf{version},
reporter => $self->{from},
reporter_version => $VERSION,
smoke_date => __posixdate($self->{_rpt}{started}),
smoke_revision => $Test::Smoke::VERSION,
smoker_version => $Test::Smoke::Smoker::VERSION,
smoke_version => $Test::Smoke::VERSION,
test_jobs => $ENV{TEST_JOBS},
username => $ENV{LOGNAME} || getlogin || getpwuid($<) || "?",
user_note => $user_note,
smoke_perl => ($^V ? sprintf("%vd", $^V) : $]),
};
};
$rpt{compiler_msgs} = [$self->ccmessages];
$rpt{nonfatal_msgs} = [$self->nonfatalmessages];
$rpt{skipped_tests} = [$self->user_skipped_tests];
$rpt{harness_only} = delete $rpt{harnessonly};
$rpt{summary} = $self->summary;
$rpt{log_file} = undef;
my $rpt_fail = $rpt{summary} eq "PASS" ? 0 : 1;
if (my $send_log = $self->{send_log}) {
if ( ($send_log eq "always")
or ($send_log eq "on_fail" && $rpt_fail))
{
$rpt{log_file} = $self->get_logfile();
}
}
$rpt{out_file} = undef;
if (my $send_out = $self->{send_out}) {
if ( ($send_out eq "always")
or ($send_out eq "on_fail" && $rpt_fail))
{
$rpt{out_file} = $self->get_outfile();
}
}
delete $rpt{$_} for qw/from send_log send_out user_note/, grep m/^_/ => keys %rpt;
my $json = JSON->new->utf8(1)->pretty(1)->encode(\%rpt);
# write the json to file:
my $jsn_file = catfile($self->{ddir}, $self->{jsnfile});
if (open my $jsn, ">", $jsn_file) {
binmode($jsn);
print {$jsn} $json;
close $jsn;
$self->log_info("Write to '%s': ok", $jsn_file);
}
else {
$self->log_warn("Error creating '%s': %s", $jsn_file, $!);
}
return $self->{_json} = $json;
}
=head2 $reporter->report( )
Return a string with the full report
=cut
sub report {
my $self = shift;
return unless defined $self->{_outfile};
$self->_get_usernote();
my $report = $self->preamble;
$report .= "Summary: ".$self->summary."\n\n";
( run in 2.391 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )