Upgrade to Test::Harness 3.14
[p5sagit/p5-mst-13.2.git] / ext / Test / Harness / t / state_results.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if ( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = '../lib';
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12
13 use strict;
14 use Test::More tests => 25;
15 use App::Prove::State;
16
17 my $test_suite_data = test_suite_data();
18
19 #
20 # Test test suite results
21 #
22
23 can_ok 'App::Prove::State::Result', 'new';
24 isa_ok my $result = App::Prove::State::Result->new($test_suite_data),
25   'App::Prove::State::Result', '... and the object it returns';
26
27 ok $result, 'state_version';
28 ok defined $result->state_version, '... and it should be defined';
29
30 can_ok $result, 'generation';
31 is $result->generation, $test_suite_data->{generation},
32   '... and it should return the correct generation';
33
34 can_ok $result, 'num_tests';
35 is $result->num_tests, scalar keys %{ $test_suite_data->{tests} },
36   '... and it should return the number of tests run';
37
38 can_ok $result, 'raw';
39 is_deeply $result->raw, $test_suite_data,
40   '... and it should return the raw, unblessed data';
41
42 #
43 # Check individual tests.
44 #
45
46 can_ok $result, 'tests';
47
48 can_ok $result, 'test';
49 eval { $result->test };
50 my $error = $@;
51 like $error, qr/^\Qtest() requires a test name/,
52   '... and it should croak() if a test name is not supplied';
53
54 my $name = 't/compat/failure.t';
55 ok my $test = $result->test('t/compat/failure.t'),
56   'result() should succeed if the test name is found';
57 isa_ok $test, 'App::Prove::State::Result::Test',
58   '... and the object it returns';
59
60 can_ok $test, 'name';
61 is $test->name, $name, '... and it should return the test name';
62
63 can_ok $test, 'last_pass_time';
64 like $test->last_pass_time, qr/^\d+\.\d+$/,
65   '... and it should return a numeric value';
66
67 can_ok $test, 'last_fail_time';
68 ok !defined $test->last_fail_time,
69   '... and it should return undef if the test has never failed';
70
71 can_ok $result, 'remove';
72 ok $result->remove($name), '... and calling it should succeed';
73
74 ok $test = $result->test($name),
75   '... and fetching the removed test should suceed';
76 ok !defined $test->last_pass_time, '... and it should have clean values';
77
78 sub test_suite_data {
79     return {
80         'version'    => App::Prove::State::Result->state_version,
81         'generation' => '51',
82         'tests'      => {
83             't/compat/failure.t' => {
84                 'last_result'    => '0',
85                 'last_run_time'  => '1196371471.57738',
86                 'last_pass_time' => '1196371471.57738',
87                 'total_passes'   => '48',
88                 'seq'            => '1549',
89                 'gen'            => '51',
90                 'elapsed'        => 0.1230,
91                 'last_todo'      => '1',
92                 'mtime'          => 1196285623,
93             },
94             't/yamlish-writer.t' => {
95                 'last_result'    => '0',
96                 'last_run_time'  => '1196371480.5761',
97                 'last_pass_time' => '1196371480.5761',
98                 'last_fail_time' => '1196368609',
99                 'total_passes'   => '41',
100                 'seq'            => '1578',
101                 'gen'            => '49',
102                 'elapsed'        => 12.2983,
103                 'last_todo'      => '0',
104                 'mtime'          => 1196285400,
105             },
106             't/compat/env.t' => {
107                 'last_result'    => '0',
108                 'last_run_time'  => '1196371471.42967',
109                 'last_pass_time' => '1196371471.42967',
110                 'last_fail_time' => '1196368608',
111                 'total_passes'   => '48',
112                 'seq'            => '1548',
113                 'gen'            => '52',
114                 'elapsed'        => 3.1290,
115                 'last_todo'      => '0',
116                 'mtime'          => 1196285739,
117             },
118             't/compat/version.t' => {
119                 'last_result'    => '2',
120                 'last_run_time'  => '1196371472.96476',
121                 'last_pass_time' => '1196371472.96476',
122                 'last_fail_time' => '1196368609',
123                 'total_passes'   => '47',
124                 'seq'            => '1555',
125                 'gen'            => '51',
126                 'elapsed'        => 0.2363,
127                 'last_todo'      => '4',
128                 'mtime'          => 1196285239,
129             },
130             't/compat/inc_taint.t' => {
131                 'last_result'    => '3',
132                 'last_run_time'  => '1196371471.89682',
133                 'last_pass_time' => '1196371471.89682',
134                 'total_passes'   => '47',
135                 'seq'            => '1551',
136                 'gen'            => '51',
137                 'elapsed'        => 1.6938,
138                 'last_todo'      => '0',
139                 'mtime'          => 1196185639,
140             },
141             't/source.t' => {
142                 'last_result'    => '0',
143                 'last_run_time'  => '1196371479.72508',
144                 'last_pass_time' => '1196371479.72508',
145                 'total_passes'   => '41',
146                 'seq'            => '1570',
147                 'gen'            => '51',
148                 'elapsed'        => 0.0143,
149                 'last_todo'      => '0',
150                 'mtime'          => 1186285639,
151             },
152         }
153     };
154 }