File Coverage

blib/lib/Test/Harness/Results.pm
Criterion Covered Total %
statement 56 60 93.3
branch 2 4 50.0
condition 22 24 91.6
subroutine 25 27 92.5
pod 3 25 12.0
total 108 140 77.1


line stmt bran cond sub pod time code
1             # -*- Mode: cperl; cperl-indent-level: 4 -*-
2             package Test::Harness::Results;
3              
4 5     5   25 use strict;
  5         10  
  5         171  
5 5     5   23 use vars qw($VERSION);
  5         15  
  5         3372  
6             $VERSION = '0.01';
7              
8             =head1 NAME
9              
10             Test::Harness::Results - object for tracking results from a single test file
11              
12             =head1 SYNOPSIS
13              
14             One Test::Harness::Results object represents the results from one
15             test file getting analyzed.
16              
17             =head1 CONSTRUCTION
18              
19             =head2 new()
20              
21             my $results = new Test::Harness::Results;
22              
23             Create a test point object. Typically, however, you'll not create
24             one yourself, but access a Results object returned to you by
25             Test::Harness::Results.
26              
27             =cut
28              
29             sub new {
30 41     41 1 210 my $class = shift;
31 41         352 my $self = bless {}, $class;
32              
33 41         152 return $self;
34             }
35              
36             =head1 ACCESSORS
37              
38             The following data points are defined:
39              
40             passing true if the whole test is considered a pass
41             (or skipped), false if its a failure
42              
43             exit the exit code of the test run, if from a file
44             wait the wait code of the test run, if from a file
45              
46             max total tests which should have been run
47             seen total tests actually seen
48             skip_all if the whole test was skipped, this will
49             contain the reason.
50              
51             ok number of tests which passed
52             (including todo and skips)
53              
54             todo number of todo tests seen
55             bonus number of todo tests which
56             unexpectedly passed
57              
58             skip number of tests skipped
59              
60             So a successful test should have max == seen == ok.
61              
62              
63             There is one final item, the details.
64              
65             details an array ref reporting the result of
66             each test looks like this:
67              
68             $results{details}[$test_num - 1] =
69             { ok => is the test considered ok?
70             actual_ok => did it literally say 'ok'?
71             name => name of the test (if any)
72             diagnostics => test diagnostics (if any)
73             type => 'skip' or 'todo' (if any)
74             reason => reason for the above (if any)
75             };
76              
77             Element 0 of the details is test #1. I tried it with element 1 being
78             #1 and 0 being empty, this is less awkward.
79              
80              
81             Each of the following fields has a getter and setter method.
82              
83             =over 4
84              
85             =item * wait
86              
87             =item * exit
88              
89             =cut
90              
91 41     41 0 98 sub set_wait { my $self = shift; $self->{wait} = shift }
  41         603  
92             sub wait {
93 22     22 1 45 my $self = shift;
94 22   100     267 return $self->{wait} || 0;
95             }
96              
97 4     4 0 22 sub set_skip_all { my $self = shift; $self->{skip_all} = shift }
  4         37  
98             sub skip_all {
99 9     9 0 720 my $self = shift;
100 9         106 return $self->{skip_all};
101             }
102              
103 38 50   38 0 97 sub inc_max { my $self = shift; $self->{max} += (@_ ? shift : 1) }
  38         270  
104             sub max {
105 164     164 0 12204 my $self = shift;
106 164   100     1870 return $self->{max} || 0;
107             }
108              
109 44     44 0 89 sub set_passing { my $self = shift; $self->{passing} = shift }
  44         302  
110             sub passing {
111 22     22 0 11246 my $self = shift;
112 22   100     222 return $self->{passing} || 0;
113             }
114              
115 157 50   157 0 462 sub inc_ok { my $self = shift; $self->{ok} += (@_ ? shift : 1) }
  157         867  
116             sub ok {
117 52     52 0 10117 my $self = shift;
118 52   100     650 return $self->{ok} || 0;
119             }
120              
121 41     41 0 95 sub set_exit { my $self = shift; $self->{exit} = shift }
  41         252  
122             sub exit {
123 22     22 1 166 my $self = shift;
124 22   100     234 return $self->{exit} || 0;
125             }
126              
127 9     9 0 25 sub inc_bonus { my $self = shift; $self->{bonus}++ }
  9         56  
128             sub bonus {
129 22     22 0 51 my $self = shift;
130 22   100     216 return $self->{bonus} || 0;
131             }
132              
133 0     0 0 0 sub set_skip_reason { my $self = shift; $self->{skip_reason} = shift }
  0         0  
134             sub skip_reason {
135 0     0 0 0 my $self = shift;
136 0   0     0 return $self->{skip_reason} || 0;
137             }
138              
139 6     6 0 21 sub inc_skip { my $self = shift; $self->{skip}++ }
  6         27  
140             sub skip {
141 22     22 0 11126 my $self = shift;
142 22   100     322 return $self->{skip} || 0;
143             }
144              
145 18     18 0 33 sub inc_todo { my $self = shift; $self->{todo}++ }
  18         244  
146             sub todo {
147 22     22 0 10768 my $self = shift;
148 22   100     275 return $self->{todo} || 0;
149             }
150              
151 170     170 0 266 sub inc_seen { my $self = shift; $self->{seen}++ }
  170         586  
152             sub seen {
153 90     90 0 10421 my $self = shift;
154 90   100     1187 return $self->{seen} || 0;
155             }
156              
157             sub set_details {
158 168     168 0 289 my $self = shift;
159 168         252 my $index = shift;
160 168         190 my $details = shift;
161              
162 168   100     801 my $array = ($self->{details} ||= []);
163 168         1138 $array->[$index-1] = $details;
164             }
165              
166             sub details {
167 50     50 0 259 my $self = shift;
168 50   100     791 return $self->{details} || [];
169             }
170              
171             1;