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