Commit | Line | Data |
a0d0e21e |
1 | #!./perl |
2 | |
3 | BEGIN { |
a0d0e21e |
4 | require Config; import Config; |
fa6b8193 |
5 | if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) { |
c764b42b |
6 | print "1..0\n"; |
a0d0e21e |
7 | exit 0; |
8 | } |
9 | } |
c07a80fd |
10 | |
2adbc9b6 |
11 | BEGIN { require "../../t/test.pl"; } |
2ae48df0 |
12 | plan(tests => 66); |
e6c299c8 |
13 | |
212caf55 |
14 | use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write |
15 | errno); |
e6c299c8 |
16 | use strict 'subs'; |
a0d0e21e |
17 | |
c07a80fd |
18 | $| = 1; |
a0d0e21e |
19 | |
e6c299c8 |
20 | $Is_W32 = $^O eq 'MSWin32'; |
21 | $Is_Dos = $^O eq 'dos'; |
22 | $Is_MPE = $^O eq 'mpeix'; |
23 | $Is_MacOS = $^O eq 'MacOS'; |
24 | $Is_VMS = $^O eq 'VMS'; |
25 | $Is_OS2 = $^O eq 'os2'; |
26 | $Is_UWin = $^O eq 'uwin'; |
27 | $Is_OS390 = $^O eq 'os390'; |
6dead956 |
28 | |
6a164b5b |
29 | my $vms_unix_rpt = 0; |
30 | my $vms_efs = 0; |
31 | my $unix_mode = 1; |
32 | |
33 | if ($Is_VMS) { |
34 | $unix_mode = 0; |
35 | if (eval 'require VMS::Feature') { |
36 | $vms_unix_rpt = VMS::Feature::current("filename_unix_report"); |
37 | $vms_efs = VMS::Feature::current("efs_charset"); |
38 | } else { |
39 | my $unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; |
40 | my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || ''; |
41 | $vms_unix_rpt = $unix_rpt =~ /^[ET1]/i; |
42 | $vms_efs = $efs_charset =~ /^[ET1]/i; |
43 | } |
44 | |
45 | # Traditional VMS mode only if VMS is not in UNIX compatible mode. |
46 | $unix_mode = ($vms_efs && $vms_unix_rpt); |
47 | |
48 | } |
49 | |
50 | |
2adbc9b6 |
51 | ok( $testfd = open("Makefile.PL", O_RDONLY, 0), 'O_RDONLY with open' ); |
7814eec4 |
52 | read($testfd, $buffer, 4) if $testfd > 2; |
2adbc9b6 |
53 | is( $buffer, "# Ex", ' with read' ); |
c07a80fd |
54 | |
7814eec4 |
55 | TODO: |
56 | { |
57 | local $TODO = "read to array element not working"; |
58 | |
59 | read($testfd, $buffer[1], 5) if $testfd > 2; |
60 | is( $buffer[1], "perl\n", ' read to array element' ); |
61 | } |
62 | |
63 | write(1,"ok 4\nnot ok 4\n", 5); |
e6c299c8 |
64 | next_test(); |
65 | |
66 | SKIP: { |
67 | skip("no pipe() support on DOS", 2) if $Is_Dos; |
a0d0e21e |
68 | |
10de532f |
69 | @fds = POSIX::pipe(); |
e6c299c8 |
70 | ok( $fds[0] > $testfd, 'POSIX::pipe' ); |
71 | |
10de532f |
72 | CORE::open($reader = \*READER, "<&=".$fds[0]); |
73 | CORE::open($writer = \*WRITER, ">&=".$fds[1]); |
7814eec4 |
74 | print $writer "ok 6\n"; |
10de532f |
75 | close $writer; |
76 | print <$reader>; |
77 | close $reader; |
e6c299c8 |
78 | next_test(); |
6bbf1b34 |
79 | } |
a0d0e21e |
80 | |
e6c299c8 |
81 | SKIP: { |
82 | skip("no sigaction support on win32/dos", 6) if $Is_W32 || $Is_Dos; |
83 | |
84 | my $sigset = new POSIX::SigSet 1, 3; |
85 | $sigset->delset(1); |
86 | ok(! $sigset->ismember(1), 'POSIX::SigSet->delset' ); |
87 | ok( $sigset->ismember(3), 'POSIX::SigSet->ismember' ); |
be4e88b6 |
88 | |
e6c299c8 |
89 | SKIP: { |
90 | skip("no kill() support on Mac OS", 4) if $Is_MacOS; |
91 | |
be4e88b6 |
92 | my $sigint_called = 0; |
93 | |
e6c299c8 |
94 | my $mask = new POSIX::SigSet &SIGINT; |
95 | my $action = new POSIX::SigAction 'main::SigHUP', $mask, 0; |
10de532f |
96 | sigaction(&SIGHUP, $action); |
97 | $SIG{'INT'} = 'SigINT'; |
7eb03357 |
98 | |
99 | # At least OpenBSD/i386 3.3 is okay, as is NetBSD 1.5. |
100 | # But not NetBSD 1.6 & 1.6.1: the test makes perl crash. |
101 | # So the kill() must not be done with this config in order to |
102 | # finish the test. |
103 | # For others (darwin & freebsd), let the test fail without crashing. |
104 | my $todo = $^O eq 'netbsd' && $Config{osvers}=~/^1\.6/; |
e6b15316 |
105 | my $why_todo = "# TODO $^O $Config{osvers} seems to lose blocked signals"; |
22f20764 |
106 | if (!$todo) { |
107 | kill 'HUP', $$; |
108 | } else { |
109 | print "not ok 9 - sigaction SIGHUP ",$why_todo,"\n"; |
110 | print "not ok 10 - sig mask delayed SIGINT ",$why_todo,"\n"; |
111 | } |
10de532f |
112 | sleep 1; |
be4e88b6 |
113 | |
7eb03357 |
114 | $todo = 1 if ($^O eq 'freebsd') |
115 | || ($^O eq 'darwin' && $Config{osvers} lt '6.6'); |
22f20764 |
116 | printf "%s 11 - masked SIGINT received %s\n", |
7eb03357 |
117 | $sigint_called ? "ok" : "not ok", |
22f20764 |
118 | $todo ? $why_todo : ''; |
be4e88b6 |
119 | |
7814eec4 |
120 | print "ok 12 - signal masks successful\n"; |
10de532f |
121 | |
122 | sub SigHUP { |
7814eec4 |
123 | print "ok 9 - sigaction SIGHUP\n"; |
10de532f |
124 | kill 'INT', $$; |
125 | sleep 2; |
7814eec4 |
126 | print "ok 10 - sig mask delayed SIGINT\n"; |
10de532f |
127 | } |
128 | |
129 | sub SigINT { |
be4e88b6 |
130 | $sigint_called++; |
10de532f |
131 | } |
e6c299c8 |
132 | |
133 | # The order of the above tests is very important, so |
134 | # we use literal prints and hard coded numbers. |
135 | next_test() for 1..4; |
d536870a |
136 | } |
6dead956 |
137 | } |
a0d0e21e |
138 | |
e6c299c8 |
139 | SKIP: { |
140 | skip("_POSIX_OPEN_MAX is inaccurate on MPE", 1) if $Is_MPE; |
141 | skip("_POSIX_OPEN_MAX undefined ($fds[1])", 1) unless &_POSIX_OPEN_MAX; |
142 | |
e85e3e79 |
143 | ok( &_POSIX_OPEN_MAX >= 16, "The minimum allowed values according to susv2" ); |
4e0f6e8c |
144 | |
c9ff6e92 |
145 | } |
a0d0e21e |
146 | |
d536870a |
147 | my $pat; |
2adbc9b6 |
148 | if ( $unix_mode ) { |
149 | $pat = qr#[\\/]POSIX$#i; |
e6c299c8 |
150 | } |
151 | else { |
2adbc9b6 |
152 | $pat = qr/\.POSIX]/i; |
d536870a |
153 | } |
e6c299c8 |
154 | like( getcwd(), qr/$pat/, 'getcwd' ); |
a0d0e21e |
155 | |
a89d8a78 |
156 | # Check string conversion functions. |
157 | |
e6c299c8 |
158 | SKIP: { |
159 | skip("strtod() not present", 1) unless $Config{d_strtod}; |
160 | |
ff68c719 |
161 | $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale}; |
e6c299c8 |
162 | |
163 | # we're just checking that strtod works, not how accurate it is |
a89d8a78 |
164 | ($n, $x) = &POSIX::strtod('3.14159_OR_SO'); |
e6c299c8 |
165 | ok((abs("3.14159" - $n) < 1e-6) && ($x == 6), 'strtod works'); |
166 | |
ff68c719 |
167 | &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale}; |
e6c299c8 |
168 | } |
169 | |
170 | SKIP: { |
171 | skip("strtol() not present", 2) unless $Config{d_strtol}; |
a89d8a78 |
172 | |
a89d8a78 |
173 | ($n, $x) = &POSIX::strtol('21_PENGUINS'); |
e6c299c8 |
174 | is($n, 21, 'strtol() number'); |
175 | is($x, 9, ' unparsed chars'); |
176 | } |
177 | |
178 | SKIP: { |
179 | skip("strtoul() not present", 2) unless $Config{d_strtoul}; |
a89d8a78 |
180 | |
a89d8a78 |
181 | ($n, $x) = &POSIX::strtoul('88_TEARS'); |
e6c299c8 |
182 | is($n, 88, 'strtoul() number'); |
183 | is($x, 6, ' unparsed chars'); |
184 | } |
a89d8a78 |
185 | |
a0d0e21e |
186 | # Pick up whether we're really able to dynamically load everything. |
e6c299c8 |
187 | ok( &POSIX::acos(1.0) == 0.0, 'dynamic loading' ); |
a0d0e21e |
188 | |
84ef74c4 |
189 | # This can coredump if struct tm has a timezone field and we |
190 | # didn't detect it. If this fails, try adding |
191 | # -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c. |
192 | # See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl |
abbe0d1a |
193 | print POSIX::strftime("ok 21 # %H:%M, on %m/%d/%y\n", localtime()); |
e6c299c8 |
194 | next_test(); |
84ef74c4 |
195 | |
33c0e3ec |
196 | # If that worked, validate the mini_mktime() routine's normalisation of |
197 | # input fields to strftime(). |
198 | sub try_strftime { |
33c0e3ec |
199 | my $expect = shift; |
200 | my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_); |
61a515a6 |
201 | is($got, $expect, "validating mini_mktime() and strftime(): $expect"); |
33c0e3ec |
202 | } |
203 | |
204 | $lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale}; |
e6c299c8 |
205 | try_strftime("Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96); |
53059177 |
206 | SKIP: { |
abbe0d1a |
207 | skip("VC++ 8 and Vista's CRTs regard 60 seconds as an invalid parameter", 1) |
6fa15125 |
208 | if ($Is_W32 and (($Config{cc} eq 'cl' and |
abbe0d1a |
209 | $Config{ccversion} =~ /^(\d+)/ and $1 >= 14) or |
6fa15125 |
210 | (Win32::GetOSVersion())[1] >= 6)); |
53059177 |
211 | |
212 | try_strftime("Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96); |
213 | } |
e6c299c8 |
214 | try_strftime("Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96); |
215 | try_strftime("Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99); |
216 | try_strftime("Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99); |
217 | try_strftime("Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100); |
218 | try_strftime("Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100); |
219 | try_strftime("Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100); |
220 | try_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100); |
33c0e3ec |
221 | &POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale}; |
222 | |
212caf55 |
223 | { |
224 | for my $test (0, 1) { |
225 | $! = 0; |
226 | # POSIX::errno is autoloaded. |
227 | # Autoloading requires many system calls. |
228 | # errno() looks at $! to generate its result. |
229 | # Autoloading should not munge the value. |
230 | my $foo = $!; |
231 | my $errno = POSIX::errno(); |
e6c299c8 |
232 | |
e6c299c8 |
233 | # Force numeric context. |
234 | is( $errno + 0, $foo + 0, 'autoloading and errno() mix' ); |
212caf55 |
235 | } |
236 | } |
237 | |
d4742b2c |
238 | SKIP: { |
239 | skip("no kill() support on Mac OS", 1) if $Is_MacOS; |
240 | is (eval "kill 0", 0, "check we have CORE::kill") |
241 | or print "\$\@ is " . _qq($@) . "\n"; |
242 | } |
243 | |
244 | # Check that we can import the POSIX kill routine |
245 | POSIX->import ('kill'); |
246 | my $result = eval "kill 0"; |
247 | is ($result, undef, "we should now have POSIX::kill"); |
248 | # Check usage. |
249 | like ($@, qr/^Usage: POSIX::kill\(pid, sig\)/, "check its usage message"); |
250 | |
251 | # Check unimplemented. |
252 | $result = eval {POSIX::offsetof}; |
253 | is ($result, undef, "offsetof should fail"); |
254 | like ($@, qr/^Unimplemented: POSIX::offsetof\(\) is C-specific/, |
255 | "check its unimplemented message"); |
256 | |
257 | # Check reimplemented. |
258 | $result = eval {POSIX::fgets}; |
259 | is ($result, undef, "fgets should fail"); |
260 | like ($@, qr/^Use method IO::Handle::gets\(\) instead/, |
261 | "check its redef message"); |
262 | |
4b3c6531 |
263 | # Simplistic tests for the isXXX() functions (bug #16799) |
264 | ok( POSIX::isalnum('1'), 'isalnum' ); |
265 | ok(!POSIX::isalnum('*'), 'isalnum' ); |
266 | ok( POSIX::isalpha('f'), 'isalpha' ); |
267 | ok(!POSIX::isalpha('7'), 'isalpha' ); |
268 | ok( POSIX::iscntrl("\cA"),'iscntrl' ); |
269 | ok(!POSIX::iscntrl("A"), 'iscntrl' ); |
270 | ok( POSIX::isdigit('1'), 'isdigit' ); |
271 | ok(!POSIX::isdigit('z'), 'isdigit' ); |
272 | ok( POSIX::isgraph('@'), 'isgraph' ); |
273 | ok(!POSIX::isgraph(' '), 'isgraph' ); |
274 | ok( POSIX::islower('l'), 'islower' ); |
275 | ok(!POSIX::islower('L'), 'islower' ); |
276 | ok( POSIX::isupper('U'), 'isupper' ); |
277 | ok(!POSIX::isupper('u'), 'isupper' ); |
278 | ok( POSIX::isprint('$'), 'isprint' ); |
279 | ok(!POSIX::isprint("\n"), 'isprint' ); |
280 | ok( POSIX::ispunct('%'), 'ispunct' ); |
281 | ok(!POSIX::ispunct('u'), 'ispunct' ); |
282 | ok( POSIX::isspace("\t"), 'isspace' ); |
283 | ok(!POSIX::isspace('_'), 'isspace' ); |
284 | ok( POSIX::isxdigit('f'), 'isxdigit' ); |
285 | ok(!POSIX::isxdigit('g'), 'isxdigit' ); |
117206bb |
286 | # metaphysical question : what should be returned for an empty string ? |
287 | # anyway this shouldn't segfault (bug #24554) |
288 | ok( POSIX::isalnum(''), 'isalnum empty string' ); |
289 | ok( POSIX::isalnum(undef),'isalnum undef' ); |
767bb2e0 |
290 | # those functions should stringify their arguments |
291 | ok(!POSIX::isalpha([]), 'isalpha []' ); |
292 | ok( POSIX::isprint([]), 'isprint []' ); |
2ae48df0 |
293 | |
294 | eval { use strict; POSIX->import("S_ISBLK"); my $x = S_ISBLK }; |
295 | unlike( $@, qr/Can't use string .* as a symbol ref/, "Can import autoloaded constants" ); |
4b3c6531 |
296 | |
404d038e |
297 | # Check that output is not flushed by _exit. This test should be last |
298 | # in the file, and is not counted in the total number of tests. |
299 | if ($^O eq 'vos') { |
300 | print "# TODO - hit VOS bug posix-885 - _exit flushes output buffers.\n"; |
301 | } else { |
302 | $| = 0; |
303 | # The following line assumes buffered output, which may be not true: |
304 | print '@#!*$@(!@#$' unless ($Is_MacOS || $Is_OS2 || $Is_UWin || $Is_OS390 || |
e6c299c8 |
305 | $Is_VMS || |
601f2d16 |
306 | (defined $ENV{PERLIO} && |
307 | $ENV{PERLIO} eq 'unix' && |
308 | $Config::Config{useperlio})); |
404d038e |
309 | _exit(0); |
310 | } |