#!/usr/bin/env perl
use warnings;
use strict;

open HTML, ">doc/ci.test.txt";
open TXT,  ">doc/ci.test_nohtml.txt";

my %codemap = ( passed => "✓", failed => "✗", warnings => "!",
                skipped => "–", timeout => "T", started => "…" );
my $failed = 0;
my $passed = 0;

print HTML "\$\$html <div class=\"par\">\n";

for ( glob '_build.current/_log/*.txt' )
{
    my $name = s,_build.current/_log/,,r;
    my $fail = "_build.current/_failed/$name";

    next unless $name =~ m,^run_,;

    if ( -e $fail )
    {
        open FAIL, $fail;
        $_ = <FAIL>;
        close FAIL;

        s,gib# out run (.*?)\n,$1,;
        s, test/, ,;

        print TXT  " • failed: $_\n";
        print HTML '$$html failed: <a href="log/' . $name . '">';
        print HTML "$_";
        print HTML "</a><br>\n";

        $failed++;
    }
    else
    {
        $passed++;
    }

}

my $pass = ( $failed == 0 ) ?
           "\nAll «$passed tests passed». New patches have been promoted to ‹current›.\n" :
           "\nSummary: $failed test(s) failed, $passed tests passed.\n";

print HTML "\$\$html </div>\n";
print HTML $pass;
print TXT  $pass;
