| 1 | package TAP::Formatter::JUnit; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use MooseX::NonMoose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 5 | extends qw( | |||||||||
| 6 | TAP::Formatter::Console | ||||||||||
| 7 | ); | ||||||||||
| 8 | |||||||||||
| 9 | 5 | ▶ | use XML::Generator; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 5 | ▶ | use TAP::Formatter::JUnit::Session; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 5 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 5 | our $VERSION = '0.15'; | |||||||||
| 14 | |||||||||||
| 15 | has 'testsuites' => ( | ||||||||||
| 16 | is => 'rw', | ||||||||||
| 17 | isa => 'ArrayRef', | ||||||||||
| 18 | 6 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 5 | traits => [qw( Array )], | |||||||||
| 20 | handles => { | ||||||||||
| 21 | add_testsuite => 'push', | ||||||||||
| 22 | }, | ||||||||||
| 23 | ); | ||||||||||
| 24 | |||||||||||
| 25 | 5 | 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::JUnit::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::JUnit::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
| |||||||||||
| 53 | } ); | ||||||||||
| 54 | 6 | return $session; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | ############################################################################### | ||||||||||
| 58 | # Subroutine: summary() | ||||||||||
| 59 | ############################################################################### | ||||||||||
| 60 | # Prints the summary report (in JUnit) after all tests are run. | ||||||||||
| 61 | sub summary { | ||||||||||
| 62 | 6 | ▶ | my $self = shift; | ||||||||
|
Subroutine
summary: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 63 | 6 | ▶ | return if $self->silent(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | 6 | my @suites = @{$self->testsuites}; | |||||||||
| 66 | 6 | print { $self->stdout } $self->xml->testsuites( @suites ); | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 5 | 1; | |||||||||
| 70 | |||||||||||
| 71 | =for stopwords xml testsuites TODO parseable JUnitXSchema.xsd | ||||||||||
| 72 | |||||||||||
| 73 | =head1 NAME | ||||||||||
| 74 | |||||||||||
| 75 | TAP::Formatter::JUnit - Harness output delegate for JUnit output | ||||||||||
| 76 | |||||||||||
| 77 | =head1 SYNOPSIS | ||||||||||
| 78 | |||||||||||
| 79 | On the command line, with F<prove>: | ||||||||||
| 80 | |||||||||||
| 81 | =for test_synopsis BEGIN { die "SKIP: This isn't Perl, but shell" } | ||||||||||
| 82 | |||||||||||
| 83 | $ prove --formatter TAP::Formatter::JUnit ... | ||||||||||
| 84 | |||||||||||
| 85 | Or, in your own scripts: | ||||||||||
| 86 | |||||||||||
| 87 | use TAP::Harness; | ||||||||||
| 88 | |||||||||||
| 89 | # What TAP output did we save from a previous run, with | ||||||||||
| 90 | # PERL_TEST_HARNESS_DUMP_TAP=tap/ | ||||||||||
| 91 | my @tests = glob("tap/*.t"); | ||||||||||
| 92 | |||||||||||
| 93 | # Convert the TAP to JUnit | ||||||||||
| 94 | my $harness = TAP::Harness->new( { | ||||||||||
| 95 | formatter_class => 'TAP::Formatter::JUnit', | ||||||||||
| 96 | merge => 1, | ||||||||||
| 97 | } ); | ||||||||||
| 98 | $harness->runtests(@tests); | ||||||||||
| 99 | |||||||||||
| 100 | =head1 DESCRIPTION | ||||||||||
| 101 | |||||||||||
| 102 | B<This code is currently in alpha state and is subject to change.> | ||||||||||
| 103 | |||||||||||
| 104 | C<TAP::Formatter::JUnit> provides JUnit output formatting for C<TAP::Harness>. | ||||||||||
| 105 | |||||||||||
| 106 | By default (e.g. when run with F<prove>), the I<entire> test suite is gathered | ||||||||||
| 107 | together into a single JUnit XML document, which is then displayed on C<STDOUT>. | ||||||||||
| 108 | You can, however, have individual JUnit XML files dumped for each individual | ||||||||||
| 109 | test, by setting C<PERL_TEST_HARNESS_DUMP_TAP> to a directory that you would | ||||||||||
| 110 | like the JUnit XML dumped to. Note, that this will B<also> cause | ||||||||||
| 111 | C<TAP::Harness> to dump the original TAP output into that directory as well (but | ||||||||||
| 112 | IMHO that's ok as you've now got the data in two parseable formats). | ||||||||||
| 113 | |||||||||||
| 114 | Timing information is included in the JUnit XML, I<if> you specified C<--timer> | ||||||||||
| 115 | when you ran F<prove>. | ||||||||||
| 116 | |||||||||||
| 117 | In standard use, a "passing TODO" is treated as failure conditions (and is | ||||||||||
| 118 | reported as such in the generated JUnit). If you wish to treat these as a | ||||||||||
| 119 | "pass" and not a "fail" condition, setting C<ALLOW_PASSING_TODOS> in your | ||||||||||
| 120 | environment will turn these into pass conditions. | ||||||||||
| 121 | |||||||||||
| 122 | The JUnit output generated is partial to being grokked by Hudson | ||||||||||
| 123 | (L<http://hudson.dev.java.net/>). That's the build tool I'm using at the | ||||||||||
| 124 | moment and needed to be able to generate JUnit output for. | ||||||||||
| 125 | |||||||||||
| 126 | =head1 ATTRIBUTES | ||||||||||
| 127 | |||||||||||
| 128 | =over | ||||||||||
| 129 | |||||||||||
| 130 | =item testsuites | ||||||||||
| 131 | |||||||||||
| 132 | List-ref of test suites that have been executed. | ||||||||||
| 133 | |||||||||||
| 134 | =item xml | ||||||||||
| 135 | |||||||||||
| 136 | An C<XML::Generator> instance, to be used to generate XML output. | ||||||||||
| 137 | |||||||||||
| 138 | =back | ||||||||||
| 139 | |||||||||||
| 140 | =head1 METHODS | ||||||||||
| 141 | |||||||||||
| 142 | =over | ||||||||||
| 143 | |||||||||||
| 144 | =item open_test($test, $parser) | ||||||||||
| 145 | |||||||||||
| 146 | Over-ridden C<open_test()> method. | ||||||||||
| 147 | |||||||||||
| 148 | Creates a C<TAP::Formatter::JUnit::Session> session, instead of a console | ||||||||||
| 149 | formatter session. | ||||||||||
| 150 | |||||||||||
| 151 | =item summary() | ||||||||||
| 152 | |||||||||||
| 153 | Prints the summary report (in JUnit) after all tests are run. | ||||||||||
| 154 | |||||||||||
| 155 | =item add_testsuite($suite) | ||||||||||
| 156 | |||||||||||
| 157 | Adds the given XML test C<$suite> to the list of test suites that we've | ||||||||||
| 158 | executed and need to summarize. | ||||||||||
| 159 | |||||||||||
| 160 | =back | ||||||||||
| 161 | |||||||||||
| 162 | =head1 AUTHOR | ||||||||||
| 163 | |||||||||||
| 164 | Graham TerMarsch <cpan@howlingfrog.com> | ||||||||||
| 165 | |||||||||||
| 166 | Many thanks to Andy Armstrong and all those involved for the B<fabulous> set of | ||||||||||
| 167 | tests in C<Test::Harness>; they became the basis for the unit tests here. | ||||||||||
| 168 | |||||||||||
| 169 | Other thanks go out to those that have provided feedback, comments, or patches: | ||||||||||
| 170 | |||||||||||
| 171 | Mark Aufflick | ||||||||||
| 172 | Joe McMahon | ||||||||||
| 173 | Michael Nachbaur | ||||||||||
| 174 | Marc Abramowitz | ||||||||||
| 175 | Colin Robertson | ||||||||||
| 176 | Phillip Kimmey | ||||||||||
| 177 | Dave Lambley | ||||||||||
| 178 | |||||||||||
| 179 | =head1 COPYRIGHT | ||||||||||
| 180 | |||||||||||
| 181 | Copyright 2008-2010, Graham TerMarsch. All Rights Reserved. | ||||||||||
| 182 | |||||||||||
| 183 | This is free software; you can redistribute it and/or modify it under the same | ||||||||||
| 184 | terms as Perl itself. | ||||||||||
| 185 | |||||||||||
| 186 | =head1 SEE ALSO | ||||||||||
| 187 | |||||||||||
| 188 | =over | ||||||||||
| 189 | |||||||||||
| 190 | =item L<TAP::Formatter::Console> | ||||||||||
| 191 | |||||||||||
| 192 | =item L<TAP::Formatter::JUnit::Session> | ||||||||||
| 193 | |||||||||||
| 194 | =item L<Hudson home page|http://hudson.dev.java.net/> | ||||||||||
| 195 | |||||||||||
| 196 | =item L<JUnitXSchema.xsd|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> | ||||||||||
| 197 | |||||||||||
| 198 | =item L<JUnit parsing in Bamboo|http://confluence.atlassian.com/display/BAMBOO/JUnit+parsing+in+Bamboo>. | ||||||||||
| 199 | |||||||||||
| 200 | =back | ||||||||||
| 201 | |||||||||||
| 202 | =cut | ||||||||||