Move Test::Harness from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / Test-Harness / t / state.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     unshift @INC, 't/lib';
5 }
6
7 use strict;
8 use Test::More;
9 use App::Prove::State;
10 use App::Prove::State::Result;
11
12 my @schedule = (
13     {   options        => 'all',
14         get_tests_args => [],
15         expect         => [
16             't/compat/env.t',
17             't/compat/failure.t',
18             't/compat/inc_taint.t',
19             't/compat/version.t',
20             't/source.t',
21             't/yamlish-writer.t',
22         ],
23     },
24     {   options        => 'failed',
25         get_tests_args => [],
26         expect         => [
27             't/compat/inc_taint.t',
28             't/compat/version.t',
29         ],
30     },
31     {   options        => 'passed',
32         get_tests_args => [],
33         expect         => [
34             't/compat/env.t',
35             't/compat/failure.t',
36             't/source.t',
37             't/yamlish-writer.t',
38         ],
39     },
40     {   options        => 'last',
41         get_tests_args => [],
42         expect         => [
43             't/compat/env.t',
44             't/compat/failure.t',
45             't/compat/inc_taint.t',
46             't/compat/version.t',
47             't/source.t',
48         ],
49     },
50     {   options        => 'todo',
51         get_tests_args => [],
52         expect         => [
53             't/compat/version.t',
54             't/compat/failure.t',
55         ],
56
57     },
58     {   options        => 'hot',
59         get_tests_args => [],
60         expect         => [
61             't/compat/version.t',
62             't/yamlish-writer.t',
63             't/compat/env.t',
64         ],
65     },
66     {   options        => 'adrian',
67         get_tests_args => [],
68         expect         => [
69             't/compat/version.t',
70             't/yamlish-writer.t',
71             't/compat/env.t',
72             't/compat/failure.t',
73             't/compat/inc_taint.t',
74             't/source.t',
75         ],
76     },
77     {   options        => 'failed,passed',
78         get_tests_args => [],
79         expect         => [
80             't/compat/inc_taint.t',
81             't/compat/version.t',
82             't/compat/env.t',
83             't/compat/failure.t',
84             't/source.t',
85             't/yamlish-writer.t',
86         ],
87     },
88     {   options        => [ 'failed', 'passed' ],
89         get_tests_args => [],
90         expect         => [
91             't/compat/inc_taint.t',
92             't/compat/version.t',
93             't/compat/env.t',
94             't/compat/failure.t',
95             't/source.t',
96             't/yamlish-writer.t',
97         ],
98     },
99     {   options        => 'slow',
100         get_tests_args => [],
101         expect         => [
102             't/yamlish-writer.t',
103             't/compat/env.t',
104             't/compat/inc_taint.t',
105             't/compat/version.t',
106             't/compat/failure.t',
107             't/source.t',
108         ],
109     },
110     {   options        => 'fast',
111         get_tests_args => [],
112         expect         => [
113             't/source.t',
114             't/compat/failure.t',
115             't/compat/version.t',
116             't/compat/inc_taint.t',
117             't/compat/env.t',
118             't/yamlish-writer.t',
119         ],
120     },
121     {   options        => 'old',
122         get_tests_args => [],
123         expect         => [
124             't/source.t',
125             't/compat/inc_taint.t',
126             't/compat/version.t',
127             't/yamlish-writer.t',
128             't/compat/failure.t',
129             't/compat/env.t',
130         ],
131     },
132     {   options        => 'new',
133         get_tests_args => [],
134         expect         => [
135             't/compat/env.t',
136             't/compat/failure.t',
137             't/yamlish-writer.t',
138             't/compat/version.t',
139             't/compat/inc_taint.t',
140             't/source.t',
141         ],
142     },
143     {   options        => 'fresh',
144         get_tests_args => [],
145         expect         => [
146             't/compat/env.t',
147             't/compat/failure.t',
148         ],
149     },
150 );
151
152 plan tests => @schedule * 2;
153
154 for my $test (@schedule) {
155     my $state = App::Prove::State->new;
156     isa_ok $state, 'App::Prove::State';
157
158     my $desc = $test->{options};
159
160     # Naughty
161     $state->{_} = get_state();
162     my $options = $test->{options};
163     $options = [$options] unless 'ARRAY' eq ref $options;
164     $state->apply_switch(@$options);
165
166     my @got    = $state->get_tests( @{ $test->{get_tests_args} } );
167     my @expect = @{ $test->{expect} };
168     unless ( is_deeply \@got, \@expect, "$desc: order OK" ) {
169         use Data::Dumper;
170         diag( Dumper( { got => \@got, want => \@expect } ) );
171     }
172 }
173
174 sub get_state {
175     return App::Prove::State::Result->new(
176         {   generation    => 51,
177             last_run_time => 1196285439,
178             tests         => {
179                 't/compat/failure.t' => {
180                     last_result    => 0,
181                     last_run_time  => 1196371471.57738,
182                     last_pass_time => 1196371471.57738,
183                     total_passes   => 48,
184                     seq            => 1549,
185                     gen            => 51,
186                     elapsed        => 0.1230,
187                     last_todo      => 1,
188                     mtime          => 1196285623,
189                 },
190                 't/yamlish-writer.t' => {
191                     last_result    => 0,
192                     last_run_time  => 1196371480.5761,
193                     last_pass_time => 1196371480.5761,
194                     last_fail_time => 1196368609,
195                     total_passes   => 41,
196                     seq            => 1578,
197                     gen            => 49,
198                     elapsed        => 12.2983,
199                     last_todo      => 0,
200                     mtime          => 1196285400,
201                 },
202                 't/compat/env.t' => {
203                     last_result    => 0,
204                     last_run_time  => 1196371471.42967,
205                     last_pass_time => 1196371471.42967,
206                     last_fail_time => 1196368608,
207                     total_passes   => 48,
208                     seq            => 1548,
209                     gen            => 52,
210                     elapsed        => 3.1290,
211                     last_todo      => 0,
212                     mtime          => 1196285739,
213                 },
214                 't/compat/version.t' => {
215                     last_result    => 2,
216                     last_run_time  => 1196371472.96476,
217                     last_pass_time => 1196371472.96476,
218                     last_fail_time => 1196368609,
219                     total_passes   => 47,
220                     seq            => 1555,
221                     gen            => 51,
222                     elapsed        => 0.2363,
223                     last_todo      => 4,
224                     mtime          => 1196285239,
225                 },
226                 't/compat/inc_taint.t' => {
227                     last_result    => 3,
228                     last_run_time  => 1196371471.89682,
229                     last_pass_time => 1196371471.89682,
230                     total_passes   => 47,
231                     seq            => 1551,
232                     gen            => 51,
233                     elapsed        => 1.6938,
234                     last_todo      => 0,
235                     mtime          => 1196185639,
236                 },
237                 't/source.t' => {
238                     last_result    => 0,
239                     last_run_time  => 1196371479.72508,
240                     last_pass_time => 1196371479.72508,
241                     total_passes   => 41,
242                     seq            => 1570,
243                     gen            => 51,
244                     elapsed        => 0.0143,
245                     last_todo      => 0,
246                     mtime          => 1186285639,
247                 },
248             }
249         }
250     );
251 }