File Coverage

blib/lib/Test/Litmus/Result.pm
Criterion Covered Total %
statement 6 53 11.3
branch 0 18 0.0
condition n/a
subroutine 2 6 33.3
pod 0 4 0.0
total 8 81 9.8


line stmt bran cond sub pod time code
1             # The contents of this file are subject to the Mozilla Public License Version
2             # 1.1 (the "License"); you may not use this file except in compliance with
3             # the License. You may obtain a copy of the License at
4             # http://www.mozilla.org/MPL/
5             #
6             # Software distributed under the License is distributed on an "AS IS" basis,
7             # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8             # for the specific language governing rights and limitations under the
9             # License.
10             #
11             # The Original Code is Test::Litmus.
12             #
13             # The Initial Developer of the Original Code is The Mozilla Corporation.
14             #
15             # Portions created by the Initial Developer are Copyright (C) 2006
16             # the Initial Developer. All Rights Reserved.
17             #
18             # Contributor(s): Zach Lipton
19              
20             package Test::Litmus::Result;
21              
22 1     1   12 use v5.6.1;
  1         3  
  1         44  
23 1     1   5 use strict;
  1         2  
  1         737  
24              
25             our $VERSION = '0.01';
26              
27             sub new {
28 0     0 0   my $class = shift;
29 0           my %args = @_;
30 0           my $self = {};
31 0           bless $self;
32            
33 0           $self->requiredField('testid', %args);
34 0 0         if ($args{'-resultstatus'} =~ /pass/i) { $self->{'resultstatus'} = 'Pass' }
  0 0          
35 0           elsif ($args{'-resultstatus'} =~ /fail/i) { $self->{'resultstatus'} = 'Fail' }
36 0           else { die "You must specify a valid resultstatus (pass or fail)" }
37 0           $self->requiredField('exitstatus', %args);
38 0           $self->requiredField('duration', %args);
39            
40             # if no timestamp specified, use the current time
41 0 0         if ($args{'-timestamp'}) { $self->{'timestamp'} = $args{'-timestamp'} }
  0            
42             else {
43 0           my @t = localtime(time);
44             # YYYYMMDDHHMMSS format
45 0           $self->{'timestamp'} = ($t[5]+1900).leadZero($t[4]+1).leadZero($t[3]).
46             leadZero($t[2]).leadZero($t[1]).leadZero($t[0]);
47             }
48            
49 0           $self->{'comment'} = $args{'-comment'};
50 0           $self->{'bugnumber'} = $args{'-bugnumber'};
51 0           $self->{'logs'} = $args{'-log'};
52            
53 0 0         $self->{'automated'} = defined $args{'-isAutomatedResult'} ?
54             $args{'-isAutomatedResult'} : 1;
55            
56 0           return $self;
57             }
58              
59             sub requiredField {
60 0     0 0   my $self = shift;
61 0           my $fieldname = shift;
62 0           my %args = @_;
63            
64 0 0         die "You must specify a $fieldname" if not defined $args{'-'.$fieldname};
65            
66 0           $self->{$fieldname} = $args{'-'.$fieldname};
67             }
68              
69             # add a leading zero to date parts if only one character is present:
70             sub leadZero {
71 0     0 0   my $num = shift;
72 0 0         if (length($num) == 1) { return (0).$num; }
  0            
73 0           return $num;
74             }
75              
76             sub toXML {
77 0     0 0   my $self = shift;
78 0           my $x;
79            
80 0           $x = '
81 0           $x .= ' is_automated_result="'.$self->{'automated'}.'"'."\n";
82 0           $x .= ' resultstatus="'.$self->{'resultstatus'}.'"'."\n";
83 0           $x .= ' exitstatus="'.$self->{'exitstatus'}.'"'."\n";
84 0           $x .= ' duration="'.$self->{'duration'}.'"'."\n";
85 0           $x .= ' timestamp="'.$self->{'timestamp'}.'">'."\n";
86            
87 0 0         if ($self->{'comment'}) {
88 0           $x .= ' '.$self->{'comment'}.''."\n";
89             }
90            
91 0 0         if ($self->{'bugnumber'}) {
92 0           $x .= ' '.$self->{'bugnumber'}.''."\n";
93             }
94            
95 0 0         if ($self->{'logs'}) {
96 0           my @logs = @{$self->{'logs'}};
  0            
97 0           foreach my $curlog (@logs) {
98 0           $x .= $curlog->toXML();
99             }
100             }
101            
102 0           $x .= ''."\n";
103             }
104              
105             1;