1 package TAP::Formatter::Color;
4 use vars qw($VERSION @ISA);
6 use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
8 @ISA = qw(TAP::Object);
16 eval 'use Win32::Console';
21 my $console = Win32::Console->new( STD_OUTPUT_HANDLE() );
23 # eval here because we might not know about these variables
24 my $fg = eval '$FG_LIGHTGRAY';
25 my $bg = eval '$BG_BLACK';
28 my ( $self, $output, $color ) = @_;
31 if ( $color eq 'reset' ) {
32 $fg = eval '$FG_LIGHTGRAY';
33 $bg = eval '$BG_BLACK';
35 elsif ( $color =~ /^on_(.+)$/ ) {
36 $bg = eval '$BG_' . uc($1);
39 $fg = eval '$FG_' . uc($color);
42 # In case of colors that aren't defined
43 $self->set_color('reset')
44 unless defined $bg && defined $fg;
46 $console->Attr( $bg | $fg );
51 eval 'use Term::ANSIColor';
57 my ( $self, $output, $color ) = @_;
58 $output->( color($color) );
70 TAP::Formatter::Color - Run Perl test scripts with color
82 Note that this harness is I<experimental>. You may not like the colors I've
83 chosen and I haven't yet provided an easy way to override them.
85 This test harness is the same as L<TAP::Harness>, but test results are output
86 in color. Passing tests are printed in green. Failing tests are in red.
87 Skipped tests are blue on a white background and TODO tests are printed in
90 If L<Term::ANSIColor> cannot be found (or L<Win32::Console> if running
91 under Windows) tests will be run without color.
95 use TAP::Formatter::Color;
96 my $harness = TAP::Formatter::Color->new( \%args );
97 $harness->runtests(@tests);
105 The constructor returns a new C<TAP::Formatter::Color> object. If
106 L<Term::ANSIColor> is not installed, returns undef.
110 # new() implementation supplied by TAP::Object
117 # shorten that message a bit
118 ( my $error = $NO_COLOR ) =~ s/ in \@INC .*//s;
119 warn "Note: Cannot run tests in color: $error\n";
120 return; # abort object construction
126 ##############################################################################
130 Test::Formatter::Color->can_color()
132 Returns a boolean indicating whether or not this module can actually
133 generate colored output. This will be false if it could not load the
134 modules needed for the current platform.
144 Set the output color.