4 if ( $ENV{PERL_CORE} ) {
6 @INC = ( '../lib', '../ext/Test/Harness/t/lib' );
23 @ISA = qw( App::Prove );
27 my $self = $class->SUPER::new(@_);
32 sub _color_default {0}
36 push @{ $self->{_log} }, [ '_runtests', @_ ];
41 my @log = @{ $self->{_log} };
55 return [ map { File::Spec->rel2abs($_) } @$ar ];
61 sub test_log_import { push @import_log, [@_] }
64 my @log = @import_log;
70 my ( @ATTR, %DEFAULT_ASSERTION, @SCHEDULE );
72 # see the "ACTUAL TEST" section at the bottom
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
84 # what we expect if the 'expect' hash does not define it
85 %DEFAULT_ASSERTION = map { $_ => undef } @ATTR;
87 $DEFAULT_ASSERTION{includes} = $DEFAULT_ASSERTION{argv}
88 = sub { 'ARRAY' eq ref shift };
90 my @dummy_tests = map { File::Spec->catdir( 't', 'sample-tests', $_ ) }
91 qw(simple simple_yaml);
92 my $dummy_test = $dummy_tests[0];
94 ########################################################################
95 # declarations - this drives all of the subtests.
96 # The cheatsheet follows.
97 # required: name, expect
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
107 { name => 'Create empty',
110 { name => 'Set all options via constructor',
113 argv => [qw(one two three)],
121 includes => [qw(four five six)],
138 argv => [qw(one two three)],
146 includes => [qw(four five six)],
162 { name => 'Call with defaults',
163 args => { argv => [qw( one two three )] },
171 'one', 'two', 'three'
176 # Test all options individually
178 # { name => 'Just archive',
180 # argv => [qw( one two three )],
195 { name => 'Just argv',
197 argv => [qw( one two three )],
200 argv => [qw( one two three )],
204 { verbosity => 0, show_count => 1 },
211 { name => 'Just blib',
213 argv => [qw( one two three )],
221 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
226 'one', 'two', 'three'
231 { name => 'Just color',
233 argv => [qw( one two three )],
246 'one', 'two', 'three'
251 { name => 'Just directives',
253 argv => [qw( one two three )],
266 'one', 'two', 'three'
270 { name => 'Just exec',
272 argv => [qw( one two three )],
285 'one', 'two', 'three'
289 { name => 'Just failures',
291 argv => [qw( one two three )],
304 'one', 'two', 'three'
309 { name => 'Just formatter',
311 argv => [qw( one two three )],
312 formatter => 'TAP::Harness',
315 formatter => 'TAP::Harness',
319 { formatter_class => 'TAP::Harness',
324 'one', 'two', 'three'
329 { name => 'Just includes',
331 argv => [qw( one two three )],
332 includes => [qw( four five six )],
335 includes => [qw( four five six )],
339 { lib => mabs( [qw( four five six )] ),
344 'one', 'two', 'three'
348 { name => 'Just lib',
350 argv => [qw( one two three )],
358 { lib => mabs( ['lib'] ),
363 'one', 'two', 'three'
367 { name => 'Just merge',
369 argv => [qw( one two three )],
382 'one', 'two', 'three'
386 { name => 'Just parse',
388 argv => [qw( one two three )],
401 'one', 'two', 'three'
405 { name => 'Just quiet',
407 argv => [qw( one two three )],
419 'one', 'two', 'three'
423 { name => 'Just really_quiet',
425 argv => [qw( one two three )],
437 'one', 'two', 'three'
441 { name => 'Just recurse',
443 argv => [qw( one two three )],
455 'one', 'two', 'three'
459 { name => 'Just reverse',
461 argv => [qw( one two three )],
473 'three', 'two', 'one'
478 { name => 'Just shuffle',
480 argv => [qw( one two three )],
497 { name => 'Just taint_fail',
499 argv => [qw( one two three )],
507 { switches => ['-T'],
512 'one', 'two', 'three'
516 { name => 'Just taint_warn',
518 argv => [qw( one two three )],
526 { switches => ['-t'],
531 'one', 'two', 'three'
535 { name => 'Just verbose',
537 argv => [qw( one two three )],
549 'one', 'two', 'three'
553 { name => 'Just warnings_fail',
555 argv => [qw( one two three )],
563 { switches => ['-W'],
568 'one', 'two', 'three'
572 { name => 'Just warnings_warn',
574 argv => [qw( one two three )],
582 { switches => ['-w'],
587 'one', 'two', 'three'
592 # Command line parsing
593 { name => 'Switch -v',
595 argv => [qw( one two three )],
597 switches => [ '-v', $dummy_test ],
612 { name => 'Switch --verbose',
614 argv => [qw( one two three )],
616 switches => [ '--verbose', $dummy_test ],
631 { name => 'Switch -f',
633 argv => [qw( one two three )],
635 switches => [ '-f', $dummy_test ],
636 expect => { failures => 1 },
649 { name => 'Switch --failures',
651 argv => [qw( one two three )],
653 switches => [ '--failures', $dummy_test ],
654 expect => { failures => 1 },
667 { name => 'Switch -l',
669 argv => [qw( one two three )],
671 switches => [ '-l', $dummy_test ],
672 expect => { lib => 1 },
675 { lib => mabs( ['lib'] ),
685 { name => 'Switch --lib',
687 argv => [qw( one two three )],
689 switches => [ '--lib', $dummy_test ],
690 expect => { lib => 1 },
693 { lib => mabs( ['lib'] ),
703 { name => 'Switch -b',
705 argv => [qw( one two three )],
707 switches => [ '-b', $dummy_test ],
708 expect => { blib => 1 },
711 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
721 { name => 'Switch --blib',
723 argv => [qw( one two three )],
725 switches => [ '--blib', $dummy_test ],
726 expect => { blib => 1 },
729 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
739 { name => 'Switch -s',
741 argv => [qw( one two three )],
743 switches => [ '-s', $dummy_test ],
744 expect => { shuffle => 1 },
756 { name => 'Switch --shuffle',
758 argv => [qw( one two three )],
760 switches => [ '--shuffle', $dummy_test ],
761 expect => { shuffle => 1 },
773 { name => 'Switch -c',
775 argv => [qw( one two three )],
777 switches => [ '-c', $dummy_test ],
778 expect => { color => 1 },
791 { name => 'Switch -r',
793 argv => [qw( one two three )],
795 switches => [ '-r', $dummy_test ],
796 expect => { recurse => 1 },
808 { name => 'Switch --recurse',
810 argv => [qw( one two three )],
812 switches => [ '--recurse', $dummy_test ],
813 expect => { recurse => 1 },
825 { name => 'Switch --reverse',
827 argv => [qw( one two three )],
829 switches => [ '--reverse', @dummy_tests ],
830 expect => { backwards => 1 },
842 { name => 'Switch -p',
844 argv => [qw( one two three )],
846 switches => [ '-p', $dummy_test ],
862 { name => 'Switch --parse',
864 argv => [qw( one two three )],
866 switches => [ '--parse', $dummy_test ],
882 { name => 'Switch -q',
884 argv => [qw( one two three )],
886 switches => [ '-q', $dummy_test ],
887 expect => { quiet => 1 },
899 { name => 'Switch --quiet',
901 argv => [qw( one two three )],
903 switches => [ '--quiet', $dummy_test ],
904 expect => { quiet => 1 },
916 { name => 'Switch -Q',
918 argv => [qw( one two three )],
920 switches => [ '-Q', $dummy_test ],
921 expect => { really_quiet => 1 },
933 { name => 'Switch --QUIET',
935 argv => [qw( one two three )],
937 switches => [ '--QUIET', $dummy_test ],
938 expect => { really_quiet => 1 },
950 { name => 'Switch -m',
952 argv => [qw( one two three )],
954 switches => [ '-m', $dummy_test ],
955 expect => { merge => 1 },
968 { name => 'Switch --merge',
970 argv => [qw( one two three )],
972 switches => [ '--merge', $dummy_test ],
973 expect => { merge => 1 },
986 { name => 'Switch --directives',
988 argv => [qw( one two three )],
990 switches => [ '--directives', $dummy_test ],
991 expect => { directives => 1 },
1004 # Executing one word (why would it be a -s though?)
1005 { name => 'Switch --exec -s',
1007 argv => [qw( one two three )],
1009 switches => [ '--exec', '-s', $dummy_test ],
1010 expect => { exec => '-s' },
1024 { name => 'Switch --exec "/foo/bar/perl -Ilib"',
1026 argv => [qw( one two three )],
1028 switches => [ '--exec', '/foo/bar/perl -Ilib', $dummy_test ],
1029 expect => { exec => '/foo/bar/perl -Ilib' },
1032 { exec => [qw(/foo/bar/perl -Ilib)],
1042 # null exec (run tests as compiled binaries)
1043 { name => 'Switch --exec ""',
1044 switches => [ '--exec', '', $dummy_test ],
1046 exec => # ick, must workaround the || default bit with a sub
1047 sub { my $val = shift; defined($val) and !length($val) }
1062 { name => 'Load plugin',
1063 switches => [ '-P', 'Dummy', $dummy_test ],
1065 argv => [qw( one two three )],
1068 plugins => ['Dummy'],
1071 my @loaded = get_import_log();
1072 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1087 { name => 'Load plugin (args)',
1088 switches => [ '-P', 'Dummy=cracking,cheese,gromit', $dummy_test ],
1090 argv => [qw( one two three )],
1093 plugins => ['Dummy'],
1096 my @loaded = get_import_log();
1098 [ [ 'App::Prove::Plugin::Dummy', 'cracking', 'cheese',
1116 { name => 'Load plugin (explicit path)',
1117 switches => [ '-P', 'App::Prove::Plugin::Dummy', $dummy_test ],
1119 argv => [qw( one two three )],
1122 plugins => ['Dummy'],
1125 my @loaded = get_import_log();
1126 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1141 { name => 'Load module',
1142 switches => [ '-M', 'App::Prove::Plugin::Dummy', $dummy_test ],
1144 argv => [qw( one two three )],
1147 plugins => ['Dummy'],
1150 my @loaded = get_import_log();
1151 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1167 # Hmm, that doesn't work...
1168 # { name => 'Switch -h',
1170 # argv => [qw( one two three )],
1172 # switches => [ '-h', $dummy_test ],
1183 # { name => 'Switch --help',
1185 # argv => [qw( one two three )],
1187 # switches => [ '--help', $dummy_test ],
1196 # { name => 'Switch -?',
1198 # argv => [qw( one two three )],
1200 # switches => [ '-?', $dummy_test ],
1210 # { name => 'Switch -H',
1212 # argv => [qw( one two three )],
1214 # switches => [ '-H', $dummy_test ],
1224 # { name => 'Switch --man',
1226 # argv => [qw( one two three )],
1228 # switches => [ '--man', $dummy_test ],
1238 # { name => 'Switch -V',
1240 # argv => [qw( one two three )],
1242 # switches => [ '-V', $dummy_test ],
1252 # { name => 'Switch --version',
1254 # argv => [qw( one two three )],
1256 # switches => [ '--version', $dummy_test ],
1266 # { name => 'Switch --color!',
1268 # argv => [qw( one two three )],
1270 # switches => [ '--color!', $dummy_test ],
1280 { name => 'Switch -I=s@',
1282 argv => [qw( one two three )],
1284 switches => [ '-Ilib', $dummy_test ],
1287 my ( $val, $attr ) = @_;
1291 && $val->[0] =~ /lib$/;
1296 # { name => 'Switch -a',
1298 # argv => [qw( one two three )],
1300 # switches => [ '-a', $dummy_test ],
1310 # { name => 'Switch --archive=-s',
1312 # argv => [qw( one two three )],
1314 # switches => [ '--archive=-s', $dummy_test ],
1324 # { name => 'Switch --formatter=-s',
1326 # argv => [qw( one two three )],
1328 # switches => [ '--formatter=-s', $dummy_test ],
1338 # { name => 'Switch -e',
1340 # argv => [qw( one two three )],
1342 # switches => [ '-e', $dummy_test ],
1352 # { name => 'Switch --harness=-s',
1354 # argv => [qw( one two three )],
1356 # switches => [ '--harness=-s', $dummy_test ],
1369 ########################################################################
1372 for my $test (@SCHEDULE) {
1373 $extra_plan += $test->{plan} || 0;
1374 $extra_plan += 2 if $test->{runlog};
1375 $extra_plan += 1 if $test->{switches};
1378 plan tests => @SCHEDULE * ( 3 + @ATTR ) + $extra_plan;
1382 for my $test (@SCHEDULE) {
1383 my $name = $test->{name};
1384 my $class = $test->{class} || 'FakeProve';
1386 local $ENV{HARNESS_TIMER};
1388 ok my $app = $class->new( exists $test->{args} ? $test->{args} : () ),
1389 "$name: App::Prove created OK";
1391 isa_ok $app, 'App::Prove';
1392 isa_ok $app, $class;
1394 # Optionally parse command args
1395 if ( my $switches = $test->{switches} ) {
1396 eval { $app->process_args( '--norc', @$switches ) };
1397 if ( my $err_pattern = $test->{parse_error} ) {
1398 like $@, $err_pattern, "$name: expected parse error";
1401 ok !$@, "$name: no parse error";
1405 my $expect = $test->{expect} || {};
1406 for my $attr ( sort @ATTR ) {
1407 my $val = $app->$attr();
1408 my $assertion = $expect->{$attr} || $DEFAULT_ASSERTION{$attr};
1411 if ( 'CODE' eq ref $assertion ) {
1412 $is_ok = ok $assertion->( $val, $attr ),
1413 "$name: $attr has the expected value";
1415 elsif ( 'Regexp' eq ref $assertion ) {
1416 $is_ok = like $val, $assertion, "$name: $attr matches $assertion";
1419 $is_ok = is_deeply $val, $assertion,
1420 "$name: $attr has the expected value";
1424 diag "got $val for $attr";
1428 if ( my $runlog = $test->{runlog} ) {
1430 if ( my $err_pattern = $test->{run_error} ) {
1431 like $@, $err_pattern, "$name: expected error OK";
1433 pass for 1 .. $test->{plan};
1436 unless ( ok !$@, "$name: no error OK" ) {
1437 diag "$name: error: $@\n";
1440 my $gotlog = [ $app->get_log ];
1442 if ( my $extra = $test->{extra} ) {
1447 is_deeply $gotlog, $runlog,
1448 "$name: run results match"
1452 diag Dumper( { wanted => $runlog, got => $gotlog } );