blib/lib/TAP/Formatter/Color.pm

filter: Statementstmt 68.5% 24 / 35 Branchbran 40.0% 4 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 1 / 1 totaltotal 63.6% 35 / 55 CC 6 SCAR 15.1
CC
6
Cov
62%
BEGIN
9.7
_initialize
2.5
__ANON__
2.0
CRAP 4.5
« blib/lib/TAP/Parser/Aggregator.pm ↑ Summary blib/lib/TAP/Parser/SourceHandler/RawTAP.pm »
1 package TAP::Formatter::Color;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use base 'TAP::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 my $NO_COLOR;
11  
12 3 ▶BEGIN {
Subroutine BEGIN: called CC=5 SCAR=22.7
13 3 $NO_COLOR = 0;
14  
15 3 eval 'require Term::ANSIColor';
16 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
17 0 $NO_COLOR = $@;
18 };
19 3 ▶ if (IS_WIN32) {
Branch: 1 branch
BranchTrueFalseTotal
if (&IS_WIN32()) 0 3 3
20 0 eval 'use Win32::Console::ANSI';
21 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
22 0 $NO_COLOR = $@;
23 }
24 };
25  
26 3 ▶ if ($NO_COLOR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NO_COLOR) { } 0 3 3
27 0 ▶ *set_color = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 } else {
29 0 ▶ *set_color = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 0 my ( $self, $output, $color ) = @_;
31 0 $output->( Term::ANSIColor::color($color) );
32 3 };
33 }
34 }
35  
36 =head1 NAME
37  
38 TAP::Formatter::Color - Run Perl test scripts with color
39  
40 =head1 VERSION
41  
42 Version 3.52
43  
44 =cut
45  
46 3 our $VERSION = '3.52';
47  
48 =head1 DESCRIPTION
49  
50 Note that this harness is I<experimental>. You may not like the colors I've
51 chosen and I haven't yet provided an easy way to override them.
52  
53 This test harness is the same as L<TAP::Harness>, but test results are output
54 in color. Passing tests are printed in green. Failing tests are in red.
55 Skipped tests are blue on a white background and TODO tests are printed in
56 white.
57  
58 If L<Term::ANSIColor> cannot be found (and L<Win32::Console::ANSI> if running
59 under Windows) tests will be run without color.
60  
61 =head1 SYNOPSIS
62  
63 use TAP::Formatter::Color;
64 my $harness = TAP::Formatter::Color->new( \%args );
65 $harness->runtests(@tests);
66  
67 =head1 METHODS
68  
69 =head2 Class Methods
70  
71 =head3 C<new>
72  
73 The constructor returns a new C<TAP::Formatter::Color> object. If
74 L<Term::ANSIColor> is not installed, returns undef.
75  
76 =cut
77  
78 # new() implementation supplied by TAP::Object
79  
80 2 ▶sub _initialize {
Subroutine _initialize: called CC=2 SCAR=9.2
81 2 my $self = shift;
82  
83 2 ▶ if ($NO_COLOR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($NO_COLOR) 0 2 2
84  
85 # shorten that message a bit
86 0 ( my $error = $NO_COLOR ) =~ s/ in \@INC .*//s;
87 0 warn "Note: Cannot run tests in color: $error\n";
88 0 return; # abort object construction
89 }
90  
91 2 return $self;
92 }
93  
94 ##############################################################################
95  
96 =head3 C<can_color>
97  
98 Test::Formatter::Color->can_color()
99  
100 Returns a boolean indicating whether or not this module can actually
101 generate colored output. This will be false if it could not load the
102 modules needed for the current platform.
103  
104 =cut
105  
106 0 ▶sub can_color {
Subroutine can_color: not called CC=1 SCAR=6.9
Pod documented
107 0 return !$NO_COLOR;
108 }
109  
110 =head3 C<set_color>
111  
112 Set the output color.
113  
114 =cut
115  
116 3 1;
« blib/lib/TAP/Parser/Aggregator.pm ↑ Summary blib/lib/TAP/Parser/SourceHandler/RawTAP.pm »