3 # Can't use Test.pm, that's a 5.005 thing.
7 if( $ENV{PERL_CORE} ) {
13 require Test::Builder;
14 my $TB = Test::Builder->create();
25 my $Perl = File::Spec->rel2abs($^X);
27 # VMS can't use its own $^X in a system call until almost 5.8
28 $Perl = "MCR $^X" if $] < 5.007003;
30 # Quiet noisy 'SYS$ABORT'
31 $Perl .= q{ -"I../lib"} if $ENV{PERL_CORE};
32 $Perl .= q{ -"Mvmsish=hushed"};
36 eval { require POSIX; &POSIX::WEXITSTATUS(0) };
38 *exitstatus = sub { $_[0] >> 8 };
41 *exitstatus = sub { POSIX::WEXITSTATUS($_[0]) }
45 # Some OS' will alter the exit code to their own native sense...
46 # sometimes. Rather than deal with the exception we'll just
47 # build up the mapping.
48 print "# Building up a map of exit codes. May take a while.\n";
51 open my $fh, ">", "exit_map_test" or die $!;
55 import vmsish qw(hushed);
63 END { 1 while unlink "exit_map_test" }
65 for my $exit (0..255) {
66 # This correctly emulates Test::Builder's behavior.
67 my $out = qx[$Perl exit_map_test $exit];
68 $TB->like( $out, qr/^exit $exit\n/, "exit map test for $exit" );
69 $Exit_Map{$exit} = exitstatus($?);
82 'too_few_fail.plx' => 2,
84 'last_minute_death.plx' => 255,
85 'pre_plan_death.plx' => 'not zero',
86 'death_in_eval.plx' => 0,
88 'death_with_handler.plx' => 255,
93 my $lib = File::Spec->catdir(qw(lib Test Simple sample_tests));
94 while( my($test_name, $exit_code) = each %Tests ) {
95 my $file = File::Spec->catfile($lib, $test_name);
96 my $wait_stat = system(qq{$Perl -"I../blib/lib" -"I../lib" -"I../t/lib" $file});
97 my $actual_exit = exitstatus($wait_stat);
99 if( $exit_code eq 'not zero' ) {
100 $TB->isnt_num( $actual_exit, $Exit_Map{0},
101 "$test_name exited with $actual_exit ".
102 "(expected non-zero)");
105 $TB->is_num( $actual_exit, $Exit_Map{$exit_code},
106 "$test_name exited with $actual_exit ".
107 "(expected $Exit_Map{$exit_code})");
111 $TB->done_testing( scalar keys(%Tests) + 256 );
113 # So any END block file cleanup works.