Question

I'm trying to get color (colour) output using prove / TAP::Harness with Active state Perl on Windows 7.

The actual tests run fine, its just that there is no colour output.

I get a similar problem using Strawberry Perl and WinXP.

I am unable to use a *nix and cygwin or other thirdparty xterm both of which do colour the output.

I know its a little picky thing but I think I've become addicted to the "green" :-)

Is there a simple fix? - couldn't see anything on the Activate state site - I was thinking of raising a bug. Any guidance on debugging or what to check?

Is it worth writing my own formatter?

Thanks in advance for your help.

More detail on installed modules and approaches tried...

These are installed and to the best of my knowledge working

   Win32::Console::ANSI;
   Term::ANSIColor;

This test script worked:

   #!/usr/bin/perl
   use strict;
   use warnings;
   use Win32::Console::ANSI;
   use Term::ANSIColor;

   print "One fish\n";
   print "Two fish\n";
   print color("red"), "Red Fish\n", color("reset");
   print color("blue"), "Blue Fish\n", color("reset");

I have tried:

prove
prove -c

and using the following test harness programs with and without formatter but I was under the assumption colour was on by default.

#!/usr/bin/perl
use strict;
use warnings;
use TAP::Harness;

my @tests = glob( 't/*.t' );
my $harness = TAP::Harness->new();
$harness->runtests( @tests );

I have also install the HTML formatter and that appears to be working.

 prove  --formatter=TAP::Formatter::HTML

Running:

prove  --formatter=TAP::Formatter::Color

Gives Can't locate object method "verbosity" via package "TAP::Formatter::Color" at x:/Perl/site/lib/TAP/Harness.pm line 679.

Thanks Mike

Was it helpful?

Solution

It appears to be a bug1 in TAP::Formatter::Color. It's attaching to the console's STDOUT handle but the messages that should be colored are on STDERR.

This:

my $console = Win32::Console->new( STD_OUTPUT_HANDLE() );

Should be this instead:

my $console = Win32::Console->new( STD_ERROR_HANDLE() );

Also, despite what the documentation says, --color is not the default on Windows. App::Prove (which is what's behind the "prove" executable) explicitly sets the default to false for Windows:

sub _color_default {
    my $self = shift;
    return -t STDOUT && !$ENV{HARNESS_NOTTY} && !IS_WIN32;
}


1. The bug was fixed in Test::Harness v3.41

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top