| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package TAP::Formatter::Color; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1466
|
use strict; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
57
|
|
|
4
|
2
|
|
|
2
|
|
18
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
111
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
8
|
use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ ); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
147
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
9
|
use base 'TAP::Object'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
702
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $NO_COLOR; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN { |
|
13
|
2
|
|
|
2
|
|
4
|
$NO_COLOR = 0; |
|
14
|
|
|
|
|
|
|
|
|
15
|
2
|
50
|
|
|
|
10
|
if (IS_WIN32) { |
|
16
|
0
|
|
|
|
|
0
|
eval 'use Win32::Console'; |
|
17
|
0
|
0
|
|
|
|
0
|
if ($@) { |
|
18
|
0
|
|
|
|
|
0
|
$NO_COLOR = $@; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
else { |
|
21
|
0
|
|
|
|
|
0
|
my $console = Win32::Console->new( STD_OUTPUT_HANDLE() ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# eval here because we might not know about these variables |
|
24
|
0
|
|
|
|
|
0
|
my $fg = eval '$FG_LIGHTGRAY'; |
|
25
|
0
|
|
|
|
|
0
|
my $bg = eval '$BG_BLACK'; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
*set_color = sub { |
|
28
|
0
|
|
|
|
|
0
|
my ( $self, $output, $color ) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
my $var; |
|
31
|
0
|
0
|
|
|
|
0
|
if ( $color eq 'reset' ) { |
|
|
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
$fg = eval '$FG_LIGHTGRAY'; |
|
33
|
0
|
|
|
|
|
0
|
$bg = eval '$BG_BLACK'; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
elsif ( $color =~ /^on_(.+)$/ ) { |
|
36
|
0
|
|
|
|
|
0
|
$bg = eval '$BG_' . uc($1); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
else { |
|
39
|
0
|
|
|
|
|
0
|
$fg = eval '$FG_' . uc($color); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# In case of colors that aren't defined |
|
43
|
0
|
0
|
0
|
|
|
0
|
$self->set_color('reset') |
|
44
|
|
|
|
|
|
|
unless defined $bg && defined $fg; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
0
|
$console->Attr( $bg | $fg ); |
|
47
|
0
|
|
|
|
|
0
|
}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
else { |
|
51
|
2
|
|
|
2
|
|
143
|
eval 'use Term::ANSIColor'; |
|
|
2
|
|
|
|
|
1699
|
|
|
|
2
|
|
|
|
|
11849
|
|
|
|
2
|
|
|
|
|
95
|
|
|
52
|
2
|
50
|
|
|
|
9
|
if ($@) { |
|
53
|
0
|
|
|
|
|
0
|
$NO_COLOR = $@; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
else { |
|
56
|
|
|
|
|
|
|
*set_color = sub { |
|
57
|
0
|
|
|
0
|
|
0
|
my ( $self, $output, $color ) = @_; |
|
58
|
0
|
|
|
|
|
0
|
$output->( color($color) ); |
|
59
|
2
|
|
|
|
|
11
|
}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
2
|
50
|
|
|
|
277
|
if ($NO_COLOR) { |
|
64
|
0
|
|
|
|
|
0
|
*set_color = sub { }; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 NAME |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
TAP::Formatter::Color - Run Perl test scripts with color |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 VERSION |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Version 3.38 |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
our $VERSION = '3.38'; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Note that this harness is I. You may not like the colors I've |
|
83
|
|
|
|
|
|
|
chosen and I haven't yet provided an easy way to override them. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This test harness is the same as L, 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. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
If L cannot be found (or L if running |
|
91
|
|
|
|
|
|
|
under Windows) tests will be run without color. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
use TAP::Formatter::Color; |
|
96
|
|
|
|
|
|
|
my $harness = TAP::Formatter::Color->new( \%args ); |
|
97
|
|
|
|
|
|
|
$harness->runtests(@tests); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 METHODS |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 Class Methods |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head3 C |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
The constructor returns a new C object. If |
|
106
|
|
|
|
|
|
|
L is not installed, returns undef. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# new() implementation supplied by TAP::Object |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _initialize { |
|
113
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
|
114
|
|
|
|
|
|
|
|
|
115
|
1
|
50
|
|
|
|
2
|
if ($NO_COLOR) { |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# shorten that message a bit |
|
118
|
0
|
|
|
|
|
0
|
( my $error = $NO_COLOR ) =~ s/ in \@INC .*//s; |
|
119
|
0
|
|
|
|
|
0
|
warn "Note: Cannot run tests in color: $error\n"; |
|
120
|
0
|
|
|
|
|
0
|
return; # abort object construction |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
18
|
return $self; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
############################################################################## |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head3 C |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Test::Formatter::Color->can_color() |
|
131
|
|
|
|
|
|
|
|
|
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. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub can_color { |
|
139
|
0
|
|
|
0
|
1
|
|
return !$NO_COLOR; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head3 C |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Set the output color. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |