6 require Config; import Config;
7 if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
13 BEGIN { require "./test.pl"; }
16 use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write
22 $Is_W32 = $^O eq 'MSWin32';
23 $Is_Dos = $^O eq 'dos';
24 $Is_MPE = $^O eq 'mpeix';
25 $Is_MacOS = $^O eq 'MacOS';
26 $Is_VMS = $^O eq 'VMS';
27 $Is_OS2 = $^O eq 'os2';
28 $Is_UWin = $^O eq 'uwin';
29 $Is_OS390 = $^O eq 'os390';
31 ok( $testfd = open("TEST", O_RDONLY, 0), 'O_RDONLY with open' );
32 read($testfd, $buffer, 4) if $testfd > 2;
33 is( $buffer, "#!./", ' with read' );
37 local $TODO = "read to array element not working";
39 read($testfd, $buffer[1], 5) if $testfd > 2;
40 is( $buffer[1], "perl\n", ' read to array element' );
43 write(1,"ok 4\nnot ok 4\n", 5);
47 skip("no pipe() support on DOS", 2) if $Is_Dos;
50 ok( $fds[0] > $testfd, 'POSIX::pipe' );
52 CORE::open($reader = \*READER, "<&=".$fds[0]);
53 CORE::open($writer = \*WRITER, ">&=".$fds[1]);
54 print $writer "ok 6\n";
62 skip("no sigaction support on win32/dos", 6) if $Is_W32 || $Is_Dos;
64 my $sigset = new POSIX::SigSet 1, 3;
66 ok(! $sigset->ismember(1), 'POSIX::SigSet->delset' );
67 ok( $sigset->ismember(3), 'POSIX::SigSet->ismember' );
70 skip("no kill() support on Mac OS", 4) if $Is_MacOS;
72 my $sigint_called = 0;
74 my $mask = new POSIX::SigSet &SIGINT;
75 my $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
76 sigaction(&SIGHUP, $action);
77 $SIG{'INT'} = 'SigINT';
79 # At least OpenBSD/i386 3.3 is okay, as is NetBSD 1.5.
80 # But not NetBSD 1.6 & 1.6.1: the test makes perl crash.
81 # So the kill() must not be done with this config in order to
83 # For others (darwin & freebsd), let the test fail without crashing.
84 my $todo = $^O eq 'netbsd' && $Config{osvers}=~/^1\.6/;
85 my $why_todo = "# TODO $^O $Config{osvers} seems to lose blocked signals";
89 print "not ok 9 - sigaction SIGHUP ",$why_todo,"\n";
90 print "not ok 10 - sig mask delayed SIGINT ",$why_todo,"\n";
94 $todo = 1 if ($^O eq 'freebsd')
95 || ($^O eq 'darwin' && $Config{osvers} lt '6.6');
96 printf "%s 11 - masked SIGINT received %s\n",
97 $sigint_called ? "ok" : "not ok",
98 $todo ? $why_todo : '';
100 print "ok 12 - signal masks successful\n";
103 print "ok 9 - sigaction SIGHUP\n";
106 print "ok 10 - sig mask delayed SIGINT\n";
113 # The order of the above tests is very important, so
114 # we use literal prints and hard coded numbers.
115 next_test() for 1..4;
120 skip("_POSIX_OPEN_MAX is inaccurate on MPE", 1) if $Is_MPE;
121 skip("_POSIX_OPEN_MAX undefined ($fds[1])", 1) unless &_POSIX_OPEN_MAX;
123 ok( &_POSIX_OPEN_MAX >= 16, "The minimum allowed values according to susv2" );
137 like( getcwd(), qr/$pat/, 'getcwd' );
139 # Check string conversion functions.
142 skip("strtod() not present", 1) unless $Config{d_strtod};
144 $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
146 # we're just checking that strtod works, not how accurate it is
147 ($n, $x) = &POSIX::strtod('3.14159_OR_SO');
148 ok((abs("3.14159" - $n) < 1e-6) && ($x == 6), 'strtod works');
150 &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
154 skip("strtol() not present", 2) unless $Config{d_strtol};
156 ($n, $x) = &POSIX::strtol('21_PENGUINS');
157 is($n, 21, 'strtol() number');
158 is($x, 9, ' unparsed chars');
162 skip("strtoul() not present", 2) unless $Config{d_strtoul};
164 ($n, $x) = &POSIX::strtoul('88_TEARS');
165 is($n, 88, 'strtoul() number');
166 is($x, 6, ' unparsed chars');
169 # Pick up whether we're really able to dynamically load everything.
170 ok( &POSIX::acos(1.0) == 0.0, 'dynamic loading' );
172 # This can coredump if struct tm has a timezone field and we
173 # didn't detect it. If this fails, try adding
174 # -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
175 # See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl
176 print POSIX::strftime("ok 21 # %H:%M, on %D\n", localtime());
179 # If that worked, validate the mini_mktime() routine's normalisation of
180 # input fields to strftime().
183 my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_);
184 is($got, $expect, "validating mini_mktime() and strftime(): $expect");
187 $lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale};
188 try_strftime("Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96);
190 skip("VC++ 8 regards 60 seconds as an invalid parameter", 1)
191 if $Config{cc} eq 'cl' and $Config{ccversion} =~ /^(\d+)/ and $1 >= 14;
193 try_strftime("Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96);
195 try_strftime("Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96);
196 try_strftime("Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99);
197 try_strftime("Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99);
198 try_strftime("Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100);
199 try_strftime("Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100);
200 try_strftime("Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100);
201 try_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100);
202 &POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale};
205 for my $test (0, 1) {
207 # POSIX::errno is autoloaded.
208 # Autoloading requires many system calls.
209 # errno() looks at $! to generate its result.
210 # Autoloading should not munge the value.
212 my $errno = POSIX::errno();
214 # Force numeric context.
215 is( $errno + 0, $foo + 0, 'autoloading and errno() mix' );
220 skip("no kill() support on Mac OS", 1) if $Is_MacOS;
221 is (eval "kill 0", 0, "check we have CORE::kill")
222 or print "\$\@ is " . _qq($@) . "\n";
225 # Check that we can import the POSIX kill routine
226 POSIX->import ('kill');
227 my $result = eval "kill 0";
228 is ($result, undef, "we should now have POSIX::kill");
230 like ($@, qr/^Usage: POSIX::kill\(pid, sig\)/, "check its usage message");
232 # Check unimplemented.
233 $result = eval {POSIX::offsetof};
234 is ($result, undef, "offsetof should fail");
235 like ($@, qr/^Unimplemented: POSIX::offsetof\(\) is C-specific/,
236 "check its unimplemented message");
238 # Check reimplemented.
239 $result = eval {POSIX::fgets};
240 is ($result, undef, "fgets should fail");
241 like ($@, qr/^Use method IO::Handle::gets\(\) instead/,
242 "check its redef message");
244 # Simplistic tests for the isXXX() functions (bug #16799)
245 ok( POSIX::isalnum('1'), 'isalnum' );
246 ok(!POSIX::isalnum('*'), 'isalnum' );
247 ok( POSIX::isalpha('f'), 'isalpha' );
248 ok(!POSIX::isalpha('7'), 'isalpha' );
249 ok( POSIX::iscntrl("\cA"),'iscntrl' );
250 ok(!POSIX::iscntrl("A"), 'iscntrl' );
251 ok( POSIX::isdigit('1'), 'isdigit' );
252 ok(!POSIX::isdigit('z'), 'isdigit' );
253 ok( POSIX::isgraph('@'), 'isgraph' );
254 ok(!POSIX::isgraph(' '), 'isgraph' );
255 ok( POSIX::islower('l'), 'islower' );
256 ok(!POSIX::islower('L'), 'islower' );
257 ok( POSIX::isupper('U'), 'isupper' );
258 ok(!POSIX::isupper('u'), 'isupper' );
259 ok( POSIX::isprint('$'), 'isprint' );
260 ok(!POSIX::isprint("\n"), 'isprint' );
261 ok( POSIX::ispunct('%'), 'ispunct' );
262 ok(!POSIX::ispunct('u'), 'ispunct' );
263 ok( POSIX::isspace("\t"), 'isspace' );
264 ok(!POSIX::isspace('_'), 'isspace' );
265 ok( POSIX::isxdigit('f'), 'isxdigit' );
266 ok(!POSIX::isxdigit('g'), 'isxdigit' );
267 # metaphysical question : what should be returned for an empty string ?
268 # anyway this shouldn't segfault (bug #24554)
269 ok( POSIX::isalnum(''), 'isalnum empty string' );
270 ok( POSIX::isalnum(undef),'isalnum undef' );
271 # those functions should stringify their arguments
272 ok(!POSIX::isalpha([]), 'isalpha []' );
273 ok( POSIX::isprint([]), 'isprint []' );
275 eval { use strict; POSIX->import("S_ISBLK"); my $x = S_ISBLK };
276 unlike( $@, qr/Can't use string .* as a symbol ref/, "Can import autoloaded constants" );
278 # Check that output is not flushed by _exit. This test should be last
279 # in the file, and is not counted in the total number of tests.
281 print "# TODO - hit VOS bug posix-885 - _exit flushes output buffers.\n";
284 # The following line assumes buffered output, which may be not true:
285 print '@#!*$@(!@#$' unless ($Is_MacOS || $Is_OS2 || $Is_UWin || $Is_OS390 ||
287 (defined $ENV{PERLIO} &&
288 $ENV{PERLIO} eq 'unix' &&
289 $Config::Config{useperlio}));