1 package TAP::Formatter::Color;
7 use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
15 eval 'use Win32::Console';
20 my $console = Win32::Console->new( STD_OUTPUT_HANDLE() );
22 # eval here because we might not know about these variables
23 my $fg = eval '$FG_LIGHTGRAY';
24 my $bg = eval '$BG_BLACK';
27 my ( $self, $output, $color ) = @_;
30 if ( $color eq 'reset' ) {
31 $fg = eval '$FG_LIGHTGRAY';
32 $bg = eval '$BG_BLACK';
34 elsif ( $color =~ /^on_(.+)$/ ) {
35 $bg = eval '$BG_' . uc($1);
38 $fg = eval '$FG_' . uc($color);
41 # In case of colors that aren't defined
42 $self->set_color('reset')
43 unless defined $bg && defined $fg;
45 $console->Attr( $bg | $fg );
50 eval 'use Term::ANSIColor';
56 my ( $self, $output, $color ) = @_;
57 $output->( color($color) );
69 TAP::Formatter::Color - Run Perl test scripts with color
81 Note that this harness is I<experimental>. You may not like the colors I've
82 chosen and I haven't yet provided an easy way to override them.
84 This test harness is the same as L<TAP::Harness>, but test results are output
85 in color. Passing tests are printed in green. Failing tests are in red.
86 Skipped tests are blue on a white background and TODO tests are printed in
89 If L<Term::ANSIColor> cannot be found (or L<Win32::Console> if running
90 under Windows) tests will be run without color.
94 use TAP::Formatter::Color;
95 my $harness = TAP::Formatter::Color->new( \%args );
96 $harness->runtests(@tests);
104 The constructor returns a new C<TAP::Formatter::Color> object. If
105 L<Term::ANSIColor> is not installed, returns undef.
114 # shorten that message a bit
115 ( my $error = $NO_COLOR ) =~ s/ in \@INC .*//s;
116 warn "Note: Cannot run tests in color: $error\n";
120 return bless {}, $class;
123 ##############################################################################
127 Test::Formatter::Color->can_color()
129 Returns a boolean indicating whether or not this module can actually
130 generate colored output. This will be false if it could not load the
131 modules needed for the current platform.
141 Set the output color.