Changeset 1150 for status/report.pl


Ignore:
Timestamp:
Jan 30, 2008, 6:16:57 PM (14 years ago)
Author:
Earle Martin
Message:

Tabular output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • status/report.pl

    r1149 r1150  
    77use Template;
    88
    9 my $file = $ARGV[0];
     9my (%results, %test_names);
    1010
    11 die 'No input file specified'  unless $file;
    12 die "That file doesn't exist"  unless -e $file;
    13 die "That isn't a plain file"  unless -f _;
    14 die "That file isn't readable" unless -r _;
     11foreach (glob "reports/*") {
     12        my ($report_name) = $_ =~ m{reports/test-results-(.*)\.txt};
     13       
     14        $results{$report_name} = load_report($_);
     15}
    1516
    16 open (my $RESULTS, '<', $file) or die "Can't open $file: $!";
    17 my @lines = <$RESULTS>;
    18 close $RESULTS;
    19 
    20 my (%tests, $current_test);
    21 
    22 foreach (@lines) {
    23                 chomp;
    24 
    25                 if (m{^t/(.*?)\.}) {
    26                         $current_test = $1;
    27                 } elsif (/^ok$/) {
    28                         $tests{$current_test} = 100;
    29                 } elsif (/Failed .*? tests, (.*?)% okay/) {
    30                         $tests{$current_test} = $1;
    31                 }
    32 }
     17my %report_data = (
     18        'results'    => \%results,
     19        'test_names' => [ sort keys %test_names ],
     20);
    3321
    3422my $tt = Template->new({
     
    3624});
    3725
    38 $tt->process('tests.tt', { 'tests' => \%tests }) or die $tt->error;
     26$tt->process('tests.tt', { 'data' => \%report_data }) or die $tt->error;
     27
     28# ----------------------------------------------------------------------------
     29
     30sub load_report {
     31        my $file = shift;
     32
     33        die 'No input file specified'  unless $file;
     34        die "That file doesn't exist"  unless -e $file;
     35        die "That isn't a plain file"  unless -f _;
     36        die "That file isn't readable" unless -r _;
     37
     38        open (my $RESULTS, '<', $file) or die "Can't open $file: $!";
     39        my @lines = <$RESULTS>;
     40        close $RESULTS;
     41
     42        my (%tests, $current_test);
     43
     44        # XXX: Test files get added, removed, renamed, etc. A mechanism is necessary
     45        # here to cope with this.
     46       
     47        foreach (@lines) {
     48                        chomp;
     49
     50                        if (m{^t/(.*?)\.}) {
     51                                $current_test = $1;
     52                                $test_names{$current_test} = 1;
     53                        } elsif (/^ok$/) {
     54                                $tests{$current_test} = 100;
     55                        } elsif (/Failed .*? tests, (.*?)% okay/) {
     56                                $tests{$current_test} = $1;
     57                        }
     58        }
     59       
     60        \%tests;
     61}
Note: See TracChangeset for help on using the changeset viewer.