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 $IsMacPerl = $^O eq 'MacOS';
24 my $IsVMS = $^O eq 'VMS';
26 # VMS uses native, not POSIX, exit codes.
27 my $die_exit = $IsVMS ? 44 : 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
208 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 5
226 details => [ { 'ok' => 1, actual_ok => 1 },
227 { 'ok' => 0, actual_ok => 0 },
228 { 'ok' => 1, actual_ok => 1 },
229 { 'ok' => 1, actual_ok => 1 },
230 { 'ok' => 0, actual_ok => 0 },
248 details => [ { 'ok' => 1, actual_ok => 1 },
249 { 'ok' => 1, actual_ok => 1,
251 reason => 'rain delay',
253 ({ 'ok' => 1, actual_ok => 1 }) x 3
271 details => [ { 'ok' => 1, actual_ok => 1,
328 details => [ { 'ok' => 1, actual_ok => 1 },
329 { 'ok' => 1, actual_ok => 1,
331 { 'ok' => 1, actual_ok => 0,
333 ({ 'ok' => 1, actual_ok => 1 }) x 2
350 details => [ { 'ok' => 1, actual_ok => 1,
351 name => '- -T honored'
369 details => [ { 'ok' => 0, actual_ok => 0 },
370 { 'ok' => 1, actual_ok => 1 },
377 'wait' => $wait_non_zero,
394 'wait' => $wait_non_zero,
404 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 4
412 'wait' => $wait_non_zero,
422 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 4
440 details => [ { 'ok' => 1, actual_ok => 1 },
441 { 'ok' => 1, actual_ok => 1 },
445 'shbang_misparse' =>{
459 details => [ ({ 'ok' => 1, actual_ok => 1 }) x 2 ]
463 plan tests => (keys(%samples) * 4) + 3;
465 use_ok('Test::Harness::Straps');
467 $SIG{__WARN__} = sub {
468 warn @_ unless $_[0] =~ /^Enormous test number/ ||
469 $_[0] =~ /^Can't detailize/
471 while( my($test, $expect) = each %samples ) {
472 for (0..$#{$expect->{details}}) {
473 $expect->{details}[$_]{type} = ''
474 unless exists $expect->{details}[$_]{type};
475 $expect->{details}[$_]{name} = ''
476 unless exists $expect->{details}[$_]{name};
477 $expect->{details}[$_]{reason} = ''
478 unless exists $expect->{details}[$_]{reason};
481 my $test_path = File::Spec->catfile($SAMPLE_TESTS, $test);
482 my $strap = Test::Harness::Straps->new;
483 my %results = $strap->analyze_file($test_path);
485 is_deeply($results{details}, $expect->{details}, "$test details" );
487 delete $expect->{details};
488 delete $results{details};
491 skip '$? unreliable in MacPerl', 2 if $IsMacPerl;
493 # We can only check if it's zero or non-zero.
494 is( !!$results{'wait'}, !!$expect->{'wait'}, 'wait status' );
495 delete $results{'wait'};
496 delete $expect->{'wait'};
498 # Have to check the exit status seperately so we can skip it
500 is( $results{'exit'}, $expect->{'exit'} );
501 delete $results{'exit'};
502 delete $expect->{'exit'};
505 is_deeply(\%results, $expect, " the rest $test" );
509 my $strap = Test::Harness::Straps->new;
510 ok( !$strap->analyze_file('I_dont_exist') );
511 is( $strap->{error}, "I_dont_exist does not exist" );