6 print "1..0 # Skip, needs fixing. Probably an -I issue\n";
22 @ISA = qw( App::Prove );
26 my $self = $class->SUPER::new(@_);
31 sub _color_default {0}
35 push @{ $self->{_log} }, [ '_runtests', @_ ];
40 my @log = @{ $self->{_log} };
54 return [ map { File::Spec->rel2abs($_) } @$ar ];
60 sub test_log_import { push @import_log, [@_] }
63 my @log = @import_log;
69 my ( @ATTR, %DEFAULT_ASSERTION, @SCHEDULE );
71 # see the "ACTUAL TEST" section at the bottom
77 archive argv blib color directives exec failures formatter harness
78 includes lib merge parse quiet really_quiet recurse backwards
79 shuffle taint_fail taint_warn verbose warnings_fail warnings_warn
82 # what we expect if the 'expect' hash does not define it
83 %DEFAULT_ASSERTION = map { $_ => undef } @ATTR;
85 $DEFAULT_ASSERTION{includes} = $DEFAULT_ASSERTION{argv}
86 = sub { 'ARRAY' eq ref shift };
88 my @dummy_tests = map { File::Spec->catdir( 't', 'sample-tests', $_ ) }
89 qw(simple simple_yaml);
90 my $dummy_test = $dummy_tests[0];
92 ########################################################################
93 # declarations - this drives all of the subtests.
94 # The cheatsheet follows.
95 # required: name, expect
97 # args - arguments to constructor
98 # switches - command-line switches
99 # runlog - expected results of internal calls to _runtests, must
100 # match FakeProve's _log attr
101 # run_error - depends on 'runlog' (if missing, asserts no error)
102 # extra - follow-up check to handle exceptional cleanup / verification
103 # class - The App::Prove subclass to test. Defaults to FakeProve
105 { name => 'Create empty',
108 { name => 'Set all options via constructor',
111 argv => [qw(one two three)],
119 includes => [qw(four five six)],
136 argv => [qw(one two three)],
144 includes => [qw(four five six)],
160 { name => 'Call with defaults',
161 args => { argv => [qw( one two three )] },
174 # Test all options individually
176 # { name => 'Just archive',
178 # argv => [qw( one two three )],
193 { name => 'Just argv',
195 argv => [qw( one two three )],
198 argv => [qw( one two three )],
209 { name => 'Just blib',
211 argv => [qw( one two three )],
219 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
223 'one', 'two', 'three'
228 { name => 'Just color',
230 argv => [qw( one two three )],
242 'one', 'two', 'three'
247 { name => 'Just directives',
249 argv => [qw( one two three )],
261 'one', 'two', 'three'
265 { name => 'Just exec',
267 argv => [qw( one two three )],
279 'one', 'two', 'three'
283 { name => 'Just failures',
285 argv => [qw( one two three )],
297 'one', 'two', 'three'
302 { name => 'Just formatter',
304 argv => [qw( one two three )],
305 formatter => 'TAP::Harness',
308 formatter => 'TAP::Harness',
312 { formatter_class => 'TAP::Harness',
316 'one', 'two', 'three'
321 { name => 'Just includes',
323 argv => [qw( one two three )],
324 includes => [qw( four five six )],
327 includes => [qw( four five six )],
331 { lib => mabs( [qw( four five six )] ),
335 'one', 'two', 'three'
339 { name => 'Just lib',
341 argv => [qw( one two three )],
349 { lib => mabs( ['lib'] ),
353 'one', 'two', 'three'
357 { name => 'Just merge',
359 argv => [qw( one two three )],
371 'one', 'two', 'three'
375 { name => 'Just parse',
377 argv => [qw( one two three )],
389 'one', 'two', 'three'
393 { name => 'Just quiet',
395 argv => [qw( one two three )],
406 'one', 'two', 'three'
410 { name => 'Just really_quiet',
412 argv => [qw( one two three )],
423 'one', 'two', 'three'
427 { name => 'Just recurse',
429 argv => [qw( one two three )],
439 'one', 'two', 'three'
443 { name => 'Just reverse',
445 argv => [qw( one two three )],
455 'three', 'two', 'one'
460 { name => 'Just shuffle',
462 argv => [qw( one two three )],
477 { name => 'Just taint_fail',
479 argv => [qw( one two three )],
487 { switches => ['-T'],
491 'one', 'two', 'three'
495 { name => 'Just taint_warn',
497 argv => [qw( one two three )],
505 { switches => ['-t'],
509 'one', 'two', 'three'
513 { name => 'Just verbose',
515 argv => [qw( one two three )],
526 'one', 'two', 'three'
530 { name => 'Just warnings_fail',
532 argv => [qw( one two three )],
540 { switches => ['-W'],
544 'one', 'two', 'three'
548 { name => 'Just warnings_warn',
550 argv => [qw( one two three )],
558 { switches => ['-w'],
562 'one', 'two', 'three'
567 # Command line parsing
568 { name => 'Switch -v',
570 argv => [qw( one two three )],
572 switches => [ '-v', $dummy_test ],
586 { name => 'Switch --verbose',
588 argv => [qw( one two three )],
590 switches => [ '--verbose', $dummy_test ],
604 { name => 'Switch -f',
606 argv => [qw( one two three )],
608 switches => [ '-f', $dummy_test ],
609 expect => { failures => 1 },
621 { name => 'Switch --failures',
623 argv => [qw( one two three )],
625 switches => [ '--failures', $dummy_test ],
626 expect => { failures => 1 },
638 { name => 'Switch -l',
640 argv => [qw( one two three )],
642 switches => [ '-l', $dummy_test ],
643 expect => { lib => 1 },
646 { lib => mabs( ['lib'] ),
655 { name => 'Switch --lib',
657 argv => [qw( one two three )],
659 switches => [ '--lib', $dummy_test ],
660 expect => { lib => 1 },
663 { lib => mabs( ['lib'] ),
672 { name => 'Switch -b',
674 argv => [qw( one two three )],
676 switches => [ '-b', $dummy_test ],
677 expect => { blib => 1 },
680 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
689 { name => 'Switch --blib',
691 argv => [qw( one two three )],
693 switches => [ '--blib', $dummy_test ],
694 expect => { blib => 1 },
697 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
706 { name => 'Switch -s',
708 argv => [qw( one two three )],
710 switches => [ '-s', $dummy_test ],
711 expect => { shuffle => 1 },
721 { name => 'Switch --shuffle',
723 argv => [qw( one two three )],
725 switches => [ '--shuffle', $dummy_test ],
726 expect => { shuffle => 1 },
736 { name => 'Switch -c',
738 argv => [qw( one two three )],
740 switches => [ '-c', $dummy_test ],
741 expect => { color => 1 },
753 { name => 'Switch -r',
755 argv => [qw( one two three )],
757 switches => [ '-r', $dummy_test ],
758 expect => { recurse => 1 },
768 { name => 'Switch --recurse',
770 argv => [qw( one two three )],
772 switches => [ '--recurse', $dummy_test ],
773 expect => { recurse => 1 },
783 { name => 'Switch --reverse',
785 argv => [qw( one two three )],
787 switches => [ '--reverse', @dummy_tests ],
788 expect => { backwards => 1 },
798 { name => 'Switch -p',
800 argv => [qw( one two three )],
802 switches => [ '-p', $dummy_test ],
817 { name => 'Switch --parse',
819 argv => [qw( one two three )],
821 switches => [ '--parse', $dummy_test ],
836 { name => 'Switch -q',
838 argv => [qw( one two three )],
840 switches => [ '-q', $dummy_test ],
841 expect => { quiet => 1 },
852 { name => 'Switch --quiet',
854 argv => [qw( one two three )],
856 switches => [ '--quiet', $dummy_test ],
857 expect => { quiet => 1 },
868 { name => 'Switch -Q',
870 argv => [qw( one two three )],
872 switches => [ '-Q', $dummy_test ],
873 expect => { really_quiet => 1 },
884 { name => 'Switch --QUIET',
886 argv => [qw( one two three )],
888 switches => [ '--QUIET', $dummy_test ],
889 expect => { really_quiet => 1 },
900 { name => 'Switch -m',
902 argv => [qw( one two three )],
904 switches => [ '-m', $dummy_test ],
905 expect => { merge => 1 },
917 { name => 'Switch --merge',
919 argv => [qw( one two three )],
921 switches => [ '--merge', $dummy_test ],
922 expect => { merge => 1 },
934 { name => 'Switch --directives',
936 argv => [qw( one two three )],
938 switches => [ '--directives', $dummy_test ],
939 expect => { directives => 1 },
951 # Executing one word (why would it be a -s though?)
952 { name => 'Switch --exec -s',
954 argv => [qw( one two three )],
956 switches => [ '--exec', '-s', $dummy_test ],
957 expect => { exec => '-s' },
959 [ '_runtests', { exec => ['-s'], verbosity => 0 },
967 { name => 'Switch --exec "/foo/bar/perl -Ilib"',
969 argv => [qw( one two three )],
971 switches => [ '--exec', '/foo/bar/perl -Ilib', $dummy_test ],
972 expect => { exec => '/foo/bar/perl -Ilib' },
975 { exec => [qw(/foo/bar/perl -Ilib)],
984 # null exec (run tests as compiled binaries)
985 { name => 'Switch --exec ""',
986 switches => [ '--exec', '', $dummy_test ],
988 exec => # ick, must workaround the || default bit with a sub
989 sub { my $val = shift; defined($val) and !length($val) }
993 { exec => [], verbosity => 0 },
1001 { name => 'Load plugin',
1002 switches => [ '-P', 'Dummy', $dummy_test ],
1004 argv => [qw( one two three )],
1007 plugins => ['Dummy'],
1010 my @loaded = get_import_log();
1011 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1024 { name => 'Load plugin (args)',
1025 switches => [ '-P', 'Dummy=cracking,cheese,gromit', $dummy_test ],
1027 argv => [qw( one two three )],
1030 plugins => ['Dummy'],
1033 my @loaded = get_import_log();
1035 [ [ 'App::Prove::Plugin::Dummy', 'cracking', 'cheese',
1051 { name => 'Load plugin (explicit path)',
1052 switches => [ '-P', 'App::Prove::Plugin::Dummy', $dummy_test ],
1054 argv => [qw( one two three )],
1057 plugins => ['Dummy'],
1060 my @loaded = get_import_log();
1061 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1074 { name => 'Load module',
1075 switches => [ '-M', 'App::Prove::Plugin::Dummy', $dummy_test ],
1077 argv => [qw( one two three )],
1080 plugins => ['Dummy'],
1083 my @loaded = get_import_log();
1084 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1098 # Hmm, that doesn't work...
1099 # { name => 'Switch -h',
1101 # argv => [qw( one two three )],
1103 # switches => [ '-h', $dummy_test ],
1114 # { name => 'Switch --help',
1116 # argv => [qw( one two three )],
1118 # switches => [ '--help', $dummy_test ],
1127 # { name => 'Switch -?',
1129 # argv => [qw( one two three )],
1131 # switches => [ '-?', $dummy_test ],
1141 # { name => 'Switch -H',
1143 # argv => [qw( one two three )],
1145 # switches => [ '-H', $dummy_test ],
1155 # { name => 'Switch --man',
1157 # argv => [qw( one two three )],
1159 # switches => [ '--man', $dummy_test ],
1169 # { name => 'Switch -V',
1171 # argv => [qw( one two three )],
1173 # switches => [ '-V', $dummy_test ],
1183 # { name => 'Switch --version',
1185 # argv => [qw( one two three )],
1187 # switches => [ '--version', $dummy_test ],
1197 # { name => 'Switch --color!',
1199 # argv => [qw( one two three )],
1201 # switches => [ '--color!', $dummy_test ],
1211 { name => 'Switch -I=s@',
1213 argv => [qw( one two three )],
1215 switches => [ '-Ilib', $dummy_test ],
1218 my ( $val, $attr ) = @_;
1222 && $val->[0] =~ /lib$/;
1227 # { name => 'Switch -a',
1229 # argv => [qw( one two three )],
1231 # switches => [ '-a', $dummy_test ],
1241 # { name => 'Switch --archive=-s',
1243 # argv => [qw( one two three )],
1245 # switches => [ '--archive=-s', $dummy_test ],
1255 # { name => 'Switch --formatter=-s',
1257 # argv => [qw( one two three )],
1259 # switches => [ '--formatter=-s', $dummy_test ],
1269 # { name => 'Switch -e',
1271 # argv => [qw( one two three )],
1273 # switches => [ '-e', $dummy_test ],
1283 # { name => 'Switch --harness=-s',
1285 # argv => [qw( one two three )],
1287 # switches => [ '--harness=-s', $dummy_test ],
1300 ########################################################################
1303 for my $test (@SCHEDULE) {
1304 $extra_plan += $test->{plan} || 0;
1305 $extra_plan += 2 if $test->{runlog};
1306 $extra_plan += 1 if $test->{switches};
1309 plan tests => @SCHEDULE * ( 3 + @ATTR ) + $extra_plan;
1313 for my $test (@SCHEDULE) {
1314 my $name = $test->{name};
1315 my $class = $test->{class} || 'FakeProve';
1317 ok my $app = $class->new( exists $test->{args} ? $test->{args} : () ),
1318 "$name: App::Prove created OK";
1320 isa_ok $app, 'App::Prove';
1321 isa_ok $app, $class;
1323 # Optionally parse command args
1324 if ( my $switches = $test->{switches} ) {
1325 eval { $app->process_args( '--norc', @$switches ) };
1326 if ( my $err_pattern = $test->{parse_error} ) {
1327 like $@, $err_pattern, "$name: expected parse error";
1330 ok !$@, "$name: no parse error";
1334 my $expect = $test->{expect} || {};
1335 for my $attr ( sort @ATTR ) {
1336 my $val = $app->$attr();
1337 my $assertion = $expect->{$attr} || $DEFAULT_ASSERTION{$attr};
1340 if ( 'CODE' eq ref $assertion ) {
1341 $is_ok = ok $assertion->( $val, $attr ),
1342 "$name: $attr has the expected value";
1344 elsif ( 'Regexp' eq ref $assertion ) {
1345 $is_ok = like $val, $assertion, "$name: $attr matches $assertion";
1348 $is_ok = is_deeply $val, $assertion,
1349 "$name: $attr has the expected value";
1353 diag "got $val for $attr";
1357 if ( my $runlog = $test->{runlog} ) {
1359 if ( my $err_pattern = $test->{run_error} ) {
1360 like $@, $err_pattern, "$name: expected error OK";
1362 pass for 1 .. $test->{plan};
1365 unless ( ok !$@, "$name: no error OK" ) {
1366 diag "$name: error: $@\n";
1369 my $gotlog = [ $app->get_log ];
1371 if ( my $extra = $test->{extra} ) {
1376 is_deeply $gotlog, $runlog,
1377 "$name: run results match"
1381 diag Dumper( { wanted => $runlog, got => $gotlog } );