Skip Menu |

This queue is for tickets about the Test-Harness CPAN distribution.

Report information
The Basics
Id: 71850
Status: open
Priority: 0/
Queue: Test-Harness

People
Owner: Nobody in particular
Requestors: kuno [...] frob.nl
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.23
Fixed in: (no value)



Subject: --color doesn't work when output is piped
prove --color t/testfile.t produces colored output on a terminal but not when piped. This is easy to test by running "prove --color t/testfile.t | cat" on a terminal. I'm using perl v5.10.1 supplied by Debian Stable, and Test::Harness 3.23 installed from source / through CPAN.
Subject: Re: [rt.cpan.org #71850] --color doesn't work when output is piped
Date: Sat, 22 Oct 2011 15:54:21 -0700
To: bug-Test-Harness [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
This is caused by Test::Harness choosing TAP::Formatter::File for output if output is not to a TTY. TAP::Formatter::File does not output color. IMO I don't see why it shouldn't, if the user explicitly asked for color give them color. That would be a matter of moving _set_colors, _output_success and _failure_output from TAP::Formatter::Console up into TAP::Formatter::Base so all formatters have it available.
On Sat Oct 22 18:54:32 2011, schwern@pobox.com wrote: Show quoted text
> This is caused by Test::Harness choosing TAP::Formatter::File for output if > output is not to a TTY. TAP::Formatter::File does not output color. IMO I > don't see why it shouldn't, if the user explicitly asked for color give them > color. That would be a matter of moving _set_colors, _output_success and > _failure_output from TAP::Formatter::Console up into TAP::Formatter::Base so > all formatters have it available.
I think this can be easily solved by continuing to use TAP::Formatter::Console (rather than switching to TAP::Formatter::File) if the user asks for color. This is a two line patch in TAP::Harness (plus comments).
Subject: tap-harness-color-pipe.patch
diff --git a/lib/TAP/Harness.pm b/lib/TAP/Harness.pm index 9564630..b3df99d 100644 --- a/lib/TAP/Harness.pm +++ b/lib/TAP/Harness.pm @@ -418,8 +418,12 @@ Any keys for which the value is C<undef> will be ignored. $self->jobs(1) unless defined $self->jobs; + # Switch to TAP::Formatter::File if either HARNESS_NOTTY is set, or if + # STDOUT is not connect to a TTY and the user did not explicitly ask + # for color + my $stdout_is_tty = -t ( $arg_for{stdout} || \*STDOUT ); local $default_class{formatter_class} = 'TAP::Formatter::File' - unless -t ( $arg_for{stdout} || \*STDOUT ) && !$ENV{HARNESS_NOTTY}; + unless ( $stdout_is_tty || $arg_for{color} ) && !$ENV{HARNESS_NOTTY}; while ( my ( $attr, $class ) = each %default_class ) { $self->$attr( $self->$attr() || $class );