Commit | Line | Data |
b965d173 |
1 | #!/usr/bin/perl -w |
2 | |
3 | BEGIN { |
5e2a19fc |
4 | if ( $ENV{PERL_CORE} ) { |
5 | chdir 't'; |
6 | @INC = ( '../lib', 'lib' ); |
7 | } |
8 | else { |
9 | unshift @INC, 't/lib'; |
b965d173 |
10 | } |
11 | } |
12 | |
13 | use strict; |
b965d173 |
14 | |
15 | use Test::More; |
16 | use File::Spec; |
17 | |
18 | use App::Prove; |
19 | |
20 | package FakeProve; |
21 | use vars qw( @ISA ); |
22 | |
23 | @ISA = qw( App::Prove ); |
24 | |
25 | sub new { |
26 | my $class = shift; |
27 | my $self = $class->SUPER::new(@_); |
28 | $self->{_log} = []; |
29 | return $self; |
30 | } |
31 | |
32 | sub _color_default {0} |
33 | |
34 | sub _runtests { |
35 | my $self = shift; |
36 | push @{ $self->{_log} }, [ '_runtests', @_ ]; |
37 | } |
38 | |
39 | sub get_log { |
40 | my $self = shift; |
41 | my @log = @{ $self->{_log} }; |
42 | $self->{_log} = []; |
43 | return @log; |
44 | } |
45 | |
46 | sub _shuffle { |
47 | my $self = shift; |
48 | s/^/xxx/ for @_; |
49 | } |
50 | |
51 | package main; |
52 | |
53 | sub mabs { |
54 | my $ar = shift; |
55 | return [ map { File::Spec->rel2abs($_) } @$ar ]; |
56 | } |
57 | |
58 | { |
59 | my @import_log = (); |
60 | |
61 | sub test_log_import { push @import_log, [@_] } |
62 | |
63 | sub get_import_log { |
64 | my @log = @import_log; |
65 | @import_log = (); |
66 | return @log; |
67 | } |
68 | } |
69 | |
70 | my ( @ATTR, %DEFAULT_ASSERTION, @SCHEDULE ); |
71 | |
72 | # see the "ACTUAL TEST" section at the bottom |
73 | |
74 | BEGIN { # START PLAN |
75 | |
76 | # list of attributes |
77 | @ATTR = qw( |
78 | archive argv blib color directives exec failures formatter harness |
79 | includes lib merge parse quiet really_quiet recurse backwards |
80 | shuffle taint_fail taint_warn verbose warnings_fail warnings_warn |
81 | ); |
82 | |
83 | # what we expect if the 'expect' hash does not define it |
84 | %DEFAULT_ASSERTION = map { $_ => undef } @ATTR; |
85 | |
86 | $DEFAULT_ASSERTION{includes} = $DEFAULT_ASSERTION{argv} |
87 | = sub { 'ARRAY' eq ref shift }; |
88 | |
89 | my @dummy_tests = map { File::Spec->catdir( 't', 'sample-tests', $_ ) } |
90 | qw(simple simple_yaml); |
91 | my $dummy_test = $dummy_tests[0]; |
92 | |
93 | ######################################################################## |
94 | # declarations - this drives all of the subtests. |
95 | # The cheatsheet follows. |
96 | # required: name, expect |
97 | # optional: |
98 | # args - arguments to constructor |
99 | # switches - command-line switches |
100 | # runlog - expected results of internal calls to _runtests, must |
101 | # match FakeProve's _log attr |
102 | # run_error - depends on 'runlog' (if missing, asserts no error) |
103 | # extra - follow-up check to handle exceptional cleanup / verification |
104 | # class - The App::Prove subclass to test. Defaults to FakeProve |
105 | @SCHEDULE = ( |
106 | { name => 'Create empty', |
107 | expect => {} |
108 | }, |
109 | { name => 'Set all options via constructor', |
110 | args => { |
111 | archive => 1, |
112 | argv => [qw(one two three)], |
113 | blib => 2, |
114 | color => 3, |
115 | directives => 4, |
116 | exec => 5, |
117 | failures => 7, |
118 | formatter => 8, |
119 | harness => 9, |
120 | includes => [qw(four five six)], |
121 | lib => 10, |
122 | merge => 11, |
123 | parse => 13, |
124 | quiet => 14, |
125 | really_quiet => 15, |
126 | recurse => 16, |
127 | backwards => 17, |
128 | shuffle => 18, |
129 | taint_fail => 19, |
130 | taint_warn => 20, |
131 | verbose => 21, |
132 | warnings_fail => 22, |
133 | warnings_warn => 23, |
134 | }, |
135 | expect => { |
136 | archive => 1, |
137 | argv => [qw(one two three)], |
138 | blib => 2, |
139 | color => 3, |
140 | directives => 4, |
141 | exec => 5, |
142 | failures => 7, |
143 | formatter => 8, |
144 | harness => 9, |
145 | includes => [qw(four five six)], |
146 | lib => 10, |
147 | merge => 11, |
148 | parse => 13, |
149 | quiet => 14, |
150 | really_quiet => 15, |
151 | recurse => 16, |
152 | backwards => 17, |
153 | shuffle => 18, |
154 | taint_fail => 19, |
155 | taint_warn => 20, |
156 | verbose => 21, |
157 | warnings_fail => 22, |
158 | warnings_warn => 23, |
159 | } |
160 | }, |
161 | { name => 'Call with defaults', |
162 | args => { argv => [qw( one two three )] }, |
163 | expect => {}, |
164 | runlog => [ |
165 | [ '_runtests', |
166 | { verbosity => 0 }, |
167 | 'TAP::Harness', |
168 | 'one', |
169 | 'two', |
170 | 'three' |
171 | ] |
172 | ], |
173 | }, |
174 | |
175 | # Test all options individually |
176 | |
177 | # { name => 'Just archive', |
178 | # args => { |
179 | # argv => [qw( one two three )], |
180 | # archive => 1, |
181 | # }, |
182 | # expect => { |
183 | # archive => 1, |
184 | # }, |
185 | # runlog => [ |
186 | # [ { archive => 1, |
187 | # }, |
188 | # 'TAP::Harness', |
189 | # 'one', 'two', |
190 | # 'three' |
191 | # ] |
192 | # ], |
193 | # }, |
194 | { name => 'Just argv', |
195 | args => { |
196 | argv => [qw( one two three )], |
197 | }, |
198 | expect => { |
199 | argv => [qw( one two three )], |
200 | }, |
201 | runlog => [ |
202 | [ '_runtests', |
203 | { verbosity => 0 }, |
204 | 'TAP::Harness', |
205 | 'one', 'two', |
206 | 'three' |
207 | ] |
208 | ], |
209 | }, |
210 | { name => 'Just blib', |
211 | args => { |
212 | argv => [qw( one two three )], |
213 | blib => 1, |
214 | }, |
215 | expect => { |
216 | blib => 1, |
217 | }, |
218 | runlog => [ |
219 | [ '_runtests', |
220 | { lib => mabs( [ 'blib/lib', 'blib/arch' ] ), |
221 | verbosity => 0 |
222 | }, |
223 | 'TAP::Harness', |
224 | 'one', 'two', 'three' |
225 | ] |
226 | ], |
227 | }, |
228 | |
229 | { name => 'Just color', |
230 | args => { |
231 | argv => [qw( one two three )], |
232 | color => 1, |
233 | }, |
234 | expect => { |
235 | color => 1, |
236 | }, |
237 | runlog => [ |
238 | [ '_runtests', |
239 | { color => 1, |
240 | verbosity => 0 |
241 | }, |
242 | 'TAP::Harness', |
243 | 'one', 'two', 'three' |
244 | ] |
245 | ], |
246 | }, |
247 | |
248 | { name => 'Just directives', |
249 | args => { |
250 | argv => [qw( one two three )], |
251 | directives => 1, |
252 | }, |
253 | expect => { |
254 | directives => 1, |
255 | }, |
256 | runlog => [ |
257 | [ '_runtests', |
258 | { directives => 1, |
259 | verbosity => 0 |
260 | }, |
261 | 'TAP::Harness', |
262 | 'one', 'two', 'three' |
263 | ] |
264 | ], |
265 | }, |
266 | { name => 'Just exec', |
267 | args => { |
268 | argv => [qw( one two three )], |
269 | exec => 1, |
270 | }, |
271 | expect => { |
272 | exec => 1, |
273 | }, |
274 | runlog => [ |
275 | [ '_runtests', |
276 | { exec => [1], |
277 | verbosity => 0 |
278 | }, |
279 | 'TAP::Harness', |
280 | 'one', 'two', 'three' |
281 | ] |
282 | ], |
283 | }, |
284 | { name => 'Just failures', |
285 | args => { |
286 | argv => [qw( one two three )], |
287 | failures => 1, |
288 | }, |
289 | expect => { |
290 | failures => 1, |
291 | }, |
292 | runlog => [ |
293 | [ '_runtests', |
294 | { failures => 1, |
295 | verbosity => 0 |
296 | }, |
297 | 'TAP::Harness', |
298 | 'one', 'two', 'three' |
299 | ] |
300 | ], |
301 | }, |
302 | |
303 | { name => 'Just formatter', |
304 | args => { |
305 | argv => [qw( one two three )], |
306 | formatter => 'TAP::Harness', |
307 | }, |
308 | expect => { |
309 | formatter => 'TAP::Harness', |
310 | }, |
311 | runlog => [ |
312 | [ '_runtests', |
313 | { formatter_class => 'TAP::Harness', |
314 | verbosity => 0 |
315 | }, |
316 | 'TAP::Harness', |
317 | 'one', 'two', 'three' |
318 | ] |
319 | ], |
320 | }, |
321 | |
322 | { name => 'Just includes', |
323 | args => { |
324 | argv => [qw( one two three )], |
325 | includes => [qw( four five six )], |
326 | }, |
327 | expect => { |
328 | includes => [qw( four five six )], |
329 | }, |
330 | runlog => [ |
331 | [ '_runtests', |
332 | { lib => mabs( [qw( four five six )] ), |
333 | verbosity => 0 |
334 | }, |
335 | 'TAP::Harness', |
336 | 'one', 'two', 'three' |
337 | ] |
338 | ], |
339 | }, |
340 | { name => 'Just lib', |
341 | args => { |
342 | argv => [qw( one two three )], |
343 | lib => 1, |
344 | }, |
345 | expect => { |
346 | lib => 1, |
347 | }, |
348 | runlog => [ |
349 | [ '_runtests', |
350 | { lib => mabs( ['lib'] ), |
351 | verbosity => 0 |
352 | }, |
353 | 'TAP::Harness', |
354 | 'one', 'two', 'three' |
355 | ] |
356 | ], |
357 | }, |
358 | { name => 'Just merge', |
359 | args => { |
360 | argv => [qw( one two three )], |
361 | merge => 1, |
362 | }, |
363 | expect => { |
364 | merge => 1, |
365 | }, |
366 | runlog => [ |
367 | [ '_runtests', |
368 | { merge => 1, |
369 | verbosity => 0 |
370 | }, |
371 | 'TAP::Harness', |
372 | 'one', 'two', 'three' |
373 | ] |
374 | ], |
375 | }, |
376 | { name => 'Just parse', |
377 | args => { |
378 | argv => [qw( one two three )], |
379 | parse => 1, |
380 | }, |
381 | expect => { |
382 | parse => 1, |
383 | }, |
384 | runlog => [ |
385 | [ '_runtests', |
386 | { errors => 1, |
387 | verbosity => 0 |
388 | }, |
389 | 'TAP::Harness', |
390 | 'one', 'two', 'three' |
391 | ] |
392 | ], |
393 | }, |
394 | { name => 'Just quiet', |
395 | args => { |
396 | argv => [qw( one two three )], |
397 | quiet => 1, |
398 | }, |
399 | expect => { |
400 | quiet => 1, |
401 | }, |
402 | runlog => [ |
403 | [ '_runtests', |
404 | { verbosity => -1 |
405 | }, |
406 | 'TAP::Harness', |
407 | 'one', 'two', 'three' |
408 | ] |
409 | ], |
410 | }, |
411 | { name => 'Just really_quiet', |
412 | args => { |
413 | argv => [qw( one two three )], |
414 | really_quiet => 1, |
415 | }, |
416 | expect => { |
417 | really_quiet => 1, |
418 | }, |
419 | runlog => [ |
420 | [ '_runtests', |
421 | { verbosity => -2 |
422 | }, |
423 | 'TAP::Harness', |
424 | 'one', 'two', 'three' |
425 | ] |
426 | ], |
427 | }, |
428 | { name => 'Just recurse', |
429 | args => { |
430 | argv => [qw( one two three )], |
431 | recurse => 1, |
432 | }, |
433 | expect => { |
434 | recurse => 1, |
435 | }, |
436 | runlog => [ |
437 | [ '_runtests', |
438 | { verbosity => 0 }, |
439 | 'TAP::Harness', |
440 | 'one', 'two', 'three' |
441 | ] |
442 | ], |
443 | }, |
444 | { name => 'Just reverse', |
445 | args => { |
446 | argv => [qw( one two three )], |
447 | backwards => 1, |
448 | }, |
449 | expect => { |
450 | backwards => 1, |
451 | }, |
452 | runlog => [ |
453 | [ '_runtests', |
454 | { verbosity => 0 }, |
455 | 'TAP::Harness', |
456 | 'three', 'two', 'one' |
457 | ] |
458 | ], |
459 | }, |
460 | |
461 | { name => 'Just shuffle', |
462 | args => { |
463 | argv => [qw( one two three )], |
464 | shuffle => 1, |
465 | }, |
466 | expect => { |
467 | shuffle => 1, |
468 | }, |
469 | runlog => [ |
470 | [ '_runtests', |
471 | { verbosity => 0 }, |
472 | 'TAP::Harness', |
473 | 'xxxone', 'xxxtwo', |
474 | 'xxxthree' |
475 | ] |
476 | ], |
477 | }, |
478 | { name => 'Just taint_fail', |
479 | args => { |
480 | argv => [qw( one two three )], |
481 | taint_fail => 1, |
482 | }, |
483 | expect => { |
484 | taint_fail => 1, |
485 | }, |
486 | runlog => [ |
487 | [ '_runtests', |
488 | { switches => ['-T'], |
489 | verbosity => 0 |
490 | }, |
491 | 'TAP::Harness', |
492 | 'one', 'two', 'three' |
493 | ] |
494 | ], |
495 | }, |
496 | { name => 'Just taint_warn', |
497 | args => { |
498 | argv => [qw( one two three )], |
499 | taint_warn => 1, |
500 | }, |
501 | expect => { |
502 | taint_warn => 1, |
503 | }, |
504 | runlog => [ |
505 | [ '_runtests', |
506 | { switches => ['-t'], |
507 | verbosity => 0 |
508 | }, |
509 | 'TAP::Harness', |
510 | 'one', 'two', 'three' |
511 | ] |
512 | ], |
513 | }, |
514 | { name => 'Just verbose', |
515 | args => { |
516 | argv => [qw( one two three )], |
517 | verbose => 1, |
518 | }, |
519 | expect => { |
520 | verbose => 1, |
521 | }, |
522 | runlog => [ |
523 | [ '_runtests', |
524 | { verbosity => 1 |
525 | }, |
526 | 'TAP::Harness', |
527 | 'one', 'two', 'three' |
528 | ] |
529 | ], |
530 | }, |
531 | { name => 'Just warnings_fail', |
532 | args => { |
533 | argv => [qw( one two three )], |
534 | warnings_fail => 1, |
535 | }, |
536 | expect => { |
537 | warnings_fail => 1, |
538 | }, |
539 | runlog => [ |
540 | [ '_runtests', |
541 | { switches => ['-W'], |
542 | verbosity => 0 |
543 | }, |
544 | 'TAP::Harness', |
545 | 'one', 'two', 'three' |
546 | ] |
547 | ], |
548 | }, |
549 | { name => 'Just warnings_warn', |
550 | args => { |
551 | argv => [qw( one two three )], |
552 | warnings_warn => 1, |
553 | }, |
554 | expect => { |
555 | warnings_warn => 1, |
556 | }, |
557 | runlog => [ |
558 | [ '_runtests', |
559 | { switches => ['-w'], |
560 | verbosity => 0 |
561 | }, |
562 | 'TAP::Harness', |
563 | 'one', 'two', 'three' |
564 | ] |
565 | ], |
566 | }, |
567 | |
568 | # Command line parsing |
569 | { name => 'Switch -v', |
570 | args => { |
571 | argv => [qw( one two three )], |
572 | }, |
573 | switches => [ '-v', $dummy_test ], |
574 | expect => { |
575 | verbose => 1, |
576 | }, |
577 | runlog => [ |
578 | [ '_runtests', |
579 | { verbosity => 1 |
580 | }, |
581 | 'TAP::Harness', |
582 | $dummy_test |
583 | ] |
584 | ], |
585 | }, |
586 | |
587 | { name => 'Switch --verbose', |
588 | args => { |
589 | argv => [qw( one two three )], |
590 | }, |
591 | switches => [ '--verbose', $dummy_test ], |
592 | expect => { |
593 | verbose => 1, |
594 | }, |
595 | runlog => [ |
596 | [ '_runtests', |
597 | { verbosity => 1 |
598 | }, |
599 | 'TAP::Harness', |
600 | $dummy_test |
601 | ] |
602 | ], |
603 | }, |
604 | |
605 | { name => 'Switch -f', |
606 | args => { |
607 | argv => [qw( one two three )], |
608 | }, |
609 | switches => [ '-f', $dummy_test ], |
610 | expect => { failures => 1 }, |
611 | runlog => [ |
612 | [ '_runtests', |
613 | { failures => 1, |
614 | verbosity => 0 |
615 | }, |
616 | 'TAP::Harness', |
617 | $dummy_test |
618 | ] |
619 | ], |
620 | }, |
621 | |
622 | { name => 'Switch --failures', |
623 | args => { |
624 | argv => [qw( one two three )], |
625 | }, |
626 | switches => [ '--failures', $dummy_test ], |
627 | expect => { failures => 1 }, |
628 | runlog => [ |
629 | [ '_runtests', |
630 | { failures => 1, |
631 | verbosity => 0 |
632 | }, |
633 | 'TAP::Harness', |
634 | $dummy_test |
635 | ] |
636 | ], |
637 | }, |
638 | |
639 | { name => 'Switch -l', |
640 | args => { |
641 | argv => [qw( one two three )], |
642 | }, |
643 | switches => [ '-l', $dummy_test ], |
644 | expect => { lib => 1 }, |
645 | runlog => [ |
646 | [ '_runtests', |
647 | { lib => mabs( ['lib'] ), |
648 | verbosity => 0 |
649 | }, |
650 | 'TAP::Harness', |
651 | $dummy_test |
652 | ] |
653 | ], |
654 | }, |
655 | |
656 | { name => 'Switch --lib', |
657 | args => { |
658 | argv => [qw( one two three )], |
659 | }, |
660 | switches => [ '--lib', $dummy_test ], |
661 | expect => { lib => 1 }, |
662 | runlog => [ |
663 | [ '_runtests', |
664 | { lib => mabs( ['lib'] ), |
665 | verbosity => 0 |
666 | }, |
667 | 'TAP::Harness', |
668 | $dummy_test |
669 | ] |
670 | ], |
671 | }, |
672 | |
673 | { name => 'Switch -b', |
674 | args => { |
675 | argv => [qw( one two three )], |
676 | }, |
677 | switches => [ '-b', $dummy_test ], |
678 | expect => { blib => 1 }, |
679 | runlog => [ |
680 | [ '_runtests', |
681 | { lib => mabs( [ 'blib/lib', 'blib/arch' ] ), |
682 | verbosity => 0 |
683 | }, |
684 | 'TAP::Harness', |
685 | $dummy_test |
686 | ] |
687 | ], |
688 | }, |
689 | |
690 | { name => 'Switch --blib', |
691 | args => { |
692 | argv => [qw( one two three )], |
693 | }, |
694 | switches => [ '--blib', $dummy_test ], |
695 | expect => { blib => 1 }, |
696 | runlog => [ |
697 | [ '_runtests', |
698 | { lib => mabs( [ 'blib/lib', 'blib/arch' ] ), |
699 | verbosity => 0 |
700 | }, |
701 | 'TAP::Harness', |
702 | $dummy_test |
703 | ] |
704 | ], |
705 | }, |
706 | |
707 | { name => 'Switch -s', |
708 | args => { |
709 | argv => [qw( one two three )], |
710 | }, |
711 | switches => [ '-s', $dummy_test ], |
712 | expect => { shuffle => 1 }, |
713 | runlog => [ |
714 | [ '_runtests', |
715 | { verbosity => 0 }, |
716 | 'TAP::Harness', |
717 | "xxx$dummy_test" |
718 | ] |
719 | ], |
720 | }, |
721 | |
722 | { name => 'Switch --shuffle', |
723 | args => { |
724 | argv => [qw( one two three )], |
725 | }, |
726 | switches => [ '--shuffle', $dummy_test ], |
727 | expect => { shuffle => 1 }, |
728 | runlog => [ |
729 | [ '_runtests', |
730 | { verbosity => 0 }, |
731 | 'TAP::Harness', |
732 | "xxx$dummy_test" |
733 | ] |
734 | ], |
735 | }, |
736 | |
737 | { name => 'Switch -c', |
738 | args => { |
739 | argv => [qw( one two three )], |
740 | }, |
741 | switches => [ '-c', $dummy_test ], |
742 | expect => { color => 1 }, |
743 | runlog => [ |
744 | [ '_runtests', |
745 | { color => 1, |
746 | verbosity => 0 |
747 | }, |
748 | 'TAP::Harness', |
749 | $dummy_test |
750 | ] |
751 | ], |
752 | }, |
753 | |
754 | { name => 'Switch -r', |
755 | args => { |
756 | argv => [qw( one two three )], |
757 | }, |
758 | switches => [ '-r', $dummy_test ], |
759 | expect => { recurse => 1 }, |
760 | runlog => [ |
761 | [ '_runtests', |
762 | { verbosity => 0 }, |
763 | 'TAP::Harness', |
764 | $dummy_test |
765 | ] |
766 | ], |
767 | }, |
768 | |
769 | { name => 'Switch --recurse', |
770 | args => { |
771 | argv => [qw( one two three )], |
772 | }, |
773 | switches => [ '--recurse', $dummy_test ], |
774 | expect => { recurse => 1 }, |
775 | runlog => [ |
776 | [ '_runtests', |
777 | { verbosity => 0 }, |
778 | 'TAP::Harness', |
779 | $dummy_test |
780 | ] |
781 | ], |
782 | }, |
783 | |
784 | { name => 'Switch --reverse', |
785 | args => { |
786 | argv => [qw( one two three )], |
787 | }, |
788 | switches => [ '--reverse', @dummy_tests ], |
789 | expect => { backwards => 1 }, |
790 | runlog => [ |
791 | [ '_runtests', |
792 | { verbosity => 0 }, |
793 | 'TAP::Harness', |
794 | reverse @dummy_tests |
795 | ] |
796 | ], |
797 | }, |
798 | |
799 | { name => 'Switch -p', |
800 | args => { |
801 | argv => [qw( one two three )], |
802 | }, |
803 | switches => [ '-p', $dummy_test ], |
804 | expect => { |
805 | parse => 1, |
806 | }, |
807 | runlog => [ |
808 | [ '_runtests', |
809 | { errors => 1, |
810 | verbosity => 0 |
811 | }, |
812 | 'TAP::Harness', |
813 | $dummy_test |
814 | ] |
815 | ], |
816 | }, |
817 | |
818 | { name => 'Switch --parse', |
819 | args => { |
820 | argv => [qw( one two three )], |
821 | }, |
822 | switches => [ '--parse', $dummy_test ], |
823 | expect => { |
824 | parse => 1, |
825 | }, |
826 | runlog => [ |
827 | [ '_runtests', |
828 | { errors => 1, |
829 | verbosity => 0 |
830 | }, |
831 | 'TAP::Harness', |
832 | $dummy_test |
833 | ] |
834 | ], |
835 | }, |
836 | |
837 | { name => 'Switch -q', |
838 | args => { |
839 | argv => [qw( one two three )], |
840 | }, |
841 | switches => [ '-q', $dummy_test ], |
842 | expect => { quiet => 1 }, |
843 | runlog => [ |
844 | [ '_runtests', |
845 | { verbosity => -1 |
846 | }, |
847 | 'TAP::Harness', |
848 | $dummy_test |
849 | ] |
850 | ], |
851 | }, |
852 | |
853 | { name => 'Switch --quiet', |
854 | args => { |
855 | argv => [qw( one two three )], |
856 | }, |
857 | switches => [ '--quiet', $dummy_test ], |
858 | expect => { quiet => 1 }, |
859 | runlog => [ |
860 | [ '_runtests', |
861 | { verbosity => -1 |
862 | }, |
863 | 'TAP::Harness', |
864 | $dummy_test |
865 | ] |
866 | ], |
867 | }, |
868 | |
869 | { name => 'Switch -Q', |
870 | args => { |
871 | argv => [qw( one two three )], |
872 | }, |
873 | switches => [ '-Q', $dummy_test ], |
874 | expect => { really_quiet => 1 }, |
875 | runlog => [ |
876 | [ '_runtests', |
877 | { verbosity => -2 |
878 | }, |
879 | 'TAP::Harness', |
880 | $dummy_test |
881 | ] |
882 | ], |
883 | }, |
884 | |
885 | { name => 'Switch --QUIET', |
886 | args => { |
887 | argv => [qw( one two three )], |
888 | }, |
889 | switches => [ '--QUIET', $dummy_test ], |
890 | expect => { really_quiet => 1 }, |
891 | runlog => [ |
892 | [ '_runtests', |
893 | { verbosity => -2 |
894 | }, |
895 | 'TAP::Harness', |
896 | $dummy_test |
897 | ] |
898 | ], |
899 | }, |
900 | |
901 | { name => 'Switch -m', |
902 | args => { |
903 | argv => [qw( one two three )], |
904 | }, |
905 | switches => [ '-m', $dummy_test ], |
906 | expect => { merge => 1 }, |
907 | runlog => [ |
908 | [ '_runtests', |
909 | { merge => 1, |
910 | verbosity => 0 |
911 | }, |
912 | 'TAP::Harness', |
913 | $dummy_test |
914 | ] |
915 | ], |
916 | }, |
917 | |
918 | { name => 'Switch --merge', |
919 | args => { |
920 | argv => [qw( one two three )], |
921 | }, |
922 | switches => [ '--merge', $dummy_test ], |
923 | expect => { merge => 1 }, |
924 | runlog => [ |
925 | [ '_runtests', |
926 | { merge => 1, |
927 | verbosity => 0 |
928 | }, |
929 | 'TAP::Harness', |
930 | $dummy_test |
931 | ] |
932 | ], |
933 | }, |
934 | |
935 | { name => 'Switch --directives', |
936 | args => { |
937 | argv => [qw( one two three )], |
938 | }, |
939 | switches => [ '--directives', $dummy_test ], |
940 | expect => { directives => 1 }, |
941 | runlog => [ |
942 | [ '_runtests', |
943 | { directives => 1, |
944 | verbosity => 0 |
945 | }, |
946 | 'TAP::Harness', |
947 | $dummy_test |
948 | ] |
949 | ], |
950 | }, |
951 | |
952 | # Executing one word (why would it be a -s though?) |
953 | { name => 'Switch --exec -s', |
954 | args => { |
955 | argv => [qw( one two three )], |
956 | }, |
957 | switches => [ '--exec', '-s', $dummy_test ], |
958 | expect => { exec => '-s' }, |
959 | runlog => [ |
960 | [ '_runtests', { exec => ['-s'], verbosity => 0 }, |
961 | 'TAP::Harness', |
962 | $dummy_test |
963 | ] |
964 | ], |
965 | }, |
966 | |
967 | # multi-part exec |
968 | { name => 'Switch --exec "/foo/bar/perl -Ilib"', |
969 | args => { |
970 | argv => [qw( one two three )], |
971 | }, |
972 | switches => [ '--exec', '/foo/bar/perl -Ilib', $dummy_test ], |
973 | expect => { exec => '/foo/bar/perl -Ilib' }, |
974 | runlog => [ |
975 | [ '_runtests', |
976 | { exec => [qw(/foo/bar/perl -Ilib)], |
977 | verbosity => 0 |
978 | }, |
979 | 'TAP::Harness', |
980 | $dummy_test |
981 | ] |
982 | ], |
983 | }, |
984 | |
985 | # null exec (run tests as compiled binaries) |
986 | { name => 'Switch --exec ""', |
987 | switches => [ '--exec', '', $dummy_test ], |
988 | expect => { |
989 | exec => # ick, must workaround the || default bit with a sub |
990 | sub { my $val = shift; defined($val) and !length($val) } |
991 | }, |
992 | runlog => [ |
993 | [ '_runtests', |
994 | { exec => [], verbosity => 0 }, |
995 | 'TAP::Harness', |
996 | $dummy_test |
997 | ] |
998 | ], |
999 | }, |
1000 | |
1001 | # Plugins |
1002 | { name => 'Load plugin', |
1003 | switches => [ '-P', 'Dummy', $dummy_test ], |
1004 | args => { |
1005 | argv => [qw( one two three )], |
1006 | }, |
1007 | expect => { |
1008 | plugins => ['Dummy'], |
1009 | }, |
1010 | extra => sub { |
1011 | my @loaded = get_import_log(); |
1012 | is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ], |
1013 | "Plugin loaded OK"; |
1014 | }, |
1015 | plan => 1, |
1016 | runlog => [ |
1017 | [ '_runtests', |
1018 | { verbosity => 0 }, |
1019 | 'TAP::Harness', |
1020 | $dummy_test |
1021 | ] |
1022 | ], |
1023 | }, |
1024 | |
1025 | { name => 'Load plugin (args)', |
1026 | switches => [ '-P', 'Dummy=cracking,cheese,gromit', $dummy_test ], |
1027 | args => { |
1028 | argv => [qw( one two three )], |
1029 | }, |
1030 | expect => { |
1031 | plugins => ['Dummy'], |
1032 | }, |
1033 | extra => sub { |
1034 | my @loaded = get_import_log(); |
1035 | is_deeply \@loaded, |
1036 | [ [ 'App::Prove::Plugin::Dummy', 'cracking', 'cheese', |
1037 | 'gromit' |
1038 | ] |
1039 | ], |
1040 | "Plugin loaded OK"; |
1041 | }, |
1042 | plan => 1, |
1043 | runlog => [ |
1044 | [ '_runtests', |
1045 | { verbosity => 0 }, |
1046 | 'TAP::Harness', |
1047 | $dummy_test |
1048 | ] |
1049 | ], |
1050 | }, |
1051 | |
1052 | { name => 'Load plugin (explicit path)', |
1053 | switches => [ '-P', 'App::Prove::Plugin::Dummy', $dummy_test ], |
1054 | args => { |
1055 | argv => [qw( one two three )], |
1056 | }, |
1057 | expect => { |
1058 | plugins => ['Dummy'], |
1059 | }, |
1060 | extra => sub { |
1061 | my @loaded = get_import_log(); |
1062 | is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ], |
1063 | "Plugin loaded OK"; |
1064 | }, |
1065 | plan => 1, |
1066 | runlog => [ |
1067 | [ '_runtests', |
1068 | { verbosity => 0 }, |
1069 | 'TAP::Harness', |
1070 | $dummy_test |
1071 | ] |
1072 | ], |
1073 | }, |
1074 | |
1075 | { name => 'Load module', |
1076 | switches => [ '-M', 'App::Prove::Plugin::Dummy', $dummy_test ], |
1077 | args => { |
1078 | argv => [qw( one two three )], |
1079 | }, |
1080 | expect => { |
1081 | plugins => ['Dummy'], |
1082 | }, |
1083 | extra => sub { |
1084 | my @loaded = get_import_log(); |
1085 | is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ], |
1086 | "Plugin loaded OK"; |
1087 | }, |
1088 | plan => 1, |
1089 | runlog => [ |
1090 | [ '_runtests', |
1091 | { verbosity => 0 }, |
1092 | 'TAP::Harness', |
1093 | $dummy_test |
1094 | ] |
1095 | ], |
1096 | }, |
1097 | |
1098 | # TODO |
1099 | # Hmm, that doesn't work... |
1100 | # { name => 'Switch -h', |
1101 | # args => { |
1102 | # argv => [qw( one two three )], |
1103 | # }, |
1104 | # switches => [ '-h', $dummy_test ], |
1105 | # expect => {}, |
1106 | # runlog => [ |
1107 | # [ '_runtests', |
1108 | # {}, |
1109 | # 'TAP::Harness', |
1110 | # $dummy_test |
1111 | # ] |
1112 | # ], |
1113 | # }, |
1114 | |
1115 | # { name => 'Switch --help', |
1116 | # args => { |
1117 | # argv => [qw( one two three )], |
1118 | # }, |
1119 | # switches => [ '--help', $dummy_test ], |
1120 | # expect => {}, |
1121 | # runlog => [ |
1122 | # [ {}, |
1123 | # 'TAP::Harness', |
1124 | # $dummy_test |
1125 | # ] |
1126 | # ], |
1127 | # }, |
1128 | # { name => 'Switch -?', |
1129 | # args => { |
1130 | # argv => [qw( one two three )], |
1131 | # }, |
1132 | # switches => [ '-?', $dummy_test ], |
1133 | # expect => {}, |
1134 | # runlog => [ |
1135 | # [ {}, |
1136 | # 'TAP::Harness', |
1137 | # $dummy_test |
1138 | # ] |
1139 | # ], |
1140 | # }, |
1141 | # |
1142 | # { name => 'Switch -H', |
1143 | # args => { |
1144 | # argv => [qw( one two three )], |
1145 | # }, |
1146 | # switches => [ '-H', $dummy_test ], |
1147 | # expect => {}, |
1148 | # runlog => [ |
1149 | # [ {}, |
1150 | # 'TAP::Harness', |
1151 | # $dummy_test |
1152 | # ] |
1153 | # ], |
1154 | # }, |
1155 | # |
1156 | # { name => 'Switch --man', |
1157 | # args => { |
1158 | # argv => [qw( one two three )], |
1159 | # }, |
1160 | # switches => [ '--man', $dummy_test ], |
1161 | # expect => {}, |
1162 | # runlog => [ |
1163 | # [ {}, |
1164 | # 'TAP::Harness', |
1165 | # $dummy_test |
1166 | # ] |
1167 | # ], |
1168 | # }, |
1169 | # |
1170 | # { name => 'Switch -V', |
1171 | # args => { |
1172 | # argv => [qw( one two three )], |
1173 | # }, |
1174 | # switches => [ '-V', $dummy_test ], |
1175 | # expect => {}, |
1176 | # runlog => [ |
1177 | # [ {}, |
1178 | # 'TAP::Harness', |
1179 | # $dummy_test |
1180 | # ] |
1181 | # ], |
1182 | # }, |
1183 | # |
1184 | # { name => 'Switch --version', |
1185 | # args => { |
1186 | # argv => [qw( one two three )], |
1187 | # }, |
1188 | # switches => [ '--version', $dummy_test ], |
1189 | # expect => {}, |
1190 | # runlog => [ |
1191 | # [ {}, |
1192 | # 'TAP::Harness', |
1193 | # $dummy_test |
1194 | # ] |
1195 | # ], |
1196 | # }, |
1197 | # |
1198 | # { name => 'Switch --color!', |
1199 | # args => { |
1200 | # argv => [qw( one two three )], |
1201 | # }, |
1202 | # switches => [ '--color!', $dummy_test ], |
1203 | # expect => {}, |
1204 | # runlog => [ |
1205 | # [ {}, |
1206 | # 'TAP::Harness', |
1207 | # $dummy_test |
1208 | # ] |
1209 | # ], |
1210 | # }, |
1211 | # |
1212 | { name => 'Switch -I=s@', |
1213 | args => { |
1214 | argv => [qw( one two three )], |
1215 | }, |
1216 | switches => [ '-Ilib', $dummy_test ], |
1217 | expect => { |
1218 | includes => sub { |
1219 | my ( $val, $attr ) = @_; |
1220 | return |
1221 | 'ARRAY' eq ref $val |
1222 | && 1 == @$val |
1223 | && $val->[0] =~ /lib$/; |
1224 | }, |
1225 | }, |
1226 | }, |
1227 | |
1228 | # { name => 'Switch -a', |
1229 | # args => { |
1230 | # argv => [qw( one two three )], |
1231 | # }, |
1232 | # switches => [ '-a', $dummy_test ], |
1233 | # expect => {}, |
1234 | # runlog => [ |
1235 | # [ {}, |
1236 | # 'TAP::Harness', |
1237 | # $dummy_test |
1238 | # ] |
1239 | # ], |
1240 | # }, |
1241 | # |
1242 | # { name => 'Switch --archive=-s', |
1243 | # args => { |
1244 | # argv => [qw( one two three )], |
1245 | # }, |
1246 | # switches => [ '--archive=-s', $dummy_test ], |
1247 | # expect => {}, |
1248 | # runlog => [ |
1249 | # [ {}, |
1250 | # 'TAP::Harness', |
1251 | # $dummy_test |
1252 | # ] |
1253 | # ], |
1254 | # }, |
1255 | # |
1256 | # { name => 'Switch --formatter=-s', |
1257 | # args => { |
1258 | # argv => [qw( one two three )], |
1259 | # }, |
1260 | # switches => [ '--formatter=-s', $dummy_test ], |
1261 | # expect => {}, |
1262 | # runlog => [ |
1263 | # [ {}, |
1264 | # 'TAP::Harness', |
1265 | # $dummy_test |
1266 | # ] |
1267 | # ], |
1268 | # }, |
1269 | # |
1270 | # { name => 'Switch -e', |
1271 | # args => { |
1272 | # argv => [qw( one two three )], |
1273 | # }, |
1274 | # switches => [ '-e', $dummy_test ], |
1275 | # expect => {}, |
1276 | # runlog => [ |
1277 | # [ {}, |
1278 | # 'TAP::Harness', |
1279 | # $dummy_test |
1280 | # ] |
1281 | # ], |
1282 | # }, |
1283 | # |
1284 | # { name => 'Switch --harness=-s', |
1285 | # args => { |
1286 | # argv => [qw( one two three )], |
1287 | # }, |
1288 | # switches => [ '--harness=-s', $dummy_test ], |
1289 | # expect => {}, |
1290 | # runlog => [ |
1291 | # [ {}, |
1292 | # 'TAP::Harness', |
1293 | # $dummy_test |
1294 | # ] |
1295 | # ], |
1296 | # }, |
1297 | |
1298 | ); |
1299 | |
1300 | # END SCHEDULE |
1301 | ######################################################################## |
1302 | |
1303 | my $extra_plan = 0; |
1304 | for my $test (@SCHEDULE) { |
1305 | $extra_plan += $test->{plan} || 0; |
1306 | $extra_plan += 2 if $test->{runlog}; |
1307 | $extra_plan += 1 if $test->{switches}; |
1308 | } |
1309 | |
1310 | plan tests => @SCHEDULE * ( 3 + @ATTR ) + $extra_plan; |
1311 | } # END PLAN |
1312 | |
1313 | # ACTUAL TEST |
1314 | for my $test (@SCHEDULE) { |
1315 | my $name = $test->{name}; |
1316 | my $class = $test->{class} || 'FakeProve'; |
1317 | |
1318 | ok my $app = $class->new( exists $test->{args} ? $test->{args} : () ), |
1319 | "$name: App::Prove created OK"; |
1320 | |
1321 | isa_ok $app, 'App::Prove'; |
1322 | isa_ok $app, $class; |
1323 | |
1324 | # Optionally parse command args |
1325 | if ( my $switches = $test->{switches} ) { |
1326 | eval { $app->process_args( '--norc', @$switches ) }; |
1327 | if ( my $err_pattern = $test->{parse_error} ) { |
1328 | like $@, $err_pattern, "$name: expected parse error"; |
1329 | } |
1330 | else { |
1331 | ok !$@, "$name: no parse error"; |
1332 | } |
1333 | } |
1334 | |
1335 | my $expect = $test->{expect} || {}; |
1336 | for my $attr ( sort @ATTR ) { |
1337 | my $val = $app->$attr(); |
1338 | my $assertion = $expect->{$attr} || $DEFAULT_ASSERTION{$attr}; |
1339 | my $is_ok = undef; |
1340 | |
1341 | if ( 'CODE' eq ref $assertion ) { |
1342 | $is_ok = ok $assertion->( $val, $attr ), |
1343 | "$name: $attr has the expected value"; |
1344 | } |
1345 | elsif ( 'Regexp' eq ref $assertion ) { |
1346 | $is_ok = like $val, $assertion, "$name: $attr matches $assertion"; |
1347 | } |
1348 | else { |
1349 | $is_ok = is_deeply $val, $assertion, |
1350 | "$name: $attr has the expected value"; |
1351 | } |
1352 | |
1353 | unless ($is_ok) { |
1354 | diag "got $val for $attr"; |
1355 | } |
1356 | } |
1357 | |
1358 | if ( my $runlog = $test->{runlog} ) { |
1359 | eval { $app->run }; |
1360 | if ( my $err_pattern = $test->{run_error} ) { |
1361 | like $@, $err_pattern, "$name: expected error OK"; |
1362 | pass; |
1363 | pass for 1 .. $test->{plan}; |
1364 | } |
1365 | else { |
1366 | unless ( ok !$@, "$name: no error OK" ) { |
1367 | diag "$name: error: $@\n"; |
1368 | } |
1369 | |
1370 | my $gotlog = [ $app->get_log ]; |
1371 | |
1372 | if ( my $extra = $test->{extra} ) { |
1373 | $extra->($gotlog); |
1374 | } |
1375 | |
1376 | unless ( |
1377 | is_deeply $gotlog, $runlog, |
1378 | "$name: run results match" |
1379 | ) |
1380 | { |
1381 | use Data::Dumper; |
1382 | diag Dumper( { wanted => $runlog, got => $gotlog } ); |
1383 | } |
1384 | } |
1385 | } |
1386 | } |