chromatic wrote code that only reports test failures and I liked it so much that I stole it to report passing tests in green and failing tests in red. This is just a proof of concept and may get expanded, which is why I didn't toss this into Code Catacombs.

The major problem with this lies in Test::Harness's annoying habit of printing failure output directly to STDERR, so you cannot currently have the normal "got/expected" behavior lining up with the pretty red failure message. That behavior might get fixed at some point.

In the meantime, feel free to play with this and comment on it. It needs some work.

#!/usr/bin/perl use strict; use warnings; use Term::ANSIColor; use Test::Harness::Straps; use constant SUCCESS => color 'bold green'; use constant FAILURE => color 'bold red'; use constant SKIP => color 'bold yellow'; use constant RESET => color 'reset'; my $strap = Test::Harness::Straps->new(); for my $file (@ARGV) { next unless -f $file; my %results = $strap->analyze_file( $file ); my ($header, $results) = process_results( $file, \%results ); if ($results{passing}) { print SUCCESS; print( sprintf("All (%d) tests passed in %s\n", $results{seen +}, $file)); } elsif ($results{skip_all}) { print SKIP; print sprintf("All (%d) tests skipped in %s\n", $results{seen} +, $file); } else { print FAILURE; print "$header\n"; } foreach my $result (@$results) { if ($result->{test}{ok}) { print SUCCESS; } else { print FAILURE; } print $result->{output}; } print RESET; } sub process_results { my ($file, $results) = @_; my $report = create_header($file, @{$results}{qw( max se +en ok )}); my $count = 0; my @results; for my $test ( @{ $results->{details} } ) { $count++; push @results => { test => $test, output => create_test_result( $test->{ok}, $count, @{ $tes +t }{qw( name reason ) } ) } } return ($report, \@results); } sub create_header { my ($file, $expected, $seen, $passed) = @_; my $failed = $seen - $passed; return sprintf "File '%s'\nExpected %d / Seen %d / Okay %d / Faile +d %d\n", @_, $failed; } sub create_test_result { my ($ok, $number, $name, $reason) = @_; $ok = $ok ? 'ok' : 'not ok'; $reason = $reason ? " ($reason)" : ""; return sprintf "%6s %4d %s%s\n", $ok, $number, $name, $reason; }

Cheers,
Ovid

New address of my CGI Course.


In reply to See your test results in color. by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.