vmsish fix, ieee rand() cleanup
[p5sagit/p5-mst-13.2.git] / vms / ext / vmsish.t
CommitLineData
68dc0745 1
2BEGIN { unshift @INC, '[-.lib]'; }
3
4my $Invoke_Perl = qq(MCR $^X "-I[-.lib]");
5
96e176bf 6require "test.pl";
7plan(tests => 24);
68dc0745 8
9#========== vmsish status ==========
10`$Invoke_Perl -e 1`; # Avoid system() from a pipe from harness. Mutter.
96e176bf 11is($?,0,"simple Perl invokation: POSIX success status");
68dc0745 12{
13 use vmsish qw(status);
96e176bf 14 is(($? & 1),1, "importing vmsish [vmsish status]");
68dc0745 15 {
96e176bf 16 no vmsish qw(status); # check unimport function
17 is($?,0, "unimport vmsish [POSIX STATUS]");
68dc0745 18 }
19 # and lexical scoping
96e176bf 20 is(($? & 1),1,"lex scope of vmsish [vmsish status]");
68dc0745 21}
96e176bf 22is($?,0,"outer lex scope of vmsish [POSIX status]");
23
68dc0745 24{
25 use vmsish qw(exit); # check import function
96e176bf 26 is($?,0,"importing vmsish exit [POSIX status]");
68dc0745 27}
28
925fd5a3 29#========== vmsish exit, messages ==========
68dc0745 30{
31 use vmsish qw(status);
925fd5a3 32
33 $msg = do_a_perl('-e "exit 1"');
68dc0745 34 $msg =~ s/\n/\\n/g; # keep output on one line
96e176bf 35 like($msg,'ABORT', "POSIX ERR exit, DCL error message check");
36 is($?&1,0,"vmsish status check, POSIX ERR exit");
68dc0745 37
925fd5a3 38 $msg = do_a_perl('-e "use vmsish qw(exit); exit 1"');
68dc0745 39 $msg =~ s/\n/\\n/g; # keep output on one line
96e176bf 40 ok(length($msg)==0,"vmsish OK exit, DCL error message check");
41 is($?&1,1, "vmsish status check, vmsish OK exit");
68dc0745 42
925fd5a3 43 $msg = do_a_perl('-e "use vmsish qw(exit); exit 44"');
68dc0745 44 $msg =~ s/\n/\\n/g; # keep output on one line
96e176bf 45 like($msg, 'ABORT', "vmsish ERR exit, DCL error message check");
46 is($?&1,0,"vmsish ERR exit, vmsish status check");
47
48 $msg = do_a_perl('-e "use vmsish qw(hushed); exit 1"');
49 $msg =~ s/\n/\\n/g; # keep output on one line
50 ok(($msg !~ /ABORT/),"POSIX ERR exit, vmsish hushed, DCL error message check");
925fd5a3 51
52 $msg = do_a_perl('-e "use vmsish qw(exit hushed); exit 44"');
925fd5a3 53 $msg =~ s/\n/\\n/g; # keep output on one line
96e176bf 54 ok(($msg !~ /ABORT/),"vmsish ERR exit, vmsish hushed, DCL error message check");
55
56 $msg = do_a_perl('-e "use vmsish qw(exit hushed); no vmsish qw(hushed); exit 44"');
57 $msg =~ s/\n/\\n/g; # keep output on one line
58 like($msg,'ABORT',"vmsish ERR exit, no vmsish hushed, DCL error message check");
59
60 $msg = do_a_perl('-e "use vmsish qw(hushed); die(qw(blah));"');
61 $msg =~ s/\n/\\n/g; # keep output on one line
62 ok(($msg !~ /ABORT/),"die, vmsish hushed, DCL error message check");
63
64 $msg = do_a_perl('-e "use vmsish qw(hushed); use Carp; croak(qw(blah));"');
65 $msg =~ s/\n/\\n/g; # keep output on one line
66 ok(($msg !~ /ABORT/),"croak, vmsish hushed, DCL error message check");
67
68 $msg = do_a_perl('-e "use vmsish qw(exit); vmsish::hushed(1); exit 44;"');
69 $msg =~ s/\n/\\n/g; # keep output on one line
70 ok(($msg !~ /ABORT/),"vmsish ERR exit, vmsish hushed at runtime, DCL error message check");
71
72 local *TEST;
73 open(TEST,'>vmsish_test.pl') || die('not ok ?? : unable to open "vmsish_test.pl" for writing');
74 print TEST "#! perl\n";
75 print TEST "use vmsish qw(hushed);\n";
76 print TEST "\$obvious = (\$compile(\$error;\n";
77 close TEST;
78 $msg = do_a_perl('vmsish_test.pl');
79 $msg =~ s/\n/\\n/g; # keep output on one line
80 ok(($msg !~ /ABORT/),"compile ERR exit, vmsish hushed, DCL error message check");
81 unlink 'vmsish_test.pl';
68dc0745 82}
83
84
85#========== vmsish time ==========
86{
87 my($utctime, @utclocal, @utcgmtime, $utcmtime,
88 $vmstime, @vmslocal, @vmsgmtime, $vmsmtime,
89 $utcval, $vmaval, $offset);
90 # Make sure apparent local time isn't GMT
91 if (not $ENV{'SYS$TIMEZONE_DIFFERENTIAL'}) {
92 $oldtz = $ENV{'SYS$TIMEZONE_DIFFERENTIAL'};
93 $ENV{'SYS$TIMEZONE_DIFFERENTIAL'} = 3600;
94 eval "END { \$ENV{'SYS\$TIMEZONE_DIFFERENTIAL'} = $oldtz; }";
95 gmtime(0); # Force reset of tz offset
96 }
97 {
96e176bf 98 use_ok('vmsish qw(time)');
68dc0745 99 $vmstime = time;
100 @vmslocal = localtime($vmstime);
101 @vmsgmtime = gmtime($vmstime);
102 $vmsmtime = (stat $0)[9];
103 }
104 $utctime = time;
105 @utclocal = localtime($vmstime);
106 @utcgmtime = gmtime($vmstime);
107 $utcmtime = (stat $0)[9];
108
109 $offset = $ENV{'SYS$TIMEZONE_DIFFERENTIAL'};
110
111 # We allow lots of leeway (10 sec) difference for these tests,
112 # since it's unlikely local time will differ from UTC by so small
113 # an amount, and it renders the test resistant to delays from
114 # things like stat() on a file mounted over a slow network link.
96e176bf 115 ok($utctime - $vmstime +$offset <= 10,"(time) UTC:$utctime VMS:$vmstime");
68dc0745 116
117 $utcval = $utclocal[5] * 31536000 + $utclocal[7] * 86400 +
118 $utclocal[2] * 3600 + $utclocal[1] * 60 + $utclocal[0];
119 $vmsval = $vmslocal[5] * 31536000 + $vmslocal[7] * 86400 +
120 $vmslocal[2] * 3600 + $vmslocal[1] * 60 + $vmslocal[0];
96e176bf 121 ok($vmsval - $utcval + $offset <= 10, "(localtime)\n# UTC: @utclocal\n# VMS: @vmslocal");
68dc0745 122
123 $utcval = $utcgmtime[5] * 31536000 + $utcgmtime[7] * 86400 +
124 $utcgmtime[2] * 3600 + $utcgmtime[1] * 60 + $utcgmtime[0];
125 $vmsval = $vmsgmtime[5] * 31536000 + $vmsgmtime[7] * 86400 +
126 $vmsgmtime[2] * 3600 + $vmsgmtime[1] * 60 + $vmsgmtime[0];
96e176bf 127 ok($vmsval - $utcval + $offset <= 10, "(gmtime)\n# UTC: @utcgmtime\n# VMS: @vmsgmtime");
68dc0745 128
96e176bf 129 ok($vmsmtime - $utcmtime + $offset <= 10,"(stat) UTC: $utcmtime VMS: $vmsmtime");
925fd5a3 130}
131
132#====== need this to make sure error messages come out, even if
133# they were turned off in invoking procedure
134sub do_a_perl {
135 local *P;
136 open(P,'>vmsish_test.com') || die('not ok ?? : unable to open "vmsish_test.com" for writing');
137 print P "\$ set message/facil/sever/ident/text\n";
399b8151 138 print P "\$ define/nolog/user sys\$error _nla0:\n";
925fd5a3 139 print P "\$ $Invoke_Perl @_\n";
140 close P;
141 my $x = `\@vmsish_test.com`;
142 unlink 'vmsish_test.com';
143 return $x;
68dc0745 144}
925fd5a3 145