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