Integrate macperl patch #16868.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / exit.t
1 # Can't use Test.pm, that's a 5.005 thing.
2 package My::Test;
3
4 BEGIN {
5     if( $ENV{PERL_CORE} ) {
6         chdir 't';
7         @INC = '../lib';
8     }
9 }
10
11 unless( eval { require File::Spec } ) {
12     print "1..0 # Skip Need File::Spec to run this test\n";
13     exit 0;
14 }
15
16 if( $^O eq 'VMS' && $] <= 5.00503 ) {
17     print "1..0 # Skip test will hang on older VMS perls\n";
18     exit 0;
19 }
20
21 if( $^O eq 'MacOS' ) {
22     print "1..0 # Skip exit status broken on Mac OS\n";
23     exit 0;
24 }
25
26 my $test_num = 1;
27 # Utility testing functions.
28 sub ok ($;$) {
29     my($test, $name) = @_;
30     my $ok = '';
31     $ok .= "not " unless $test;
32     $ok .= "ok $test_num";
33     $ok .= " - $name" if defined $name;
34     $ok .= "\n";
35     print $ok;
36     $test_num++;
37 }
38
39
40 package main;
41
42 my $IsVMS = $^O eq 'VMS';
43
44 print "# Ahh!  I see you're running VMS.\n" if $IsVMS;
45
46 my %Tests = (
47              #                      Everyone Else   VMS
48              'success.plx'              => [0,      0],
49              'one_fail.plx'             => [1,      4],
50              'two_fail.plx'             => [2,      4],
51              'five_fail.plx'            => [5,      4],
52              'extras.plx'               => [3,      4],
53              'too_few.plx'              => [4,      4],
54              'death.plx'                => [255,    4],
55              'last_minute_death.plx'    => [255,    4],
56              'death_in_eval.plx'        => [0,      0],
57              'require.plx'              => [0,      0],
58             );
59
60 print "1..".keys(%Tests)."\n";
61
62 eval { require POSIX; &POSIX::WEXITSTATUS(0) };
63 if( $@ ) {
64     *exitstatus = sub { $_[0] >> 8 };
65 }
66 else {
67     *exitstatus = sub { POSIX::WEXITSTATUS($_[0]) }
68 }
69
70 chdir 't';
71 my $lib = File::Spec->catdir(qw(lib Test Simple sample_tests));
72 while( my($test_name, $exit_codes) = each %Tests ) {
73     my($exit_code) = $exit_codes->[$IsVMS ? 1 : 0];
74
75     my $Perl = $^X;
76
77     if( $^O eq 'VMS' ) {
78         # VMS can't use its own $^X in a system call until almost 5.8
79         $Perl = "MCR $^X" if $] < 5.007003;
80
81         # Quiet noisy 'SYS$ABORT'.  'hushed' only exists in 5.6 and up,
82         # but it doesn't do any harm on eariler perls.
83         $Perl .= q{ -"Mvmsish=hushed"};
84     }
85
86     my $file = File::Spec->catfile($lib, $test_name);
87     my $wait_stat = system(qq{$Perl -"I../blib/lib" -"I../lib" -"I../t/lib" $file});
88     my $actual_exit = exitstatus($wait_stat);
89
90     My::Test::ok( $actual_exit == $exit_code, 
91                   "$test_name exited with $actual_exit (expected $exit_code)");
92 }