Bamboo.pm

filter: Statementstmt 30.6% 19 / 62 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 55.5% 5 / 9 Podpod 100% 2 / 2 totaltotal 31.7% 26 / 82 CC 7 SCAR 25.6
CC
7
Cov
27%
_save_results
30.0
summary
12.0
__ANON__
2.0
CRAP 13.0
« Bamboo/Session.pm ↑ Summary
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_02';
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 sub open_test {
23 0 ▶ my ($self, $test, $parser) = @_;
Subroutine open_test: not called CC=1 SCAR=6.9
Pod documented
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 sub summary {
33 0 ▶ my ($self, $aggregate) = @_;
Subroutine summary: not called CC=3 SCAR=24.8
Pod documented
34  
35 0 ▶ $self->_save_results( $ENV{TAP_FORMATTER_BAMBOO_OUTFILE} || 'results.xml');
Condition0%0/2
$ENV{'TAP_FORMATTER_BAMBOO_OUTFILE'} || 'results.xml'
l!l
00
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'}
Aresult
11
00
36  
37 0 ▶ return if $self->silent();
Branch: 1 branch
BranchTrueFalseTotal
if $self->silent 0 0 0
38  
39 0 print { $self->stdout } "ALL DONE\n";
40 }
41  
42 sub _save_results {
43 0 ▶ my( $self, $file_path ) = @_;
Subroutine _save_results: not called CC=5 SCAR=34.0
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
BranchTrueFalseTotal
if ($test->{"fail_reasons"}) 0 0 0
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
BranchTrueFalseTotal
unless (&is_utf8($fail_description)) 0 0 0
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 =pod
98  
99 =encoding utf8
100  
101 =head1 NAME
102  
103 TAP::Formatter::Bamboo - Harness output delegate for Atlassian's Bamboo CI server
104  
105 =head1 SYNOPSIS
106  
107 On the command line, with F<prove>:
108  
109 prove --formatter TAP::Formatter::Bamboo ...
110  
111 Or, in your own scripts:
112  
113 use TAP::Harness;
114 my $harness = TAP::Harness->new( {
115 formatter_class => 'TAP::Formatter::Bamboo',
116 merge => 1,
117 } );
118 $harness->runtests(@tests);
119  
120 =head1 DESCRIPTION
121  
122 C<TAP::Formatter::Bamboo> provides JUnit output formatting for C<TAP::Harness>,
123 which can be used in Atlassian's Bamboo CI server.
124  
125 This module is based on TAP::Formatter::JUnit by Graham TerMarsch
126 <cpan@howlingfrog.com>, main differences are:
127  
128 =over
129  
130 =item * if environment variable TAP_FORMATTER_BAMBOO_OUTFILE is present then it
131 will be used as filepath for output XML (otherwise "results.xml file will be
132 created in current directory)
133  
134 =item * information about passing/failing tests is put to the STDOUT/STDERR respectively,
135 so it can be watched in Bamboo's build logs (also live during build)
136  
137 =item * output of failed tests is saved in 'failure' tag, as Bamboo doesn't care about
138 'system-out' and 'system-err' tags (but shows content of 'failure')
139  
140 =item * short information about failure reason is put in the first line of 'failure' tag
141  
142 =back
143  
144 =head1 METHODS
145  
146 =over
147  
148 =item B<open_test($test, $parser)>
149  
150 Over-ridden C<open_test()> method.
151  
152 Creates a C<TAP::Formatter::Bamboo::Session> session, instead of a console
153 formatter session.
154  
155 =item B<summary($aggregate)>
156  
157 Save resulting XML in results.xml file.
158  
159 =back
160  
161 =head1 AUTHOR
162  
163 Piotr Piątkowski <pp@idea7.pl>
164  
165 =head2 Patches, contributors
166  
167 =over 4
168  
169 =item * Bartłomiej Fulanty <starlight@cpan.org>
170  
171 =item * Bartosz Jakubski <bjakubski@cpan.org>
172  
173 =item * Graham TerMarsch <cpan@howlingfrog.com> (original C<TAP::Formatter::JUnit>)
174  
175 =back
176  
177 =head2 Credits from the original module:
178  
179 Many thanks to Andy Armstrong et al. for the B<fabulous> set of tests in
180 C<Test::Harness>; they became the basis for the unit tests here.
181  
182 Other thanks go out to those that have provided feedback, comments, or patches:
183  
184 Mark Aufflick
185 Joe McMahon
186 Michael Nachbaur
187 Marc Abramowitz
188 Colin Robertson
189 Phillip Kimmey
190 Dave Lambley
191  
192 =head1 COPYRIGHT
193  
194 This is free software; you can redistribute it and/or modify it under the same
195 terms as Perl itself.
196  
197 =head1 SEE ALSO
198  
199 L<TAP::Formatter::JUnit>,
200 L<TAP::Formatter::Console>,
201 L<http://confluence.atlassian.com/display/BAMBOO/JUnit+parsing+in+Bamboo>.
202  
203 =cut
« Bamboo/Session.pm ↑ Summary