use strict;
use Data::Dumper;
use File::Find;
use Cwd;
$Data::Dumper::Terse = 1;
my $root = undef;
my $entry = '';
my $pass_count = 0;
my $total_count = 0;
while(<>)
{
if(m/^root:\s+(.*?)$/)
{
$root = $1;
}
elsif(m/^cwd:\s+(.*?)$/)
{
if(length($entry))
{
&process_entry($root, $entry);
$entry = '';
}
$entry .= $_;
}
else
{
$entry .= $_;
}
}
if(length($entry))
{
&process_entry($root, $entry);
}
my $percentage = $pass_count * 100 / $total_count;
printf " * * * %d of %d unit-tests passed (%.1f percent) * * *\n", $pass_count, $total_count, $percentage;
sub process_entry
{
my ($root, $lines) = @_;
my $lines_seq = [split /\n/, $lines];
my $tbl = { 'root' => $root, 'stdout' => [], 'stderr' => [] };
my $line;
foreach $line (@$lines_seq)
{
if($line =~ m/^(\w+):\s+(.*)$/)
{
my $key = $1;
my $val = $2;
if(!exists($$tbl{$key}))
{ $$tbl{$key} = ''; }
if($key eq 'stdout' || $key eq 'stderr') {
push @{$$tbl{$key}}, $val;
}
else
{
$$tbl{$key} .= $val;
}
}
else
{
print "ERROR: $line";
}
}
my $test_name = $$tbl{cwd};
if ($test_name =~ m|.*/([a-zA-Z0-9-+_]+)$|)
{
$test_name = $1;
}
if(0 ne $$tbl{exit})
{
printf "%-40s FAIL Makefile failure\n", $test_name;
$total_count++;
return;
}
foreach $line (@{$$tbl{stderr}})
{
printf "%-40s FAIL spurious stderr failure: %s\n", $test_name, $line;
$total_count++;
return;
}
my $seen_result = 0;
foreach $line (@{$$tbl{stdout}})
{
if($line =~ m/^(PASS|XPASS|FAIL|XFAIL).+/)
{
$total_count++;
if($line =~ m/^PASS.+/)
{
$pass_count++;
}
else
{
printf "%-40s %s\n", $test_name, $line;
}
$seen_result = 1;
}
}
if(!$seen_result)
{
printf "%-40s AMBIGIOUS missing [X]PASS/[X]FAIL\n", $test_name;
$total_count++;
}
}