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