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