Re: new exit tests on VMS
[p5sagit/p5-mst-13.2.git] / t / run / exit.t
1 #!./perl
2 #
3 # Tests for perl exit codes, playing with $?, etc...
4
5
6 BEGIN {
7     chdir 't' if -d 't';
8     @INC = '../lib';
9 }
10
11 # VMS and Windows need -e "...", most everything else works better with '
12 my $quote = $^O =~ /^(VMS|MSWin\d+)$/ ? q{"} : q{'};
13
14 # Run some code, return its wait status.
15 sub run {
16     my($code) = shift;
17     my $cmd = "$^X -e ";
18     return system($cmd.$quote.$code.$quote);
19 }
20
21 ## can't use this in 'use Test::More' yet
22 ##my $numtests = ($^O eq 'VMS') ? 7 : 3; 
23
24 use Test::More tests => 'no_plan';
25
26 my $exit, $exit_arg;
27
28 $exit = run('exit');
29 is( $exit >> 8, 0,              'Normal exit' );
30
31 if ($^O ne 'VMS') {
32
33   $exit = run('exit 42');
34   is( $exit >> 8, 42,             'Non-zero exit' );
35
36 } else {
37
38 # On VMS, successful returns from system() are always 0, warnings are 1,
39 # errors are 2, and fatal errors are 4.
40
41   $exit = run("exit 196609"); # %CLI-S-NORMAL
42   is( $exit >> 8, 0,             'success exit' );
43
44   $exit = run("exit 196611");  # %CLI-I-NORMAL
45   is( $exit >> 8, 0,             'informational exit' );
46
47   $exit = run("exit 196608");  # %CLI-W-NORMAL
48   is( $exit >> 8, 1,             'warning exit' );
49
50   $exit = run("exit 196610");  # %CLI-E-NORMAL
51   is( $exit >> 8, 2,             'error exit' );
52
53   $exit = run("exit 196612");  # %CLI-F-NORMAL
54   is( $exit >> 8, 4,             'fatal error exit' );
55 }
56
57 $exit = run('END { $? = 42 }');
58 is( $exit >> 8, 42,             'Changing $? in END block' );