Upgrade to Test::Harness 3.14
[p5sagit/p5-mst-13.2.git] / ext / Test / Harness / lib / App / Prove / State / Result / Test.pm
1 package App::Prove::State::Result::Test;
2
3 use strict;
4
5 use vars qw($VERSION);
6
7 =head1 NAME
8
9 App::Prove::State::Result::Test - Individual test results.
10
11 =head1 VERSION
12
13 Version 3.14
14
15 =cut
16
17 $VERSION = '3.14';
18
19 =head1 DESCRIPTION
20
21 The C<prove> command supports a C<--state> option that instructs it to
22 store persistent state across runs. This module encapsulates the results for a
23 single test.
24
25 =head1 SYNOPSIS
26
27     # Re-run failed tests
28     $ prove --state=fail,save -rbv
29
30 =cut
31
32 my %methods = (
33     name           => { method => 'name' },
34     elapsed        => { method => 'elapsed', default => 0 },
35     gen            => { method => 'generation', default => 1 },
36     last_pass_time => { method => 'last_pass_time', default => undef },
37     last_fail_time => { method => 'last_fail_time', default => undef },
38     last_result    => { method => 'result', default => 0 },
39     last_run_time  => { method => 'run_time', default => undef },
40     last_todo      => { method => 'num_todo', default => 0 },
41     mtime          => { method => 'mtime', default => undef },
42     seq            => { method => 'sequence', default => 1 },
43     total_passes   => { method => 'total_passes', default => 0 },
44     total_failures => { method => 'total_failures', default => 0 },
45 );
46
47 while ( my ( $key, $description ) = each %methods ) {
48     my $default = $description->{default};
49     no strict 'refs';
50     *{ $description->{method} } = sub {
51         my $self = shift;
52         if (@_) {
53             $self->{$key} = shift;
54             return $self;
55         }
56         return $self->{$key} || $default;
57     };
58 }
59
60 =head1 METHODS
61
62 =head2 Class Methods
63
64 =head3 C<new>
65
66 =cut
67
68 sub new {
69     my ( $class, $arg_for ) = @_;
70     $arg_for ||= {};
71     bless $arg_for => $class;
72 }
73
74 =head2 Instance Methods
75
76 =head3 C<name>
77
78 The name of the test.  Usually a filename.
79
80 =head3 C<elapsed>
81
82 The total elapsed times the test took to run, in seconds from the epoch..
83
84 =head3 C<generation>
85
86 The number for the "generation" of the test run.  The first generation is 1
87 (one) and subsequent generations are 2, 3, etc.
88
89 =head3 C<last_pass_time>
90
91 The last time the test program passed, in seconds from the epoch.
92
93 Returns C<undef> if the program has never passed.
94
95 =head3 C<last_fail_time>
96
97 The last time the test suite failed, in seconds from the epoch.
98
99 Returns C<undef> if the program has never failed.
100
101 =head3 C<mtime>
102
103 Returns the mtime of the test, in seconds from the epoch.
104
105 =head3 C<raw>
106
107 Returns a hashref of raw test data, suitable for serialization by YAML.
108
109 =head3 C<result>
110
111 Currently, whether or not the test suite passed with no 'problems' (such as
112 TODO passed).
113
114 =head3 C<run_time>
115
116 The total time it took for the test to run, in seconds.  If C<Time::HiRes> is
117 available, it will have finer granularity.
118
119 =head3 C<num_todo>
120
121 The number of tests with TODO directives.
122
123 =head3 C<sequence>
124
125 The order in which this test was run for the given test suite result. 
126
127 =head3 C<total_passes>
128
129 The number of times the test has passed.
130
131 =head3 C<total_failures>
132
133 The number of times the test has failed.
134
135 =cut
136
137 sub raw {
138     my $self = shift;
139     my %raw  = %$self;
140
141     # this is backwards-compatibility hack and is not gauranteed.
142     delete $raw{name};
143     return \%raw;
144 }
145
146 1;