Re: Perl 5.7.2 Has Been Released
[p5sagit/p5-mst-13.2.git] / ext / POSIX / 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              errno);
15 use strict subs;
16
17 $| = 1;
18 print "1..29\n";
19
20 $Is_W32 = $^O eq 'MSWin32';
21 $Is_NetWare = $^O eq 'NetWare';
22 $Is_Dos = $^O eq 'dos';
23 $Is_MPE = $^O eq 'mpeix';
24
25 $testfd = open("TEST", O_RDONLY, 0) and print "ok 1\n";
26 read($testfd, $buffer, 9) if $testfd > 2;
27 print $buffer eq "#!./perl\n" ? "ok 2\n" : "not ok 2\n";
28
29 write(1,"ok 3\nnot ok 3\n", 5);
30
31 if ($Is_Dos) {
32     for (4..5) {
33         print "ok $_ # skipped, no pipe() support on dos\n";
34     }
35 } else {
36 @fds = POSIX::pipe();
37 print $fds[0] > $testfd ? "ok 4\n" : "not ok 4\n";
38 CORE::open($reader = \*READER, "<&=".$fds[0]);
39 CORE::open($writer = \*WRITER, ">&=".$fds[1]);
40 print $writer "ok 5\n";
41 close $writer;
42 print <$reader>;
43 close $reader;
44 }
45
46 if ($Is_W32 || $Is_Dos) {
47     for (6..11) {
48         print "ok $_ # skipped, no sigaction support on win32/dos\n";
49     }
50 }
51 else {
52 $sigset = new POSIX::SigSet 1,3;
53 delset $sigset 1;
54 if (!ismember $sigset 1) { print "ok 6\n" }
55 if (ismember $sigset 3) { print "ok 7\n" }
56 $mask = new POSIX::SigSet &SIGINT;
57 $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
58 sigaction(&SIGHUP, $action);
59 $SIG{'INT'} = 'SigINT';
60 kill 'HUP', $$;
61 sleep 1;
62 print "ok 11\n";
63
64 sub SigHUP {
65     print "ok 8\n";
66     kill 'INT', $$;
67     sleep 2;
68     print "ok 9\n";
69 }
70
71 sub SigINT {
72     print "ok 10\n";
73 }
74 }
75
76 if ($Is_MPE) {
77     print "ok 12 # skipped, _POSIX_OPEN_MAX is inaccurate on MPE\n"
78 } else {
79     print &_POSIX_OPEN_MAX > $fds[1] ? "ok 12\n" : "not ok 12\n"
80 }
81
82 print getcwd() =~ m#[/\\]t$# ? "ok 13\n" : "not ok 13\n";
83
84 # Check string conversion functions.
85
86 if ($Config{d_strtod}) {
87     $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
88     ($n, $x) = &POSIX::strtod('3.14159_OR_SO');
89 # we're just checking that strtod works, not how accurate it is
90     print ((abs("3.14159" - $n) < 1e-6) && ($x == 6) ?
91           "ok 14\n" : "not ok 14\n");
92     &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
93 } else { print "# strtod not present\n", "ok 14\n"; }
94
95 if ($Config{d_strtol}) {
96     ($n, $x) = &POSIX::strtol('21_PENGUINS');
97     print (($n == 21) && ($x == 9) ? "ok 15\n" : "not ok 15\n");
98 } else { print "# strtol not present\n", "ok 15\n"; }
99
100 if ($Config{d_strtoul}) {
101     ($n, $x) = &POSIX::strtoul('88_TEARS');
102     print (($n == 88) && ($x == 6) ? "ok 16\n" : "not ok 16\n");
103 } else { print "# strtoul not present\n", "ok 16\n"; }
104
105 # Pick up whether we're really able to dynamically load everything.
106 print &POSIX::acos(1.0) == 0.0 ? "ok 17\n" : "not ok 17\n";
107
108 # This can coredump if struct tm has a timezone field and we
109 # didn't detect it.  If this fails, try adding
110 # -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
111 # See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl 
112 print POSIX::strftime("ok 18 # %H:%M, on %D\n", localtime());
113
114 # If that worked, validate the mini_mktime() routine's normalisation of
115 # input fields to strftime().
116 sub try_strftime {
117     my $num = shift;
118     my $expect = shift;
119     my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_);
120     if ($got eq $expect) {
121         print "ok $num\n";
122     }
123     else {
124         print "# expected: $expect\n# got: $got\nnot ok $num\n";
125     }
126 }
127
128 $lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale};
129 try_strftime(19, "Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96);
130 try_strftime(20, "Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96);
131 try_strftime(21, "Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96);
132 try_strftime(22, "Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99);
133 try_strftime(23, "Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99);
134 try_strftime(24, "Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100);
135 try_strftime(25, "Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100);
136 try_strftime(26, "Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
137 try_strftime(27, "Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
138 &POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
139
140 {
141     for my $test (0, 1) {
142         $! = 0;
143         # POSIX::errno is autoloaded. 
144         # Autoloading requires many system calls.
145         # errno() looks at $! to generate its result.
146         # Autoloading should not munge the value.
147         my $foo  = $!;
148         my $errno = POSIX::errno();
149         print "not " unless $errno == $foo;
150         print "ok ", 28 + $test, "\n";
151     }
152 }
153
154 $| = 0;
155 # The following line assumes buffered output, which may be not true with EMX:
156 print '@#!*$@(!@#$' unless ($^O eq 'os2' || $^O eq 'uwin' || $^O eq 'os390' ||
157                             (defined $ENV{PERLIO} &&
158                              $ENV{PERLIO} eq 'unix' &&
159                              $Config::Config{useperlio}));
160 _exit(0);