4 if ( $ENV{PERL_CORE} ) {
6 @INC = ( '../lib', '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 failures formatter harness
79 includes lib merge parse quiet really_quiet recurse backwards
80 shuffle taint_fail taint_warn verbose warnings_fail warnings_warn
83 # what we expect if the 'expect' hash does not define it
84 %DEFAULT_ASSERTION = map { $_ => undef } @ATTR;
86 $DEFAULT_ASSERTION{includes} = $DEFAULT_ASSERTION{argv}
87 = sub { 'ARRAY' eq ref shift };
89 my @dummy_tests = map { File::Spec->catdir( 't', 'sample-tests', $_ ) }
90 qw(simple simple_yaml);
91 my $dummy_test = $dummy_tests[0];
93 ########################################################################
94 # declarations - this drives all of the subtests.
95 # The cheatsheet follows.
96 # required: name, expect
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
106 { name => 'Create empty',
109 { name => 'Set all options via constructor',
112 argv => [qw(one two three)],
120 includes => [qw(four five six)],
137 argv => [qw(one two three)],
145 includes => [qw(four five six)],
161 { name => 'Call with defaults',
162 args => { argv => [qw( one two three )] },
175 # Test all options individually
177 # { name => 'Just archive',
179 # argv => [qw( one two three )],
194 { name => 'Just argv',
196 argv => [qw( one two three )],
199 argv => [qw( one two three )],
210 { name => 'Just blib',
212 argv => [qw( one two three )],
220 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
224 'one', 'two', 'three'
229 { name => 'Just color',
231 argv => [qw( one two three )],
243 'one', 'two', 'three'
248 { name => 'Just directives',
250 argv => [qw( one two three )],
262 'one', 'two', 'three'
266 { name => 'Just exec',
268 argv => [qw( one two three )],
280 'one', 'two', 'three'
284 { name => 'Just failures',
286 argv => [qw( one two three )],
298 'one', 'two', 'three'
303 { name => 'Just formatter',
305 argv => [qw( one two three )],
306 formatter => 'TAP::Harness',
309 formatter => 'TAP::Harness',
313 { formatter_class => 'TAP::Harness',
317 'one', 'two', 'three'
322 { name => 'Just includes',
324 argv => [qw( one two three )],
325 includes => [qw( four five six )],
328 includes => [qw( four five six )],
332 { lib => mabs( [qw( four five six )] ),
336 'one', 'two', 'three'
340 { name => 'Just lib',
342 argv => [qw( one two three )],
350 { lib => mabs( ['lib'] ),
354 'one', 'two', 'three'
358 { name => 'Just merge',
360 argv => [qw( one two three )],
372 'one', 'two', 'three'
376 { name => 'Just parse',
378 argv => [qw( one two three )],
390 'one', 'two', 'three'
394 { name => 'Just quiet',
396 argv => [qw( one two three )],
407 'one', 'two', 'three'
411 { name => 'Just really_quiet',
413 argv => [qw( one two three )],
424 'one', 'two', 'three'
428 { name => 'Just recurse',
430 argv => [qw( one two three )],
440 'one', 'two', 'three'
444 { name => 'Just reverse',
446 argv => [qw( one two three )],
456 'three', 'two', 'one'
461 { name => 'Just shuffle',
463 argv => [qw( one two three )],
478 { name => 'Just taint_fail',
480 argv => [qw( one two three )],
488 { switches => ['-T'],
492 'one', 'two', 'three'
496 { name => 'Just taint_warn',
498 argv => [qw( one two three )],
506 { switches => ['-t'],
510 'one', 'two', 'three'
514 { name => 'Just verbose',
516 argv => [qw( one two three )],
527 'one', 'two', 'three'
531 { name => 'Just warnings_fail',
533 argv => [qw( one two three )],
541 { switches => ['-W'],
545 'one', 'two', 'three'
549 { name => 'Just warnings_warn',
551 argv => [qw( one two three )],
559 { switches => ['-w'],
563 'one', 'two', 'three'
568 # Command line parsing
569 { name => 'Switch -v',
571 argv => [qw( one two three )],
573 switches => [ '-v', $dummy_test ],
587 { name => 'Switch --verbose',
589 argv => [qw( one two three )],
591 switches => [ '--verbose', $dummy_test ],
605 { name => 'Switch -f',
607 argv => [qw( one two three )],
609 switches => [ '-f', $dummy_test ],
610 expect => { failures => 1 },
622 { name => 'Switch --failures',
624 argv => [qw( one two three )],
626 switches => [ '--failures', $dummy_test ],
627 expect => { failures => 1 },
639 { name => 'Switch -l',
641 argv => [qw( one two three )],
643 switches => [ '-l', $dummy_test ],
644 expect => { lib => 1 },
647 { lib => mabs( ['lib'] ),
656 { name => 'Switch --lib',
658 argv => [qw( one two three )],
660 switches => [ '--lib', $dummy_test ],
661 expect => { lib => 1 },
664 { lib => mabs( ['lib'] ),
673 { name => 'Switch -b',
675 argv => [qw( one two three )],
677 switches => [ '-b', $dummy_test ],
678 expect => { blib => 1 },
681 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
690 { name => 'Switch --blib',
692 argv => [qw( one two three )],
694 switches => [ '--blib', $dummy_test ],
695 expect => { blib => 1 },
698 { lib => mabs( [ 'blib/lib', 'blib/arch' ] ),
707 { name => 'Switch -s',
709 argv => [qw( one two three )],
711 switches => [ '-s', $dummy_test ],
712 expect => { shuffle => 1 },
722 { name => 'Switch --shuffle',
724 argv => [qw( one two three )],
726 switches => [ '--shuffle', $dummy_test ],
727 expect => { shuffle => 1 },
737 { name => 'Switch -c',
739 argv => [qw( one two three )],
741 switches => [ '-c', $dummy_test ],
742 expect => { color => 1 },
754 { name => 'Switch -r',
756 argv => [qw( one two three )],
758 switches => [ '-r', $dummy_test ],
759 expect => { recurse => 1 },
769 { name => 'Switch --recurse',
771 argv => [qw( one two three )],
773 switches => [ '--recurse', $dummy_test ],
774 expect => { recurse => 1 },
784 { name => 'Switch --reverse',
786 argv => [qw( one two three )],
788 switches => [ '--reverse', @dummy_tests ],
789 expect => { backwards => 1 },
799 { name => 'Switch -p',
801 argv => [qw( one two three )],
803 switches => [ '-p', $dummy_test ],
818 { name => 'Switch --parse',
820 argv => [qw( one two three )],
822 switches => [ '--parse', $dummy_test ],
837 { name => 'Switch -q',
839 argv => [qw( one two three )],
841 switches => [ '-q', $dummy_test ],
842 expect => { quiet => 1 },
853 { name => 'Switch --quiet',
855 argv => [qw( one two three )],
857 switches => [ '--quiet', $dummy_test ],
858 expect => { quiet => 1 },
869 { name => 'Switch -Q',
871 argv => [qw( one two three )],
873 switches => [ '-Q', $dummy_test ],
874 expect => { really_quiet => 1 },
885 { name => 'Switch --QUIET',
887 argv => [qw( one two three )],
889 switches => [ '--QUIET', $dummy_test ],
890 expect => { really_quiet => 1 },
901 { name => 'Switch -m',
903 argv => [qw( one two three )],
905 switches => [ '-m', $dummy_test ],
906 expect => { merge => 1 },
918 { name => 'Switch --merge',
920 argv => [qw( one two three )],
922 switches => [ '--merge', $dummy_test ],
923 expect => { merge => 1 },
935 { name => 'Switch --directives',
937 argv => [qw( one two three )],
939 switches => [ '--directives', $dummy_test ],
940 expect => { directives => 1 },
952 # Executing one word (why would it be a -s though?)
953 { name => 'Switch --exec -s',
955 argv => [qw( one two three )],
957 switches => [ '--exec', '-s', $dummy_test ],
958 expect => { exec => '-s' },
960 [ '_runtests', { exec => ['-s'], verbosity => 0 },
968 { name => 'Switch --exec "/foo/bar/perl -Ilib"',
970 argv => [qw( one two three )],
972 switches => [ '--exec', '/foo/bar/perl -Ilib', $dummy_test ],
973 expect => { exec => '/foo/bar/perl -Ilib' },
976 { exec => [qw(/foo/bar/perl -Ilib)],
985 # null exec (run tests as compiled binaries)
986 { name => 'Switch --exec ""',
987 switches => [ '--exec', '', $dummy_test ],
989 exec => # ick, must workaround the || default bit with a sub
990 sub { my $val = shift; defined($val) and !length($val) }
994 { exec => [], verbosity => 0 },
1002 { name => 'Load plugin',
1003 switches => [ '-P', 'Dummy', $dummy_test ],
1005 argv => [qw( one two three )],
1008 plugins => ['Dummy'],
1011 my @loaded = get_import_log();
1012 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1025 { name => 'Load plugin (args)',
1026 switches => [ '-P', 'Dummy=cracking,cheese,gromit', $dummy_test ],
1028 argv => [qw( one two three )],
1031 plugins => ['Dummy'],
1034 my @loaded = get_import_log();
1036 [ [ 'App::Prove::Plugin::Dummy', 'cracking', 'cheese',
1052 { name => 'Load plugin (explicit path)',
1053 switches => [ '-P', 'App::Prove::Plugin::Dummy', $dummy_test ],
1055 argv => [qw( one two three )],
1058 plugins => ['Dummy'],
1061 my @loaded = get_import_log();
1062 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1075 { name => 'Load module',
1076 switches => [ '-M', 'App::Prove::Plugin::Dummy', $dummy_test ],
1078 argv => [qw( one two three )],
1081 plugins => ['Dummy'],
1084 my @loaded = get_import_log();
1085 is_deeply \@loaded, [ ['App::Prove::Plugin::Dummy'] ],
1099 # Hmm, that doesn't work...
1100 # { name => 'Switch -h',
1102 # argv => [qw( one two three )],
1104 # switches => [ '-h', $dummy_test ],
1115 # { name => 'Switch --help',
1117 # argv => [qw( one two three )],
1119 # switches => [ '--help', $dummy_test ],
1128 # { name => 'Switch -?',
1130 # argv => [qw( one two three )],
1132 # switches => [ '-?', $dummy_test ],
1142 # { name => 'Switch -H',
1144 # argv => [qw( one two three )],
1146 # switches => [ '-H', $dummy_test ],
1156 # { name => 'Switch --man',
1158 # argv => [qw( one two three )],
1160 # switches => [ '--man', $dummy_test ],
1170 # { name => 'Switch -V',
1172 # argv => [qw( one two three )],
1174 # switches => [ '-V', $dummy_test ],
1184 # { name => 'Switch --version',
1186 # argv => [qw( one two three )],
1188 # switches => [ '--version', $dummy_test ],
1198 # { name => 'Switch --color!',
1200 # argv => [qw( one two three )],
1202 # switches => [ '--color!', $dummy_test ],
1212 { name => 'Switch -I=s@',
1214 argv => [qw( one two three )],
1216 switches => [ '-Ilib', $dummy_test ],
1219 my ( $val, $attr ) = @_;
1223 && $val->[0] =~ /lib$/;
1228 # { name => 'Switch -a',
1230 # argv => [qw( one two three )],
1232 # switches => [ '-a', $dummy_test ],
1242 # { name => 'Switch --archive=-s',
1244 # argv => [qw( one two three )],
1246 # switches => [ '--archive=-s', $dummy_test ],
1256 # { name => 'Switch --formatter=-s',
1258 # argv => [qw( one two three )],
1260 # switches => [ '--formatter=-s', $dummy_test ],
1270 # { name => 'Switch -e',
1272 # argv => [qw( one two three )],
1274 # switches => [ '-e', $dummy_test ],
1284 # { name => 'Switch --harness=-s',
1286 # argv => [qw( one two three )],
1288 # switches => [ '--harness=-s', $dummy_test ],
1301 ########################################################################
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};
1310 plan tests => @SCHEDULE * ( 3 + @ATTR ) + $extra_plan;
1314 for my $test (@SCHEDULE) {
1315 my $name = $test->{name};
1316 my $class = $test->{class} || 'FakeProve';
1318 ok my $app = $class->new( exists $test->{args} ? $test->{args} : () ),
1319 "$name: App::Prove created OK";
1321 isa_ok $app, 'App::Prove';
1322 isa_ok $app, $class;
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";
1331 ok !$@, "$name: no parse error";
1335 my $expect = $test->{expect} || {};
1336 for my $attr ( sort @ATTR ) {
1337 my $val = $app->$attr();
1338 my $assertion = $expect->{$attr} || $DEFAULT_ASSERTION{$attr};
1341 if ( 'CODE' eq ref $assertion ) {
1342 $is_ok = ok $assertion->( $val, $attr ),
1343 "$name: $attr has the expected value";
1345 elsif ( 'Regexp' eq ref $assertion ) {
1346 $is_ok = like $val, $assertion, "$name: $attr matches $assertion";
1349 $is_ok = is_deeply $val, $assertion,
1350 "$name: $attr has the expected value";
1354 diag "got $val for $attr";
1358 if ( my $runlog = $test->{runlog} ) {
1360 if ( my $err_pattern = $test->{run_error} ) {
1361 like $@, $err_pattern, "$name: expected error OK";
1363 pass for 1 .. $test->{plan};
1366 unless ( ok !$@, "$name: no error OK" ) {
1367 diag "$name: error: $@\n";
1370 my $gotlog = [ $app->get_log ];
1372 if ( my $extra = $test->{extra} ) {
1377 is_deeply $gotlog, $runlog,
1378 "$name: run results match"
1382 diag Dumper( { wanted => $runlog, got => $gotlog } );