This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The fudge factor is no more needed. I hope.
[perl5.git] / t / lib / posix.t
CommitLineData
a0d0e21e
LW
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
a0d0e21e 6 require Config; import Config;
fa6b8193 7 if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
c764b42b 8 print "1..0\n";
a0d0e21e
LW
9 exit 0;
10 }
11}
c07a80fd 12
84ef74c4 13use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write);
a0d0e21e
LW
14use strict subs;
15
c07a80fd 16$| = 1;
d0e85dce 17print "1..27\n";
a0d0e21e 18
6dead956 19$Is_W32 = $^O eq 'MSWin32';
6bbf1b34 20$Is_Dos = $^O eq 'dos';
6dead956 21
c07a80fd 22$testfd = open("TEST", O_RDONLY, 0) and print "ok 1\n";
a0d0e21e 23read($testfd, $buffer, 9) if $testfd > 2;
c07a80fd
PP
24print $buffer eq "#!./perl\n" ? "ok 2\n" : "not ok 2\n";
25
26write(1,"ok 3\nnot ok 3\n", 5);
a0d0e21e 27
6bbf1b34 28if ($Is_Dos) {
29 for (4..5) {
30 print "ok $_ # skipped, no pipe() support on dos\n";
31 }
32} else {
a0d0e21e 33@fds = POSIX::pipe();
c07a80fd
PP
34print $fds[0] > $testfd ? "ok 4\n" : "not ok 4\n";
35CORE::open($reader = \*READER, "<&=".$fds[0]);
36CORE::open($writer = \*WRITER, ">&=".$fds[1]);
37print $writer "ok 5\n";
a0d0e21e
LW
38close $writer;
39print <$reader>;
40close $reader;
6bbf1b34 41}
a0d0e21e 42
6bbf1b34 43if ($Is_W32 || $Is_Dos) {
6dead956 44 for (6..11) {
6bbf1b34 45 print "ok $_ # skipped, no sigaction support on win32/dos\n";
6dead956
GS
46 }
47}
48else {
a0d0e21e
LW
49$sigset = new POSIX::SigSet 1,3;
50delset $sigset 1;
c07a80fd
PP
51if (!ismember $sigset 1) { print "ok 6\n" }
52if (ismember $sigset 3) { print "ok 7\n" }
a0d0e21e
LW
53$mask = new POSIX::SigSet &SIGINT;
54$action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
55sigaction(&SIGHUP, $action);
56$SIG{'INT'} = 'SigINT';
57kill 'HUP', $$;
58sleep 1;
c07a80fd 59print "ok 11\n";
a0d0e21e
LW
60
61sub SigHUP {
c07a80fd 62 print "ok 8\n";
a0d0e21e
LW
63 kill 'INT', $$;
64 sleep 2;
0b3d46e6 65 print "ok 9\n";
a0d0e21e
LW
66}
67
68sub SigINT {
0b3d46e6 69 print "ok 10\n";
a0d0e21e 70}
6dead956 71}
a0d0e21e 72
c07a80fd 73print &_POSIX_OPEN_MAX > $fds[1] ? "ok 12\n" : "not ok 12\n";
a0d0e21e 74
c07a80fd 75print getcwd() =~ m#/t$# ? "ok 13\n" : "not ok 13\n";
a0d0e21e 76
a89d8a78
DH
77# Check string conversion functions.
78
79if ($Config{d_strtod}) {
ff68c719 80 $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
a89d8a78 81 ($n, $x) = &POSIX::strtod('3.14159_OR_SO');
fc68435e 82# Using long double NVs may introduce greater accuracy than wanted.
58a9a5d5 83 $n =~ s/^3.1415(8999|9000)\d*$/3.14159/
fc68435e 84 if $Config{uselongdouble} eq 'define';
7dd955c9 85 print (($n == 3.14159) && ($x == 6) ?
56dd5b29 86 "ok 14\n" : "not ok 14\n");
ff68c719 87 &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
a89d8a78
DH
88} else { print "# strtod not present\n", "ok 14\n"; }
89
90if ($Config{d_strtol}) {
91 ($n, $x) = &POSIX::strtol('21_PENGUINS');
92 print (($n == 21) && ($x == 9) ? "ok 15\n" : "not ok 15\n");
93} else { print "# strtol not present\n", "ok 15\n"; }
94
95if ($Config{d_strtoul}) {
96 ($n, $x) = &POSIX::strtoul('88_TEARS');
97 print (($n == 88) && ($x == 6) ? "ok 16\n" : "not ok 16\n");
98} else { print "# strtoul not present\n", "ok 16\n"; }
99
a0d0e21e 100# Pick up whether we're really able to dynamically load everything.
a89d8a78 101print &POSIX::acos(1.0) == 0.0 ? "ok 17\n" : "not ok 17\n";
a0d0e21e 102
84ef74c4
AD
103# This can coredump if struct tm has a timezone field and we
104# didn't detect it. If this fails, try adding
105# -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
106# See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl
107print POSIX::strftime("ok 18 # %H:%M, on %D\n", localtime());
108
33c0e3ec
SB
109# If that worked, validate the mini_mktime() routine's normalisation of
110# input fields to strftime().
111sub try_strftime {
112 my $num = shift;
113 my $expect = shift;
114 my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_);
115 if ($got eq $expect) {
116 print "ok $num\n";
117 }
118 else {
119 print "# expected: $expect\n# got: $got\nnot ok $num\n";
120 }
121}
122
123$lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale};
124try_strftime(19, "Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96);
125try_strftime(20, "Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96);
126try_strftime(21, "Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96);
127try_strftime(22, "Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99);
128try_strftime(23, "Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99);
129try_strftime(24, "Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100);
130try_strftime(25, "Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100);
131try_strftime(26, "Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
d0e85dce 132try_strftime(27, "Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
33c0e3ec
SB
133&POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
134
c07a80fd 135$| = 0;
ec40c0cd 136# The following line assumes buffered output, which may be not true with EMX:
8fde188e 137print '@#!*$@(!@#$' unless ($^O eq 'os2' || $^O eq 'uwin' || $^O eq 'os390');
a0d0e21e 138_exit(0);