Commit | Line | Data |
a0d0e21e |
1 | #!./perl |
2 | |
3 | BEGIN { |
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 | |
e6c299c8 |
13 | require "./test.pl"; |
d4742b2c |
14 | plan(tests => 38); |
e6c299c8 |
15 | |
16 | |
212caf55 |
17 | use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write |
18 | errno); |
e6c299c8 |
19 | use strict 'subs'; |
a0d0e21e |
20 | |
c07a80fd |
21 | $| = 1; |
a0d0e21e |
22 | |
e6c299c8 |
23 | $Is_W32 = $^O eq 'MSWin32'; |
24 | $Is_Dos = $^O eq 'dos'; |
25 | $Is_MPE = $^O eq 'mpeix'; |
26 | $Is_MacOS = $^O eq 'MacOS'; |
27 | $Is_VMS = $^O eq 'VMS'; |
28 | $Is_OS2 = $^O eq 'os2'; |
29 | $Is_UWin = $^O eq 'uwin'; |
30 | $Is_OS390 = $^O eq 'os390'; |
6dead956 |
31 | |
e6c299c8 |
32 | ok( $testfd = open("TEST", O_RDONLY, 0), 'O_RDONLY with open' ); |
a0d0e21e |
33 | read($testfd, $buffer, 9) if $testfd > 2; |
e6c299c8 |
34 | is( $buffer, "#!./perl\n", ' with read' ); |
c07a80fd |
35 | |
36 | write(1,"ok 3\nnot ok 3\n", 5); |
e6c299c8 |
37 | next_test(); |
38 | |
39 | SKIP: { |
40 | skip("no pipe() support on DOS", 2) if $Is_Dos; |
a0d0e21e |
41 | |
10de532f |
42 | @fds = POSIX::pipe(); |
e6c299c8 |
43 | ok( $fds[0] > $testfd, 'POSIX::pipe' ); |
44 | |
10de532f |
45 | CORE::open($reader = \*READER, "<&=".$fds[0]); |
46 | CORE::open($writer = \*WRITER, ">&=".$fds[1]); |
47 | print $writer "ok 5\n"; |
48 | close $writer; |
49 | print <$reader>; |
50 | close $reader; |
e6c299c8 |
51 | next_test(); |
6bbf1b34 |
52 | } |
a0d0e21e |
53 | |
e6c299c8 |
54 | SKIP: { |
55 | skip("no sigaction support on win32/dos", 6) if $Is_W32 || $Is_Dos; |
56 | |
57 | my $sigset = new POSIX::SigSet 1, 3; |
58 | $sigset->delset(1); |
59 | ok(! $sigset->ismember(1), 'POSIX::SigSet->delset' ); |
60 | ok( $sigset->ismember(3), 'POSIX::SigSet->ismember' ); |
10de532f |
61 | |
e6c299c8 |
62 | SKIP: { |
63 | skip("no kill() support on Mac OS", 4) if $Is_MacOS; |
64 | |
65 | my $mask = new POSIX::SigSet &SIGINT; |
66 | my $action = new POSIX::SigAction 'main::SigHUP', $mask, 0; |
10de532f |
67 | sigaction(&SIGHUP, $action); |
68 | $SIG{'INT'} = 'SigINT'; |
69 | kill 'HUP', $$; |
70 | sleep 1; |
e6c299c8 |
71 | print "ok 11 - signal masks successful\n"; |
10de532f |
72 | |
73 | sub SigHUP { |
e6c299c8 |
74 | print "ok 8 - sigaction SIGHUP\n"; |
10de532f |
75 | kill 'INT', $$; |
76 | sleep 2; |
e6c299c8 |
77 | print "ok 9 - sig mask delayed SIGINT\n"; |
10de532f |
78 | } |
79 | |
80 | sub SigINT { |
e6c299c8 |
81 | print "ok 10 - masked SIGINT received\n"; |
10de532f |
82 | } |
e6c299c8 |
83 | |
84 | # The order of the above tests is very important, so |
85 | # we use literal prints and hard coded numbers. |
86 | next_test() for 1..4; |
d536870a |
87 | } |
6dead956 |
88 | } |
a0d0e21e |
89 | |
e6c299c8 |
90 | SKIP: { |
91 | skip("_POSIX_OPEN_MAX is inaccurate on MPE", 1) if $Is_MPE; |
92 | skip("_POSIX_OPEN_MAX undefined ($fds[1])", 1) unless &_POSIX_OPEN_MAX; |
93 | |
94 | ok( &_POSIX_OPEN_MAX > $fds[1], '_POSIX_OPEN_MAX' ); |
c9ff6e92 |
95 | } |
a0d0e21e |
96 | |
d536870a |
97 | my $pat; |
98 | if ($Is_MacOS) { |
99 | $pat = qr/:t:$/; |
e6c299c8 |
100 | } |
101 | elsif ( $Is_VMS ) { |
102 | $pat = qr/\.T]/i; |
103 | } |
104 | else { |
79b7b35c |
105 | $pat = qr#[\\/]t$#i; |
d536870a |
106 | } |
e6c299c8 |
107 | like( getcwd(), qr/$pat/, 'getcwd' ); |
a0d0e21e |
108 | |
a89d8a78 |
109 | # Check string conversion functions. |
110 | |
e6c299c8 |
111 | SKIP: { |
112 | skip("strtod() not present", 1) unless $Config{d_strtod}; |
113 | |
ff68c719 |
114 | $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale}; |
e6c299c8 |
115 | |
116 | # we're just checking that strtod works, not how accurate it is |
a89d8a78 |
117 | ($n, $x) = &POSIX::strtod('3.14159_OR_SO'); |
e6c299c8 |
118 | ok((abs("3.14159" - $n) < 1e-6) && ($x == 6), 'strtod works'); |
119 | |
ff68c719 |
120 | &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale}; |
e6c299c8 |
121 | } |
122 | |
123 | SKIP: { |
124 | skip("strtol() not present", 2) unless $Config{d_strtol}; |
a89d8a78 |
125 | |
a89d8a78 |
126 | ($n, $x) = &POSIX::strtol('21_PENGUINS'); |
e6c299c8 |
127 | is($n, 21, 'strtol() number'); |
128 | is($x, 9, ' unparsed chars'); |
129 | } |
130 | |
131 | SKIP: { |
132 | skip("strtoul() not present", 2) unless $Config{d_strtoul}; |
a89d8a78 |
133 | |
a89d8a78 |
134 | ($n, $x) = &POSIX::strtoul('88_TEARS'); |
e6c299c8 |
135 | is($n, 88, 'strtoul() number'); |
136 | is($x, 6, ' unparsed chars'); |
137 | } |
a89d8a78 |
138 | |
a0d0e21e |
139 | # Pick up whether we're really able to dynamically load everything. |
e6c299c8 |
140 | ok( &POSIX::acos(1.0) == 0.0, 'dynamic loading' ); |
a0d0e21e |
141 | |
84ef74c4 |
142 | # This can coredump if struct tm has a timezone field and we |
143 | # didn't detect it. If this fails, try adding |
144 | # -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c. |
145 | # See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl |
61a515a6 |
146 | print POSIX::strftime("ok 20 # %H:%M, on %D\n", localtime()); |
e6c299c8 |
147 | next_test(); |
84ef74c4 |
148 | |
33c0e3ec |
149 | # If that worked, validate the mini_mktime() routine's normalisation of |
150 | # input fields to strftime(). |
151 | sub try_strftime { |
33c0e3ec |
152 | my $expect = shift; |
153 | my $got = POSIX::strftime("%a %b %d %H:%M:%S %Y %j", @_); |
61a515a6 |
154 | is($got, $expect, "validating mini_mktime() and strftime(): $expect"); |
33c0e3ec |
155 | } |
156 | |
157 | $lc = &POSIX::setlocale(&POSIX::LC_TIME, 'C') if $Config{d_setlocale}; |
e6c299c8 |
158 | try_strftime("Wed Feb 28 00:00:00 1996 059", 0,0,0, 28,1,96); |
159 | try_strftime("Thu Feb 29 00:00:60 1996 060", 60,0,-24, 30,1,96); |
160 | try_strftime("Fri Mar 01 00:00:00 1996 061", 0,0,-24, 31,1,96); |
161 | try_strftime("Sun Feb 28 00:00:00 1999 059", 0,0,0, 28,1,99); |
162 | try_strftime("Mon Mar 01 00:00:00 1999 060", 0,0,24, 28,1,99); |
163 | try_strftime("Mon Feb 28 00:00:00 2000 059", 0,0,0, 28,1,100); |
164 | try_strftime("Tue Feb 29 00:00:00 2000 060", 0,0,0, 0,2,100); |
165 | try_strftime("Wed Mar 01 00:00:00 2000 061", 0,0,0, 1,2,100); |
166 | try_strftime("Fri Mar 31 00:00:00 2000 091", 0,0,0, 31,2,100); |
33c0e3ec |
167 | &POSIX::setlocale(&POSIX::LC_TIME, $lc) if $Config{d_setlocale}; |
168 | |
212caf55 |
169 | { |
170 | for my $test (0, 1) { |
171 | $! = 0; |
172 | # POSIX::errno is autoloaded. |
173 | # Autoloading requires many system calls. |
174 | # errno() looks at $! to generate its result. |
175 | # Autoloading should not munge the value. |
176 | my $foo = $!; |
177 | my $errno = POSIX::errno(); |
e6c299c8 |
178 | |
179 | local $TODO; |
180 | $TODO = 'POSIX::errno() munged by autoloading on VMS' |
181 | if $Is_VMS && $test == 0; |
182 | |
183 | # Force numeric context. |
184 | is( $errno + 0, $foo + 0, 'autoloading and errno() mix' ); |
212caf55 |
185 | } |
186 | } |
187 | |
d4742b2c |
188 | SKIP: { |
189 | skip("no kill() support on Mac OS", 1) if $Is_MacOS; |
190 | is (eval "kill 0", 0, "check we have CORE::kill") |
191 | or print "\$\@ is " . _qq($@) . "\n"; |
192 | } |
193 | |
194 | # Check that we can import the POSIX kill routine |
195 | POSIX->import ('kill'); |
196 | my $result = eval "kill 0"; |
197 | is ($result, undef, "we should now have POSIX::kill"); |
198 | # Check usage. |
199 | like ($@, qr/^Usage: POSIX::kill\(pid, sig\)/, "check its usage message"); |
200 | |
201 | # Check unimplemented. |
202 | $result = eval {POSIX::offsetof}; |
203 | is ($result, undef, "offsetof should fail"); |
204 | like ($@, qr/^Unimplemented: POSIX::offsetof\(\) is C-specific/, |
205 | "check its unimplemented message"); |
206 | |
207 | # Check reimplemented. |
208 | $result = eval {POSIX::fgets}; |
209 | is ($result, undef, "fgets should fail"); |
210 | like ($@, qr/^Use method IO::Handle::gets\(\) instead/, |
211 | "check its redef message"); |
212 | |
c07a80fd |
213 | $| = 0; |
10de532f |
214 | # The following line assumes buffered output, which may be not true: |
e6c299c8 |
215 | print '@#!*$@(!@#$' unless ($Is_MacOS || $Is_OS2 || $Is_UWin || $Is_OS390 || |
216 | $Is_VMS || |
601f2d16 |
217 | (defined $ENV{PERLIO} && |
218 | $ENV{PERLIO} eq 'unix' && |
219 | $Config::Config{useperlio})); |
a0d0e21e |
220 | _exit(0); |