4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib');
17 my $Curdir = File::Spec->curdir;
18 my $SAMPLE_TESTS = $ENV{PERL_CORE}
19 ? File::Spec->catdir($Curdir, 'lib', 'sample-tests')
20 : File::Spec->catdir($Curdir, 't', 'sample-tests');
23 my $IsMacOS = $^O eq 'MacOS';
24 my $IsVMS = $^O eq 'VMS';
26 # VMS uses native, not POSIX, exit codes.
27 my $die_exit = $IsVMS ? 44 : $IsMacOS ? 0 : 1;
29 # We can only predict that the wait status should be zero or not.
30 my $wait_non_zero = 1;
47 details => [ { 'ok' => 1, actual_ok => 1 },
48 { 'ok' => 1, actual_ok => 1,
49 name => 'basset hounds got long ears',
51 { 'ok' => 0, actual_ok => 0,
52 name => 'all hell broke lose',
54 { 'ok' => 1, actual_ok => 1,
57 { 'ok' => 1, actual_ok => 1 },
58 { 'ok' => 1, actual_ok => 1 },
59 { 'ok' => 1, actual_ok => 1,
61 reason => 'contract negociations'
63 { 'ok' => 1, actual_ok => 1 },
64 { 'ok' => 0, actual_ok => 0 },
65 { 'ok' => 1, actual_ok => 0,
85 details => [ { 'ok' => 1, actual_ok => 1,
86 name => 'Interlock activated'
88 { 'ok' => 1, actual_ok => 1,
89 name => 'Megathrusters are go',
91 { 'ok' => 1, actual_ok => 1,
92 name => 'Head formed',
94 { 'ok' => 1, actual_ok => 1,
95 name => 'Blazing sword formed'
97 { 'ok' => 1, actual_ok => 1,
98 name => 'Robeast destroyed'
117 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 10
135 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 4
153 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 4
171 details => [ { 'ok' => 1, actual_ok => 1 },
172 { 'ok' => 0, actual_ok => 0 },
173 ({ 'ok'=> 1, actual_ok => 1 }) x 2
191 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 5
209 details => [ { 'ok' => 1, actual_ok => 1 },
210 { 'ok' => 0, actual_ok => 0 },
211 { 'ok' => 1, actual_ok => 1 },
212 { 'ok' => 1, actual_ok => 1 },
213 { 'ok' => 0, actual_ok => 0 },
231 details => [ { 'ok' => 1, actual_ok => 1 },
232 { 'ok' => 1, actual_ok => 1,
234 reason => 'rain delay',
236 ({ 'ok' => 1, actual_ok => 1 }) x 3
254 details => [ { 'ok' => 1, actual_ok => 1,
310 details => [ { 'ok' => 1, actual_ok => 1 },
311 { 'ok' => 1, actual_ok => 1,
313 { 'ok' => 1, actual_ok => 0,
315 ({ 'ok' => 1, actual_ok => 1 }) x 2
332 details => [ { 'ok' => 1, actual_ok => 1,
333 name => '- -T honored'
351 details => [ { 'ok' => 0, actual_ok => 0 },
352 { 'ok' => 1, actual_ok => 1 },
359 'wait' => $wait_non_zero,
376 'wait' => $wait_non_zero,
386 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 4
394 'wait' => $wait_non_zero,
404 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 4
422 details => [ { 'ok' => 1, actual_ok => 1 },
423 { 'ok' => 1, actual_ok => 1 },
427 'shbang_misparse' =>{
441 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 2 ]
445 plan tests => (keys(%samples) * 4) + 3;
447 use_ok('Test::Harness::Straps');
449 $SIG{__WARN__} = sub {
450 warn @_ unless $_[0] =~ /^Enormous test number/ ||
451 $_[0] =~ /^Can't detailize/
453 while( my($test, $expect) = each %samples ) {
454 for (0..$#{$expect->{details}}) {
455 $expect->{details}[$_]{type} = ''
456 unless exists $expect->{details}[$_]{type};
457 $expect->{details}[$_]{name} = ''
458 unless exists $expect->{details}[$_]{name};
459 $expect->{details}[$_]{reason} = ''
460 unless exists $expect->{details}[$_]{reason};
463 my $test_path = File::Spec->catfile($SAMPLE_TESTS, $test);
464 my $strap = Test::Harness::Straps->new;
465 my %results = $strap->analyze_file($test_path);
467 is_deeply($results{details}, $expect->{details}, "$test details" );
469 delete $expect->{details};
470 delete $results{details};
473 skip '$? unreliable in MacPerl', 2 if $IsMacOS;
475 # We can only check if it's zero or non-zero.
476 is( !!$results{'wait'}, !!$expect->{'wait'}, 'wait status' );
477 delete $results{'wait'};
478 delete $expect->{'wait'};
480 # Have to check the exit status seperately so we can skip it
482 is( $results{'exit'}, $expect->{'exit'} );
483 delete $results{'exit'};
484 delete $expect->{'exit'};
487 is_deeply(\%results, $expect, " the rest $test" );
491 my $strap = Test::Harness::Straps->new;
492 ok( !$strap->analyze_file('I_dont_exist') );
493 is( $strap->{error}, "I_dont_exist does not exist" );