Commit | Line | Data |
356733da |
1 | #!/usr/bin/perl -w |
2fe373ce |
2 | |
3 | BEGIN { |
13287dd5 |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't'; |
356733da |
6 | @INC = ('../lib', 'lib'); |
7 | } |
8 | else { |
9 | unshift @INC, 't/lib'; |
13287dd5 |
10 | } |
2fe373ce |
11 | } |
12 | |
13287dd5 |
13 | my $SAMPLE_TESTS = $ENV{PERL_CORE} ? "lib/sample-tests" : "t/sample-tests"; |
14 | |
2fe373ce |
15 | use strict; |
16 | |
17 | # For shutting up Test::Harness. |
13287dd5 |
18 | # Has to work on 5.004 which doesn't have Tie::StdHandle. |
2fe373ce |
19 | package My::Dev::Null; |
20 | |
21 | sub WRITE {} |
22 | sub PRINT {} |
23 | sub PRINTF {} |
24 | sub TIEHANDLE { |
25 | my $class = shift; |
26 | my $fh = do { local *HANDLE; \*HANDLE }; |
27 | return bless $fh, $class; |
28 | } |
29 | sub READ {} |
30 | sub READLINE {} |
31 | sub GETC {} |
32 | |
33 | |
34 | package main; |
35 | |
356733da |
36 | use Test::More; |
2fe373ce |
37 | |
38 | use vars qw($Total_tests %samples); |
39 | |
356733da |
40 | plan tests => $Total_tests; |
2fe373ce |
41 | use Test::Harness; |
356733da |
42 | use_ok('Test::Harness'); |
43 | |
2fe373ce |
44 | |
45 | BEGIN { |
46 | %samples = ( |
47 | simple => { |
48 | total => { |
49 | bonus => 0, |
50 | max => 5, |
51 | 'ok' => 5, |
52 | files => 1, |
53 | bad => 0, |
54 | good => 1, |
55 | tests => 1, |
56 | sub_skipped=> 0, |
356733da |
57 | 'todo' => 0, |
2fe373ce |
58 | skipped => 0, |
59 | }, |
60 | failed => { }, |
61 | all_ok => 1, |
62 | }, |
63 | simple_fail => { |
64 | total => { |
65 | bonus => 0, |
66 | max => 5, |
67 | 'ok' => 3, |
68 | files => 1, |
69 | bad => 1, |
70 | good => 0, |
71 | tests => 1, |
72 | sub_skipped => 0, |
356733da |
73 | 'todo' => 0, |
2fe373ce |
74 | skipped => 0, |
75 | }, |
76 | failed => { |
77 | canon => '2 5', |
78 | }, |
79 | all_ok => 0, |
80 | }, |
81 | descriptive => { |
82 | total => { |
83 | bonus => 0, |
84 | max => 5, |
85 | 'ok' => 5, |
86 | files => 1, |
87 | bad => 0, |
88 | good => 1, |
89 | tests => 1, |
90 | sub_skipped=> 0, |
356733da |
91 | 'todo' => 0, |
2fe373ce |
92 | skipped => 0, |
93 | }, |
94 | failed => { }, |
95 | all_ok => 1, |
96 | }, |
97 | no_nums => { |
98 | total => { |
99 | bonus => 0, |
100 | max => 5, |
101 | 'ok' => 4, |
102 | files => 1, |
103 | bad => 1, |
104 | good => 0, |
105 | tests => 1, |
106 | sub_skipped=> 0, |
356733da |
107 | 'todo' => 0, |
2fe373ce |
108 | skipped => 0, |
109 | }, |
110 | failed => { |
111 | canon => '3', |
112 | }, |
113 | all_ok => 0, |
114 | }, |
356733da |
115 | 'todo' => { |
2fe373ce |
116 | total => { |
117 | bonus => 1, |
118 | max => 5, |
119 | 'ok' => 5, |
120 | files => 1, |
121 | bad => 0, |
122 | good => 1, |
123 | tests => 1, |
124 | sub_skipped=> 0, |
356733da |
125 | 'todo' => 2, |
2fe373ce |
126 | skipped => 0, |
127 | }, |
128 | failed => { }, |
129 | all_ok => 1, |
130 | }, |
131 | todo_inline => { |
132 | total => { |
133 | bonus => 1, |
134 | max => 3, |
135 | 'ok' => 3, |
136 | files => 1, |
137 | bad => 0, |
138 | good => 1, |
139 | tests => 1, |
140 | sub_skipped => 0, |
356733da |
141 | 'todo' => 2, |
2fe373ce |
142 | skipped => 0, |
143 | }, |
144 | failed => { }, |
145 | all_ok => 1, |
146 | }, |
356733da |
147 | 'skip' => { |
2fe373ce |
148 | total => { |
149 | bonus => 0, |
150 | max => 5, |
151 | 'ok' => 5, |
152 | files => 1, |
153 | bad => 0, |
154 | good => 1, |
155 | tests => 1, |
156 | sub_skipped=> 1, |
356733da |
157 | 'todo' => 0, |
2fe373ce |
158 | skipped => 0, |
159 | }, |
160 | failed => { }, |
161 | all_ok => 1, |
162 | }, |
163 | bailout => 0, |
164 | combined => { |
165 | total => { |
166 | bonus => 1, |
167 | max => 10, |
168 | 'ok' => 8, |
169 | files => 1, |
170 | bad => 1, |
171 | good => 0, |
172 | tests => 1, |
173 | sub_skipped=> 1, |
356733da |
174 | 'todo' => 2, |
2fe373ce |
175 | skipped => 0 |
176 | }, |
177 | failed => { |
178 | canon => '3 9', |
179 | }, |
180 | all_ok => 0, |
181 | }, |
182 | duplicates => { |
183 | total => { |
184 | bonus => 0, |
185 | max => 10, |
186 | 'ok' => 11, |
187 | files => 1, |
188 | bad => 1, |
189 | good => 0, |
190 | tests => 1, |
191 | sub_skipped=> 0, |
356733da |
192 | 'todo' => 0, |
2fe373ce |
193 | skipped => 0, |
194 | }, |
195 | failed => { |
196 | canon => '??', |
197 | }, |
198 | all_ok => 0, |
199 | }, |
879ba010 |
200 | head_end => { |
2fe373ce |
201 | total => { |
202 | bonus => 0, |
203 | max => 4, |
204 | 'ok' => 4, |
205 | files => 1, |
206 | bad => 0, |
207 | good => 1, |
208 | tests => 1, |
209 | sub_skipped=> 0, |
356733da |
210 | 'todo' => 0, |
2fe373ce |
211 | skipped => 0, |
212 | }, |
213 | failed => { }, |
214 | all_ok => 1, |
215 | }, |
879ba010 |
216 | head_fail => { |
2fe373ce |
217 | total => { |
218 | bonus => 0, |
219 | max => 4, |
220 | 'ok' => 3, |
221 | files => 1, |
222 | bad => 1, |
223 | good => 0, |
224 | tests => 1, |
225 | sub_skipped=> 0, |
356733da |
226 | 'todo' => 0, |
2fe373ce |
227 | skipped => 0, |
228 | }, |
229 | failed => { |
230 | canon => '2', |
231 | }, |
232 | all_ok => 0, |
233 | }, |
234 | skip_all => { |
235 | total => { |
236 | bonus => 0, |
237 | max => 0, |
238 | 'ok' => 0, |
239 | files => 1, |
240 | bad => 0, |
241 | good => 1, |
242 | tests => 1, |
243 | sub_skipped=> 0, |
356733da |
244 | 'todo' => 0, |
2fe373ce |
245 | skipped => 1, |
246 | }, |
247 | failed => { }, |
248 | all_ok => 1, |
249 | }, |
250 | with_comments => { |
251 | total => { |
252 | bonus => 2, |
253 | max => 5, |
254 | 'ok' => 5, |
255 | files => 1, |
256 | bad => 0, |
257 | good => 1, |
258 | tests => 1, |
259 | sub_skipped=> 0, |
356733da |
260 | 'todo' => 4, |
2fe373ce |
261 | skipped => 0, |
262 | }, |
263 | failed => { }, |
264 | all_ok => 1, |
265 | }, |
13287dd5 |
266 | taint => { |
267 | total => { |
268 | bonus => 0, |
269 | max => 1, |
270 | 'ok' => 1, |
271 | files => 1, |
272 | bad => 0, |
273 | good => 1, |
274 | tests => 1, |
275 | sub_skipped=> 0, |
356733da |
276 | 'todo' => 0, |
13287dd5 |
277 | skipped => 0, |
278 | }, |
279 | failed => { }, |
280 | all_ok => 1, |
281 | }, |
356733da |
282 | |
283 | 'die' => { |
284 | total => { |
285 | bonus => 0, |
286 | max => 0, |
287 | 'ok' => 0, |
288 | files => 1, |
289 | bad => 1, |
290 | good => 0, |
291 | tests => 1, |
292 | sub_skipped=> 0, |
293 | 'todo' => 0, |
294 | skipped => 0, |
295 | }, |
296 | failed => { |
297 | estat => 1, |
298 | wstat => 256, |
299 | max => '??', |
300 | failed => '??', |
301 | canon => '??', |
302 | }, |
303 | all_ok => 0, |
304 | }, |
305 | |
306 | die_head_end => { |
307 | total => { |
308 | bonus => 0, |
309 | max => 0, |
310 | 'ok' => 4, |
311 | files => 1, |
312 | bad => 1, |
313 | good => 0, |
314 | tests => 1, |
315 | sub_skipped=> 0, |
316 | 'todo' => 0, |
317 | skipped => 0, |
318 | }, |
319 | failed => { |
320 | estat => 1, |
321 | wstat => 256, |
322 | max => '??', |
323 | failed => '??', |
324 | canon => '??', |
325 | }, |
326 | all_ok => 0, |
327 | }, |
328 | |
329 | die_last_minute => { |
330 | total => { |
331 | bonus => 0, |
332 | max => 4, |
333 | 'ok' => 4, |
334 | files => 1, |
335 | bad => 1, |
336 | good => 0, |
337 | tests => 1, |
338 | sub_skipped=> 0, |
339 | 'todo' => 0, |
340 | skipped => 0, |
341 | }, |
342 | failed => { |
343 | estat => 1, |
344 | wstat => 256, |
345 | max => 4, |
346 | failed => 0, |
347 | canon => '??', |
348 | }, |
349 | all_ok => 0, |
350 | }, |
351 | bignum => { |
352 | total => { |
353 | bonus => 0, |
354 | max => 2, |
355 | 'ok' => 4, |
356 | files => 1, |
357 | bad => 1, |
358 | good => 0, |
359 | tests => 1, |
360 | sub_skipped=> 0, |
361 | 'todo' => 0, |
362 | skipped => 0, |
363 | }, |
364 | failed => { |
365 | canon => '??', |
366 | }, |
367 | all_ok => 0, |
368 | }, |
2fe373ce |
369 | ); |
370 | |
356733da |
371 | $Total_tests = (keys(%samples) * 4) + 1; |
2fe373ce |
372 | } |
373 | |
374 | tie *NULL, 'My::Dev::Null' or die $!; |
375 | |
376 | while (my($test, $expect) = each %samples) { |
377 | # _run_all_tests() runs the tests but skips the formatting. |
378 | my($totals, $failed); |
379 | eval { |
380 | select NULL; # _run_all_tests() isn't as quiet as it should be. |
381 | ($totals, $failed) = |
13287dd5 |
382 | Test::Harness::_run_all_tests("$SAMPLE_TESTS/$test"); |
2fe373ce |
383 | }; |
384 | select STDOUT; |
385 | |
386 | unless( $@ ) { |
356733da |
387 | is( Test::Harness::_all_ok($totals), $expect->{all_ok}, |
2fe373ce |
388 | "$test - all ok" ); |
389 | ok( defined $expect->{total}, "$test - has total" ); |
356733da |
390 | is_deeply( {map { $_=>$totals->{$_} } keys %{$expect->{total}}}, |
391 | $expect->{total}, |
2fe373ce |
392 | "$test - totals" ); |
356733da |
393 | is_deeply( {map { $_=>$failed->{"$SAMPLE_TESTS/$test"}{$_} } |
394 | keys %{$expect->{failed}}}, |
395 | $expect->{failed}, |
2fe373ce |
396 | "$test - failed" ); |
397 | } |
398 | else { # special case for bailout |
356733da |
399 | is( $test, 'bailout' ); |
400 | like( $@, '/Further testing stopped: GERONI/i', $test ); |
401 | pass( 'skipping for bailout' ); |
402 | pass( 'skipping for bailout' ); |
2fe373ce |
403 | } |
404 | } |