Integrate macperl patch #16868.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / exit.t
CommitLineData
4dd974da 1# Can't use Test.pm, that's a 5.005 thing.
2package My::Test;
3
a9153838 4BEGIN {
5 if( $ENV{PERL_CORE} ) {
6 chdir 't';
7 @INC = '../lib';
8 }
9}
10
33459055 11unless( eval { require File::Spec } ) {
12 print "1..0 # Skip Need File::Spec to run this test\n";
a9153838 13 exit 0;
14}
15
16if( $^O eq 'VMS' && $] <= 5.00503 ) {
17 print "1..0 # Skip test will hang on older VMS perls\n";
18 exit 0;
33459055 19}
0cd946aa 20
e69a2255 21if( $^O eq 'MacOS' ) {
22 print "1..0 # Skip exit status broken on Mac OS\n";
23 exit 0;
24}
25
4dd974da 26my $test_num = 1;
27# Utility testing functions.
28sub ok ($;$) {
29 my($test, $name) = @_;
11ea77c5 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;
4dd974da 36 $test_num++;
37}
38
39
40package main;
41
d020a79a 42my $IsVMS = $^O eq 'VMS';
43
44print "# Ahh! I see you're running VMS.\n" if $IsVMS;
45
4dd974da 46my %Tests = (
d020a79a 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],
4dd974da 58 );
59
60print "1..".keys(%Tests)."\n";
61
89c1e84a 62eval { require POSIX; &POSIX::WEXITSTATUS(0) };
63if( $@ ) {
64 *exitstatus = sub { $_[0] >> 8 };
65}
66else {
67 *exitstatus = sub { POSIX::WEXITSTATUS($_[0]) }
68}
69
a9153838 70chdir 't';
0cd946aa 71my $lib = File::Spec->catdir(qw(lib Test Simple sample_tests));
d020a79a 72while( my($test_name, $exit_codes) = each %Tests ) {
73 my($exit_code) = $exit_codes->[$IsVMS ? 1 : 0];
12b8e1e4 74
a9153838 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
15db8fc4 86 my $file = File::Spec->catfile($lib, $test_name);
a9153838 87 my $wait_stat = system(qq{$Perl -"I../blib/lib" -"I../lib" -"I../t/lib" $file});
89c1e84a 88 my $actual_exit = exitstatus($wait_stat);
12b8e1e4 89
d020a79a 90 My::Test::ok( $actual_exit == $exit_code,
91 "$test_name exited with $actual_exit (expected $exit_code)");
92}