blib/lib/TAP/Formatter/JUnitREGRU.pm

filter: Statementstmt 100% 31 / 31 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 97.8% 45 / 46 CC 3 SCAR 3.1
CC
3
Cov
97%
summary
2.0
open_test
2.0
BEGIN
1.0
CRAP 1.4
« Build ↑ Summary blib/script/tap2junit »
1 package TAP::Formatter::JUnitREGRU;
2  
3 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MooseX::NonMoose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 extends qw(
6 TAP::Formatter::Console
7 );
8  
9 4 ▶use XML::Generator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use TAP::Formatter::JUnitREGRU::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 our $VERSION = '0.11';
14  
15 has 'testsuites' => (
16 is => 'rw',
17 isa => 'ArrayRef',
18 6 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 4 traits => [qw( Array )],
20 handles => {
21 add_testsuite => 'push',
22 },
23 );
24  
25 4 has 'xml' => (
26 is => 'rw',
27 isa => 'XML::Generator',
28 lazy_build => 1,
29 );
30 sub _build_xml {
31 6 ▶ return XML::Generator->new(
Subroutine _build_xml: called CC=1 SCAR=0.0
32 ':pretty',
33 ':std',
34 'escape' => 'always,high-bit,even-entities',
35 'encoding' => 'UTF-8',
36 );
37 }
38  
39 ###############################################################################
40 # Subroutine: open_test($test, $parser)
41 ###############################################################################
42 # Over-ridden 'open_test()' method.
43 #
44 # Creates a 'TAP::Formatter::JUnitREGRU::Session' session, instead of a console
45 # formatter session.
46 sub open_test {
47 6 ▶ my ($self, $test, $parser) = @_;
Subroutine open_test: called CC=2 SCAR=6.9
Pod documented
48 my $session = TAP::Formatter::JUnitREGRU::Session->new( {
49 name => $test,
50 formatter => $self,
51 parser => $parser,
52 6 ▶ passing_todo_ok => $ENV{ALLOW_PASSING_TODOS} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'ALLOW_PASSING_TODOS'} ? : 1 5 6
53 } );
54 6 return $session;
55 }
56  
57 ###############################################################################
58 # Subroutine: summary($aggregate)
59 ###############################################################################
60 # Prints the summary report (in JUnit) after all tests are run.
61 sub summary {
62 6 ▶ my ($self, $aggregate) = @_;
Subroutine summary: called CC=2 SCAR=7.0
Pod documented
63 6 ▶ return if $self->silent();
Branch: 1 branch
BranchTrueFalseTotal
if $self->silent 0 6 6
64  
65 6 my @suites = @{$self->testsuites};
66 6 print { $self->stdout } Encode::encode("UTF-8", $self->xml->testsuites( @suites ));
67 }
68  
69 4 1;
70  
71 =head1 NAME
72  
73 TAP::Formatter::JUnitREGRU - Harness output delegate for JUnit output
74  
75 =head1 SYNOPSIS
76  
77 On the command line, with F<prove>:
78  
79 prove --formatter TAP::Formatter::JUnitREGRU ...
80  
81 Or, in your own scripts:
82  
83 use TAP::Harness;
84 my $harness = TAP::Harness->new( {
85 formatter_class => 'TAP::Formatter::JUnitREGRU',
86 merge => 1,
87 } );
88 $harness->runtests(@tests);
89  
90 =head1 DESCRIPTION
91  
92 B<This code is currently in alpha state and is subject to change.>
93  
94 C<TAP::Formatter::JUnitREGRU> provides JUnit output formatting for C<TAP::Harness>.
95  
96 By default (e.g. when run with F<prove>), the I<entire> test suite is gathered
97 together into a single JUnit XML document, which is then displayed on C<STDOUT>.
98 You can, however, have individual JUnit XML files dumped for each individual
99 test, by setting c<PERL_TEST_HARNESS_DUMP_TAP> to a directory that you would
100 like the JUnit XML dumped to. Note, that this will B<also> cause
101 C<TAP::Harness> to dump the original TAP output into that directory as well (but
102 IMHO that's ok as you've now got the data in two parsable formats).
103  
104 Timing information is included in the JUnit XML, I<if> you specified C<--timer>
105 when you ran F<prove>.
106  
107 In standard use, "passing TODOs" are treated as failure conditions (and are
108 reported as such in the generated JUnit). If you wish to treat these as a
109 "pass" and not a "fail" condition, setting C<ALLOW_PASSING_TODOS> in your
110 environment will turn these into pass conditions.
111  
112 The JUnit output generated is partial to being grokked by Hudson
113 (L<http://hudson.dev.java.net/>). That's the build tool I'm using at the
114 moment and needed to be able to generate JUnit output for.
115  
116 =head1 ATTRIBUTES
117  
118 =over
119  
120 =item testsuites
121  
122 List-ref of test suites that have been executed.
123  
124 =item xml
125  
126 An C<XML::Generator> instance, to be used to generate XML output.
127  
128 =back
129  
130 =head1 METHODS
131  
132 =over
133  
134 =item B<open_test($test, $parser)>
135  
136 Over-ridden C<open_test()> method.
137  
138 Creates a C<TAP::Formatter::JUnitREGRU::Session> session, instead of a console
139 formatter session.
140  
141 =item B<summary($aggregate)>
142  
143 Prints the summary report (in JUnit) after all tests are run.
144  
145 =item B<add_testsuite($suite)>
146  
147 Adds the given XML test C<$suite> to the list of test suites that we've
148 executed and need to summarize.
149  
150 =back
151  
152 =head1 AUTHOR
153  
154 Graham TerMarsch <cpan@howlingfrog.com>
155  
156 Many thanks to Andy Armstrong et al. for the B<fabulous> set of tests in
157 C<Test::Harness>; they became the basis for the unit tests here.
158  
159 Other thanks go out to those that have provided feedback, comments, or patches:
160  
161 Mark Aufflick
162 Joe McMahon
163 Michael Nachbaur
164 Marc Abramowitz
165 Colin Robertson
166 Phillip Kimmey
167 Dave Lambley
168  
169 =head1 COPYRIGHT
170  
171 Copyright 2008-2010, Graham TerMarsch. All Rights Reserved.
172  
173 This is free software; you can redistribute it and/or modify it under the same
174 terms as Perl itself.
175  
176 =head1 SEE ALSO
177  
178 L<TAP::Formatter::Console>,
179 L<TAP::Formatter::JUnitREGRU::Session>,
180 L<http://hudson.dev.java.net/>,
181 L<http://jra1mw.cvs.cern.ch:8180/cgi-bin/jra1mw.cgi/org.glite.testing.unit/config/JUnitXSchema.xsd?view=markup&content-type=text%2Fvnd.viewcvs-markup&revision=HEAD>,
182 L<http://confluence.atlassian.com/display/BAMBOO/JUnit+parsing+in+Bamboo>.
183  
184 =cut
« Build ↑ Summary blib/script/tap2junit »