File Coverage

blib/lib/Test/Run/Plugin/ColorSummary.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Test::Run::Plugin::ColorSummary;
2              
3 1     1   25716 use warnings;
  1         3  
  1         34  
4 1     1   7 use strict;
  1         2  
  1         34  
5              
6 1     1   22 use 5.008;
  1         9  
  1         36  
7              
8 1     1   450 use Moose;
  0            
  0            
9              
10             use MRO::Compat;
11             use Term::ANSIColor;
12             # Needed for ->autoflush()
13             use IO::Handle;
14              
15             extends('Test::Run::Base');
16              
17             =head1 NAME
18              
19             Test::Run::Plugin::ColorSummary - A Test::Run plugin that
20             colors the summary.
21              
22             =head1 VERSION
23              
24             0.0201
25              
26             =cut
27              
28             our $VERSION = '0.0201';
29              
30             has 'summary_color_failure' => (is => "rw", isa => "Str");
31             has 'summary_color_success' => (is => "rw", isa => "Str");
32              
33              
34             sub _get_failure_summary_color
35             {
36             my $self = shift;
37             return $self->summary_color_failure() ||
38             $self->_get_default_failure_summary_color();
39             }
40              
41             sub _get_default_failure_summary_color
42             {
43             return "bold red";
44             }
45              
46             sub _get_success_summary_color
47             {
48             my $self = shift;
49             return $self->summary_color_success() ||
50             $self->_get_default_success_summary_color();
51             }
52              
53             sub _get_default_success_summary_color
54             {
55             return "bold blue";
56             }
57              
58             =head1 SYNOPSIS
59              
60             package MyTestRun;
61              
62             use vars qw(@ISA);
63              
64             @ISA = (qw(Test::Run::Plugin::ColorSummary Test::Run::Obj));
65              
66             my $tester = MyTestRun->new(
67             {
68             test_files =>
69             [
70             "t/sample-tests/one-ok.t",
71             "t/sample-tests/several-oks.t"
72             ],
73             }
74             );
75              
76             $tester->runtests();
77              
78             =head1 EXTRA PARAMETERS TO NEW
79              
80             We accept two new named parameters to the new constructor:
81              
82             =head2 summary_color_success
83              
84             This is the color string for coloring the success line. The string itself
85             conforms to the one specified in L<Term::ANSIColor>.
86              
87             =head2 summary_color_failure
88              
89             This is the color string for coloring the summary line in case of
90             failure. The string itself conforms to the one specified
91             in L<Term::ANSIColor>.
92              
93             =head1 FUNCTIONS
94              
95             =cut
96              
97             sub _report_success
98             {
99             my $self = shift;
100             print color($self->_get_success_summary_color());
101             $self->next::method();
102             print color("reset");
103             }
104              
105             =head2 $tester->_handle_runtests_error()
106              
107             We override _handle_runtests_error() to colour the errors in red. The rest of
108             the documentation is the code.
109              
110             =cut
111              
112             sub _handle_runtests_error_text
113             {
114             my ($self, $args) = @_;
115              
116             my $text = $args->{'text'};
117              
118             STDERR->autoflush();
119             $text =~ s{\n\z}{};
120             die color($self->_get_failure_summary_color()).$text.color("reset")."\n";
121             }
122              
123             1;
124              
125             =head1 AUTHOR
126              
127             Shlomi Fish, C<< <shlomif@iglu.org.il> >>
128              
129             =head1 BUGS
130              
131             Please report any bugs or feature requests to
132             C<bug-test-run-plugin-colorsummary@rt.cpan.org>, or through the web interface at
133             L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Run-Plugin-ColorSummary>.
134             I will be notified, and then you'll automatically be notified of progress on
135             your bug as I make changes.
136              
137             =head1 SUPPORT
138              
139             You can find documentation for this module with the perldoc command.
140              
141             perldoc Test::Run::Plugin::ColorSummary
142              
143             You can also look for information at:
144              
145             =over 4
146              
147             =item * AnnoCPAN: Annotated CPAN documentation
148              
149             L<http://annocpan.org/dist/Test::Run::Plugin::ColorSummary>
150              
151             =item * CPAN Ratings
152              
153             L<http://cpanratings.perl.org/d/Test::Run::Plugin::ColorSummary>
154              
155             =item * RT: CPAN's request tracker
156              
157             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test::Run::Plugin::ColorSummary>
158              
159             =item * Search CPAN
160              
161             L<http://search.cpan.org/dist/Test::Run::Plugin::ColorSummary/>
162              
163             =back
164              
165             =head1 SOURCE AVAILABILITY
166              
167             The latest source of Test::Run::Plugin::ColorSummary is available from the
168             Test::Run BerliOS Subversion repository:
169              
170             L<https://svn.berlios.de/svnroot/repos/web-cpan/Test-Harness-NG/>
171              
172             =head1 SEE ALSO
173              
174             L<Test::Run::Obj>, L<Term::ANSIColor>,
175             L<Test::Run::CmdLine::Plugin::ColorSummary>.
176              
177             =head1 ACKNOWLEDGEMENTS
178              
179             =head1 COPYRIGHT & LICENSE
180              
181             Copyright 2005 Shlomi Fish, all rights reserved.
182              
183             This program is released under the MIT X11 License.
184              
185             =cut
186