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