Perl: Update "prove" and add its dependencies so it actually works (again)
[msysgit.git] / lib / perl5 / 5.8.8 / TAP / Formatter / Color.pm
blobabf885b0f935609207475fa3fdb91ae1b29af398
1 package TAP::Formatter::Color;
3 use strict;
4 use vars qw($VERSION @ISA);
6 use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
8 @ISA = qw(TAP::Object);
10 my $NO_COLOR;
12 BEGIN {
13 $NO_COLOR = 0;
15 if (IS_WIN32) {
16 eval 'use Win32::Console';
17 if ($@) {
18 $NO_COLOR = $@;
20 else {
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';
27 *set_color = sub {
28 my ( $self, $output, $color ) = @_;
30 my $var;
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);
38 else {
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 );
50 else {
51 eval 'use Term::ANSIColor';
52 if ($@) {
53 $NO_COLOR = $@;
55 else {
56 *set_color = sub {
57 my ( $self, $output, $color ) = @_;
58 $output->( color($color) );
63 if ($NO_COLOR) {
64 *set_color = sub { };
68 =head1 NAME
70 TAP::Formatter::Color - Run Perl test scripts with color
72 =head1 VERSION
74 Version 3.23
76 =cut
78 $VERSION = '3.23';
80 =head1 DESCRIPTION
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
88 white.
90 If L<Term::ANSIColor> cannot be found (or L<Win32::Console> if running
91 under Windows) tests will be run without color.
93 =head1 SYNOPSIS
95 use TAP::Formatter::Color;
96 my $harness = TAP::Formatter::Color->new( \%args );
97 $harness->runtests(@tests);
99 =head1 METHODS
101 =head2 Class Methods
103 =head3 C<new>
105 The constructor returns a new C<TAP::Formatter::Color> object. If
106 L<Term::ANSIColor> is not installed, returns undef.
108 =cut
110 # new() implementation supplied by TAP::Object
112 sub _initialize {
113 my $self = shift;
115 if ($NO_COLOR) {
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
123 return $self;
126 ##############################################################################
128 =head3 C<can_color>
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.
136 =cut
138 sub can_color {
139 return !$NO_COLOR;
142 =head3 C<set_color>
144 Set the output color.
146 =cut