1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!./perl -w
#
# Verify that C<die> return the return code
# -- Robin Barker
#
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
}
use strict;
$| = 1;
my @tests = (
[ 0, 0],
[ 0, 1],
[ 0, 127],
[ 0, 128],
[ 0, 255],
[ 0, 256],
[ 0, 512],
[ 1, 0],
[ 1, 1],
[ 1, 256],
[ 128, 0],
[ 128, 1],
[ 128, 256],
[ 255, 0],
[ 255, 1],
[ 255, 256],
# see if implicit close preserves $?
[ 0, 512, '{ local *F; open F, q[TEST]; close F; $!=0 } die;'],
);
plan(tests => scalar @tests);
my $vms_exit_mode = 0;
if ($^O eq 'VMS') {
if (eval 'require VMS::Feature') {
$vms_exit_mode = !(VMS::Feature::current("posix_exit"));
} else {
my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || '';
my $env_posix_ex = $ENV{'PERL_VMS_POSIX_EXIT'} || '';
my $unix_rpt = $env_unix_rpt =~ /^[ET1]/i;
my $posix_ex = $env_posix_ex =~ /^[ET1]/i;
if (($unix_rpt || $posix_ex) ) {
$vms_exit_mode = 0;
} else {
$vms_exit_mode = 1;
}
}
}
# Dump any error messages from the dying processes off to a temp file.
my $tempfile = tempfile();
open STDERR, '>', $tempfile or die "Can't open temp error file $tempfile: $!";
foreach my $test (@tests) {
my($bang, $query, $code) = @$test;
$code ||= 'die;';
if ($^O eq 'MSWin32' || $^O eq 'NetWare' || $^O eq 'VMS') {
system(qq{$^X -e "\$! = $bang; \$? = $query; $code"});
}
else {
system(qq{$^X -e '\$! = $bang; \$? = $query; $code'});
}
my $exit = $?;
# The legacy VMS exit code 44 (SS$_ABORT) is returned if a program dies.
# We only get the severity bits, which boils down to 4. See L<perlvms/$?>.
$bang = 4 if $vms_exit_mode;
is($exit, (($bang || ($query >> 8) || 255) << 8),
sprintf "exit = 0x%04x bang = 0x%04x query = 0x%04x", $exit, $bang, $query);
}
close STDERR;
|