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