Test::Simple/More/Builder 0.42 -> 0.44
[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 my $test_num = 1;
22 # Utility testing functions.
23 sub ok ($;$) {
24     my($test, $name) = @_;
25     my $ok = '';
26     $ok .= "not " unless $test;
27     $ok .= "ok $test_num";
28     $ok .= " - $name" if defined $name;
29     $ok .= "\n";
30     print $ok;
31     $test_num++;
32 }
33
34
35 package main;
36
37 my $IsVMS = $^O eq 'VMS';
38
39 print "# Ahh!  I see you're running VMS.\n" if $IsVMS;
40
41 my %Tests = (
42              #                      Everyone Else   VMS
43              'success.plx'              => [0,      0],
44              'one_fail.plx'             => [1,      4],
45              'two_fail.plx'             => [2,      4],
46              'five_fail.plx'            => [5,      4],
47              'extras.plx'               => [3,      4],
48              'too_few.plx'              => [4,      4],
49              'death.plx'                => [255,    4],
50              'last_minute_death.plx'    => [255,    4],
51              'death_in_eval.plx'        => [0,      0],
52              'require.plx'              => [0,      0],
53             );
54
55 print "1..".keys(%Tests)."\n";
56
57 eval { require POSIX; &POSIX::WEXITSTATUS(0) };
58 if( $@ ) {
59     *exitstatus = sub { $_[0] >> 8 };
60 }
61 else {
62     *exitstatus = sub { POSIX::WEXITSTATUS($_[0]) }
63 }
64
65 chdir 't';
66 my $lib = File::Spec->catdir(qw(lib Test Simple sample_tests));
67 while( my($test_name, $exit_codes) = each %Tests ) {
68     my($exit_code) = $exit_codes->[$IsVMS ? 1 : 0];
69
70     my $Perl = $^X;
71
72     if( $^O eq 'VMS' ) {
73         # VMS can't use its own $^X in a system call until almost 5.8
74         $Perl = "MCR $^X" if $] < 5.007003;
75
76         # Quiet noisy 'SYS$ABORT'.  'hushed' only exists in 5.6 and up,
77         # but it doesn't do any harm on eariler perls.
78         $Perl .= q{ -"Mvmsish=hushed"};
79     }
80
81     my $file = File::Spec->catfile($lib, $test_name);
82     my $wait_stat = system(qq{$Perl -"I../blib/lib" -"I../lib" -"I../t/lib" $file});
83     my $actual_exit = exitstatus($wait_stat);
84
85     My::Test::ok( $actual_exit == $exit_code, 
86                   "$test_name exited with $actual_exit (expected $exit_code)");
87 }