[PATCH] Syncing with Test::Simple 0.19
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / exit.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4 }
5
6 # Can't use Test.pm, that's a 5.005 thing.
7 package My::Test;
8
9 use File::Spec;
10
11 my $test_num = 1;
12 # Utility testing functions.
13 sub ok ($;$) {
14     my($test, $name) = @_;
15     my $ok = '';
16     $ok .= "not " unless $test;
17     $ok .= "ok $test_num";
18     $ok .= " - $name" if defined $name;
19     $ok .= "\n";
20     print $ok;
21     $test_num++;
22 }
23
24
25 package main;
26
27 my $IsVMS = $^O eq 'VMS';
28
29 print "# Ahh!  I see you're running VMS.\n" if $IsVMS;
30
31 my %Tests = (
32              #                      Everyone Else   VMS
33              'success.plx'              => [0,      0],
34              'one_fail.plx'             => [1,      4],
35              'two_fail.plx'             => [2,      4],
36              'five_fail.plx'            => [5,      4],
37              'extras.plx'               => [3,      4],
38              'too_few.plx'              => [4,      4],
39              'death.plx'                => [255,    4],
40              'last_minute_death.plx'    => [255,    4],
41              'death_in_eval.plx'        => [0,      0],
42              'require.plx'              => [0,      0],
43             );
44
45 print "1..".keys(%Tests)."\n";
46
47 my $lib = File::Spec->catdir(qw(lib Test Simple sample_tests));
48 while( my($test_name, $exit_codes) = each %Tests ) {
49     my($exit_code) = $exit_codes->[$IsVMS ? 1 : 0];
50
51     my $file = File::Spec->catfile($lib, $test_name);
52     my $wait_stat = system(qq{$^X -"I../lib" -"I../t/lib" $file});
53     my $actual_exit = $wait_stat >> 8;
54
55     My::Test::ok( $actual_exit == $exit_code, 
56                   "$test_name exited with $actual_exit (expected $exit_code)");
57 }