Jenkins.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 56 CC 3 SCAR 13.3
CC
3
Cov
0%
open_test
6.0
summary
6.0
_save_tap_files
2.0
CRAP 3.8
1 package TAP::Formatter::Jenkins;
2  
3 use Moose;
4 use MooseX::NonMoose;
5 extends qw(
6 TAP::Formatter::Console
7 );
8  
9 use TAP::Formatter::Jenkins::Session;
10 use Data::Dumper;
11  
12 our $VERSION = '0.02';
13  
14 has 'test_suites' => (
15 is => 'rw',
16 isa => 'HashRef',
17 default => sub { {} },
18 );
19  
20 has 'passing_todo_ok' => (
21 is => 'rw',
22 isa => 'Bool',
23 default => 0,
24 );
25  
26 ###############################################################################
27 # Subroutine: open_test($test, $parser)
28 ###############################################################################
29 # Over-ridden 'open_test()' method.
30 #
31 # Creates a 'TAP::Formatter::Jenkins::Session' session, instead of a console
32 # formatter session.
33 sub open_test {
34 my ( $self, $test, $parser ) = @_;
35  
36 $self->passing_todo_ok( $ENV{ALLOW_PASSING_TODOS} ? 1 : 0 );
37  
38 my $session = TAP::Formatter::Jenkins::Session->new( {
39 name => $test,
40 formatter => $self,
41 parser => $parser,
42 passing_todo_ok => $self->passing_todo_ok,
43 } );
44 return $session;
45 }
46  
47 ###############################################################################
48 # Subroutine: summary($aggregate)
49 ###############################################################################
50 # Prints the summary report (in Jenkins TAP Plugin formatting) after all tests are run.
51 sub summary {
52 my ( $self, $aggregate ) = @_;
53  
54 $self->_save_tap_files;
55  
56 return if $self->silent();
57  
58 print { $self->stdout } "ALL DONE\n";
59 }
60  
61 ###############################################################################
62 # Save tests result to tap files
63 sub _save_tap_files {
64 my $self = shift;
65  
66 while ( my ( $test_name, $output ) = each %{ $self->test_suites } ) {
67 my $tap_name = $test_name;
68 $tap_name =~ s/^\///;
69 $tap_name =~ s/\//-/g;
70 $tap_name =~ s/\.t/.tap/;
71  
72 open my $tap_file, ">", $tap_name or die "Can not open file: $_";
73 print { $tap_file } $output;
74 close $tap_file;
75 }
76 }
77  
78 1;
79  
80 =head1 NAME
81  
82 TAP::Formatter::Jenkins - Harness output delegate for Jenkins TAP Plugin
83 output
84  
85 =head1 SYNOPSIS
86  
87 On the command line, with F<prove>:
88  
89 prove --formatter TAP::Formatter::Jenkins ...
90  
91 Or, in your own scripts:
92  
93 use TAP::Harness;
94 my $harness = TAP::Harness->new( {
95 formatter_class => 'TAP::Formatter::Jenkins',
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::Jenkins> provides TAP output formatting for C<TAP::Harness>,
105 which can be used in Jenkins CI server.
106  
107 This module is based on TAP::Formatter::JUnit by Graham TerMarsch
108 <cpan@howlingfrog.com>, main differences are:
109  
110 In standard use, "passing TODOs" are treated as failure conditions (and are
111 reported as such in the generated TAP). If you wish to treat these as a
112 "pass" and not a "fail" condition, setting C<ALLOW_PASSING_TODOS> in your
113 environment will turn these into pass conditions.
114  
115 =over
116  
117 =item * resulting TAP is saved in %test_suite_name%.tap instead of putting it to the stdout
118  
119 =item * converts information about failing tests to YAMLish
120  
121 =back
122  
123 =head1 ATTRIBUTES
124  
125 =over
126  
127 =item test_suites
128  
129 List-ref of test suites that have been executed.
130  
131 =back
132  
133 =head1 METHODS
134  
135 =over
136  
137 =item B<open_test($test, $parser)>
138  
139 Over-ridden C<open_test()> method.
140  
141 Creates a C<TAP::Formatter::Jenkins::Session> session, instead of a console
142 formatter session.
143  
144 =item B<summary($aggregate)>
145  
146 Prints the summary report (in Jenkins TAP Plugin formatting) after all tests are run.
147  
148 =item B<add_testsuite($suite)>
149  
150 Adds the given test C<$suite> to the list of test suites that we've
151 executed and need to summarize.
152  
153 =back
154  
155 =head1 COPYRIGHT
156  
157 This is free software; you can redistribute it and/or modify it under the same
158 terms as Perl itself.
159  
160 =head1 SEE ALSO
161  
162 L<TAP::Formatter::Jenkins::Session>,
163 L<TAP::Formatter::Jenkins::MyParser>,
164  
165 =cut