blib/lib/Rex/Output/JUnit.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 97 CC 6 SCAR 25.3
CC
6
Cov
0%
write
30.0
add
6.0
new
2.0
CRAP 12.6
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Output::JUnit;
6  
7 use v5.14.4;
8 use warnings;
9  
10 our $VERSION = '1.16.1'; # VERSION
11  
12 use Data::Dumper;
13 use Rex::Template;
14 use base 'Rex::Output::Base';
15  
16 sub new {
17 my $that = shift;
18 my $proto = ref($that) || $that;
19 my $self = {@_};
20  
21 bless( $self, $proto );
22  
23 $self->{time} = time();
24 $self->{error} = "";
25  
26 return $self;
27 }
28  
29 sub add {
30 my ( $self, $task, %option ) = @_;
31 $option{name} = $task;
32 $option{time} = time() - $self->{time};
33  
34 push( @{ $self->{"data"} }, {%option} );
35  
36 if ( exists $option{error} ) {
37 $self->error( $option{msg} );
38 }
39 }
40  
41 sub error {
42 my ( $self, $msg ) = @_;
43 $self->{error} .= $msg . "\n";
44 }
45  
46 sub write {
47 my ($self) = @_;
48  
49 if ( !exists $self->{data} ) { return; }
50  
51 my $t = Rex::Template->new;
52 my $data = eval { local $/; <DATA>; };
53 my $time = time() - $self->{time};
54  
55 if ( !exists $self->{data} ) {
56 return;
57 }
58  
59 if ( scalar( @{ $self->{data} } ) == 0 ) {
60 return;
61 }
62  
63 my $s = $t->parse(
64 $data,
65 {
66 errors => scalar(
67 grep { $_->{"error"} && $_->{"error"} == 1 } @{ $self->{"data"} }
68 ),
69 tests => scalar( @{ $self->{"data"} } ),
70 time_over_all => $time,
71 system_out => $self->{"error"} || "",
72 items => $self->{"data"},
73 }
74 );
75  
76 print $s;
77 if ($s) {
78 open( my $fh, ">", "junit_output.xml" ) or die($!);
79 print $fh $s;
80 close($fh);
81 }
82 }
83  
84 1;
85  
86 __DATA__