[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 8/5] tap: support colorization of testsuite progress output
From: |
Stefano Lattarini |
Subject: |
Re: [PATCH 8/5] tap: support colorization of testsuite progress output |
Date: |
Thu, 21 Jul 2011 17:15:50 +0200 |
User-agent: |
KMail/1.13.3 (Linux/2.6.30-2-686; KDE/4.4.4; i686; ; ) |
On Tuesday 19 July 2011, Ralf Wildenhues wrote:
> * Stefano Lattarini wrote on Tue, Jul 19, 2011 at 11:47:21AM CEST:
> > On Monday 18 July 2011, Ralf Wildenhues wrote:
> > > > + grn => '[0;32m',
> > > > + lgn => '[1;32m',
> > > > + blu => '[1;34m',
> > > > + mgn => '[0;35m',
> > > > + brg => '[1m',
> > > > + std => '[m',
> > > > +);
>
> > > > +sub decorate_result ($)
> > > > +{
> > > > + return $_[0] unless $cfg{"color-tests"};
> > > > + # Best way to simulate a 'switch' construct here.
> > >
> > > Please don't, that only obfuscates the code. automake.in uses long
> > > if ... else lists. If you don't like that,
> > >
> > I don't, at least not when using the GNU Coding Standards (as too much
> > vertical space gets wasted IMO).
>
> Maybe, but vertical space is less important than clear code. Your
> version made me stumble and think for a moment whether all code paths
> are clear.
>
> > > use a map.
> > >
> > How would that be clearer? Honest question.
> >
> > Oh, or myabe you were suggesting to use an hash?
>
> Yes, of course. Sorry for the lax terminology there.
>
> Thanks,
> Ralf
>
Below is what I've squashed in. OK?
Regards,
Stefano
-*-*-*-
diff --git a/lib/tap-driver b/lib/tap-driver
index f39d92b..69533b4 100755
--- a/lib/tap-driver
+++ b/lib/tap-driver
@@ -230,17 +230,24 @@ sub colored ($$)
sub decorate_result ($)
{
- return $_[0] unless $cfg{"color-tests"};
- # Best way to simulate a 'switch' construct here.
- for (@_)
+ my $result = shift;
+ return $result unless $cfg{"color-tests"};
+ my %color_for_result =
+ (
+ "ERROR" => 'mgn',
+ "PASS" => 'grn',
+ "XPASS" => 'red',
+ "FAIL" => 'red',
+ "XFAIL" => 'lgn',
+ "SKIP" => 'blu',
+ );
+ if (my $color = $color_for_result{$result})
+ {
+ return colored ($color, $result);
+ }
+ else
{
- $_ eq "ERROR" and return colored ('mgn', $_);
- $_ eq "PASS" and return colored ('grn', $_);
- $_ eq "XPASS" and return colored ('red', $_);
- $_ eq "FAIL" and return colored ('red', $_);
- $_ eq "XFAIL" and return colored ('lgn', $_);
- $_ eq "SKIP" and return colored ('blu', $_);
- return $_; # Don't colorize unknown stuff.
+ return $result; # Don't colorize unknown stuff.
}
}
- Re: [PATCH 5/5] {test-protocols} tap: add experimental TAP-aware driver, (continued)