| 1 | package TAP::Formatter::Bamboo; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use MooseX::NonMoose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use XML::LibXML; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use Encode qw(:all); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 1 | ▶ | use TAP::Formatter::Bamboo::Session; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 1 | extends qw( | |||||||||||
| 11 | TAP::Formatter::Console | ||||||||||||
| 12 | ); | ||||||||||||
| 13 | |||||||||||||
| 14 | 1 | our $VERSION = '0.04'; | |||||||||||
| 15 | |||||||||||||
| 16 | has _test_results => ( | ||||||||||||
| 17 | is => 'rw', | ||||||||||||
| 18 | isa => 'ArrayRef', | ||||||||||||
| 19 | 0 | ▶ | default => sub { [] }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 20 | 1 | ); | |||||||||||
| 21 | |||||||||||||
| 22 | 0 | ▶ | sub open_test { | ||||||||||
|
Subroutine
open_test: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 23 | 0 | my ($self, $test, $parser) = @_; | |||||||||||
| 24 | 0 | my $session = TAP::Formatter::Bamboo::Session->new( { | |||||||||||
| 25 | name => $test, | ||||||||||||
| 26 | formatter => $self, | ||||||||||||
| 27 | parser => $parser, | ||||||||||||
| 28 | } ); | ||||||||||||
| 29 | 0 | return $session; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 0 | ▶ | sub summary { | ||||||||||
|
Subroutine
summary: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 33 | 0 | my ($self, $aggregate) = @_; | |||||||||||
| 34 | |||||||||||||
| 35 | 0 | ▶ | $self->_save_results( $ENV{TAP_FORMATTER_BAMBOO_OUTFILE} || 'results.xml'); | ||||||||||
|
Condition0%0/2
$ENV{'TAP_FORMATTER_BAMBOO_OUTFILE'} || 'results.xml'
MC/DC0%0/1
$ENV{'TAP_FORMATTER_BAMBOO_OUTFILE'} || 'results.xml'
$ENV{'TAP_FORMATTER_BAMBOO_OUTFILE'}
Truth table0%0/2
A
A= $ENV{'TAP_FORMATTER_BAMBOO_OUTFILE'}
| |||||||||||||
| 36 | |||||||||||||
| 37 | 0 | ▶ | return if $self->silent(); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | |||||||||||||
| 39 | 0 | print { $self->stdout } "ALL DONE\n"; | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | sub _save_results { | ||||||||||
|
Subroutine
_save_results: not called CC=5 SCAR=34.0
| |||||||||||||
| 43 | 0 | my( $self, $file_path ) = @_; | |||||||||||
| 44 | |||||||||||||
| 45 | 0 | my $doc = XML::LibXML::Document->createDocument('1.0', 'UTF-8'); | |||||||||||
| 46 | 0 | $doc->setStandalone( 1 ); | |||||||||||
| 47 | 0 | my $suites = $doc->createElement( 'testsuites' ); | |||||||||||
| 48 | |||||||||||||
| 49 | 0 | for my $test ( @{$self->_test_results} ) { | |||||||||||
| 50 | |||||||||||||
| 51 | 0 | my $suite = $doc->createElement( 'testsuite' ); | |||||||||||
| 52 | 0 | $suite->setAttribute( 'name', $test->{description} ); | |||||||||||
| 53 | 0 | $suite->setAttribute( 'errors', $test->{parse_errors} ); | |||||||||||
| 54 | 0 | $suite->setAttribute( 'failures', $test->{failed} ); | |||||||||||
| 55 | 0 | $suite->setAttribute( 'tests', $test->{tests_run} ); | |||||||||||
| 56 | |||||||||||||
| 57 | 0 | my $output = $doc->createElement( 'system-out' ); | |||||||||||
| 58 | 0 | $suite->appendChild( $output ); | |||||||||||
| 59 | |||||||||||||
| 60 | 0 | my $testcase = $doc->createElement( 'testcase' ); | |||||||||||
| 61 | 0 | $testcase->setAttribute( 'name', $test->{description} ); | |||||||||||
| 62 | 0 | $testcase->setAttribute( 'time', $test->{end_time} - $test->{start_time} ); | |||||||||||
| 63 | |||||||||||||
| 64 | 0 | $suite->appendChild( $testcase ); | |||||||||||
| 65 | |||||||||||||
| 66 | 0 | ▶ | if( $test->{fail_reasons} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 67 | 0 | my $failure = $doc->createElement( 'failure' ); | |||||||||||
| 68 | 0 | my $fail_description = ''; | |||||||||||
| 69 | 0 | $fail_description .= "Fail reason(s):\n"; | |||||||||||
| 70 | 0 | for my $fail ( @{$test->{fail_reasons}} ) { | |||||||||||
| 71 | 0 | $fail_description .= " $fail\n"; | |||||||||||
| 72 | } | ||||||||||||
| 73 | 0 | $fail_description .= "Test output:\n" . $test->{output} . "\n"; | |||||||||||
| 74 | |||||||||||||
| 75 | 0 | ▶ | if (not is_utf8($fail_description)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | |||||||||||||
| 77 | # this will quietly substitute any malformed UTF-8 data it finds | ||||||||||||
| 78 | # if you'd need to make it more facist, pass Encode::FB_CROAK as | ||||||||||||
| 79 | # a third parameter | ||||||||||||
| 80 | 0 | $fail_description = encode("UTF-8", $fail_description); | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 0 | $failure->appendChild( XML::LibXML::CDATASection->new( $fail_description ) ); | |||||||||||
| 84 | 0 | $testcase->appendChild( $failure ); | |||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | 0 | $suite->appendChild( $testcase ); | |||||||||||
| 88 | 0 | $suites->appendChild( $suite ); | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | 0 | $doc->setDocumentElement( $suites ); | |||||||||||
| 92 | 0 | $doc->toFile( $file_path, 2 ); | |||||||||||
| 93 | 0 | return; | |||||||||||
| 94 | } | ||||||||||||
| 95 | 1 | 1; | |||||||||||
| 96 | |||||||||||||
| 97 | =encoding utf8 | ||||||||||||
| 98 | |||||||||||||
| 99 | =head1 NAME | ||||||||||||
| 100 | |||||||||||||
| 101 | TAP::Formatter::Bamboo - Harness output delegate for Atlassian's Bamboo CI server | ||||||||||||
| 102 | |||||||||||||
| 103 | =head1 SYNOPSIS | ||||||||||||
| 104 | |||||||||||||
| 105 | On the command line, with F<prove>: | ||||||||||||
| 106 | |||||||||||||
| 107 | prove --formatter TAP::Formatter::Bamboo ... | ||||||||||||
| 108 | |||||||||||||
| 109 | Or, in your own scripts: | ||||||||||||
| 110 | |||||||||||||
| 111 | use TAP::Harness; | ||||||||||||
| 112 | my $harness = TAP::Harness->new( { | ||||||||||||
| 113 | formatter_class => 'TAP::Formatter::Bamboo', | ||||||||||||
| 114 | merge => 1, | ||||||||||||
| 115 | } ); | ||||||||||||
| 116 | $harness->runtests(@tests); | ||||||||||||
| 117 | |||||||||||||
| 118 | =head1 DESCRIPTION | ||||||||||||
| 119 | |||||||||||||
| 120 | C<TAP::Formatter::Bamboo> provides JUnit output formatting for C<TAP::Harness>, | ||||||||||||
| 121 | which can be used in Atlassian's Bamboo CI server. | ||||||||||||
| 122 | |||||||||||||
| 123 | This module is based on TAP::Formatter::JUnit by Graham TerMarsch | ||||||||||||
| 124 | <cpan@howlingfrog.com>, main differences are: | ||||||||||||
| 125 | |||||||||||||
| 126 | =over | ||||||||||||
| 127 | |||||||||||||
| 128 | =item * if environment variable TAP_FORMATTER_BAMBOO_OUTFILE is present then it | ||||||||||||
| 129 | will be used as filepath for output XML (otherwise "results.xml file will be | ||||||||||||
| 130 | created in current directory) | ||||||||||||
| 131 | |||||||||||||
| 132 | =item * information about passing/failing tests is put to the STDOUT/STDERR respectively, | ||||||||||||
| 133 | so it can be watched in Bamboo's build logs (also live during build) | ||||||||||||
| 134 | |||||||||||||
| 135 | =item * output of failed tests is saved in 'failure' tag, as Bamboo doesn't care about | ||||||||||||
| 136 | 'system-out' and 'system-err' tags (but shows content of 'failure') | ||||||||||||
| 137 | |||||||||||||
| 138 | =item * short information about failure reason is put in the first line of 'failure' tag | ||||||||||||
| 139 | |||||||||||||
| 140 | =back | ||||||||||||
| 141 | |||||||||||||
| 142 | =head1 METHODS | ||||||||||||
| 143 | |||||||||||||
| 144 | =over | ||||||||||||
| 145 | |||||||||||||
| 146 | =item B<open_test($test, $parser)> | ||||||||||||
| 147 | |||||||||||||
| 148 | Over-ridden C<open_test()> method. | ||||||||||||
| 149 | |||||||||||||
| 150 | Creates a C<TAP::Formatter::Bamboo::Session> session, instead of a console | ||||||||||||
| 151 | formatter session. | ||||||||||||
| 152 | |||||||||||||
| 153 | =item B<summary($aggregate)> | ||||||||||||
| 154 | |||||||||||||
| 155 | Save resulting XML in results.xml file. | ||||||||||||
| 156 | |||||||||||||
| 157 | =back | ||||||||||||
| 158 | |||||||||||||
| 159 | =head1 AUTHOR | ||||||||||||
| 160 | |||||||||||||
| 161 | Piotr Piatkowski <pp@idea7.pl> | ||||||||||||
| 162 | |||||||||||||
| 163 | Graham TerMarsch <cpan@howlingfrog.com> (original C<TAP::Formatter::JUnit>) | ||||||||||||
| 164 | |||||||||||||
| 165 | Credits from the original module: | ||||||||||||
| 166 | |||||||||||||
| 167 | Many thanks to Andy Armstrong et al. for the B<fabulous> set of tests in | ||||||||||||
| 168 | C<Test::Harness>; they became the basis for the unit tests here. | ||||||||||||
| 169 | |||||||||||||
| 170 | Other thanks go out to those that have provided feedback, comments, or patches: | ||||||||||||
| 171 | |||||||||||||
| 172 | Mark Aufflick | ||||||||||||
| 173 | Joe McMahon | ||||||||||||
| 174 | Michael Nachbaur | ||||||||||||
| 175 | Marc Abramowitz | ||||||||||||
| 176 | Colin Robertson | ||||||||||||
| 177 | Phillip Kimmey | ||||||||||||
| 178 | Dave Lambley | ||||||||||||
| 179 | |||||||||||||
| 180 | =head1 COPYRIGHT | ||||||||||||
| 181 | |||||||||||||
| 182 | This is free software; you can redistribute it and/or modify it under the same | ||||||||||||
| 183 | terms as Perl itself. | ||||||||||||
| 184 | |||||||||||||
| 185 | =head1 SEE ALSO | ||||||||||||
| 186 | |||||||||||||
| 187 | L<TAP::Formatter::JUnit>, | ||||||||||||
| 188 | L<TAP::Formatter::Console>, | ||||||||||||
| 189 | L<http://confluence.atlassian.com/display/BAMBOO/JUnit+parsing+in+Bamboo>. | ||||||||||||
| 190 | |||||||||||||
| 191 | =cut | ||||||||||||