This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
README.os2 update
[perl5.git] / t / lib / 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 use strict subs;
15
16 $| = 1;
17 print "1..18\n";
18
19 $Is_W32 = $^O eq 'MSWin32';
20
21 $testfd = open("TEST", O_RDONLY, 0) and print "ok 1\n";
22 read($testfd, $buffer, 9) if $testfd > 2;
23 print $buffer eq "#!./perl\n" ? "ok 2\n" : "not ok 2\n";
24
25 write(1,"ok 3\nnot ok 3\n", 5);
26
27 @fds = POSIX::pipe();
28 print $fds[0] > $testfd ? "ok 4\n" : "not ok 4\n";
29 CORE::open($reader = \*READER, "<&=".$fds[0]);
30 CORE::open($writer = \*WRITER, ">&=".$fds[1]);
31 print $writer "ok 5\n";
32 close $writer;
33 print <$reader>;
34 close $reader;
35
36 if ($Is_W32) {
37     for (6..11) {
38         print "ok $_ # skipped, no sigaction support on win32\n";
39     }
40 }
41 else {
42 $sigset = new POSIX::SigSet 1,3;
43 delset $sigset 1;
44 if (!ismember $sigset 1) { print "ok 6\n" }
45 if (ismember $sigset 3) { print "ok 7\n" }
46 $mask = new POSIX::SigSet &SIGINT;
47 $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
48 sigaction(&SIGHUP, $action);
49 $SIG{'INT'} = 'SigINT';
50 kill 'HUP', $$;
51 sleep 1;
52 print "ok 11\n";
53
54 sub SigHUP {
55     print "ok 8\n";
56     kill 'INT', $$;
57     sleep 2;
58     print "ok 9\n";
59 }
60
61 sub SigINT {
62     print "ok 10\n";
63 }
64 }
65
66 print &_POSIX_OPEN_MAX > $fds[1] ? "ok 12\n" : "not ok 12\n";
67
68 print getcwd() =~ m#/t$# ? "ok 13\n" : "not ok 13\n";
69
70 # Check string conversion functions.
71
72 if ($Config{d_strtod}) {
73     $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
74     ($n, $x) = &POSIX::strtod('3.14159_OR_SO');
75     print (($n == 3.14159) && ($x == 6) ? "ok 14\n" : "not ok 14\n");
76     &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
77 } else { print "# strtod not present\n", "ok 14\n"; }
78
79 if ($Config{d_strtol}) {
80     ($n, $x) = &POSIX::strtol('21_PENGUINS');
81     print (($n == 21) && ($x == 9) ? "ok 15\n" : "not ok 15\n");
82 } else { print "# strtol not present\n", "ok 15\n"; }
83
84 if ($Config{d_strtoul}) {
85     ($n, $x) = &POSIX::strtoul('88_TEARS');
86     print (($n == 88) && ($x == 6) ? "ok 16\n" : "not ok 16\n");
87 } else { print "# strtoul not present\n", "ok 16\n"; }
88
89 # Pick up whether we're really able to dynamically load everything.
90 print &POSIX::acos(1.0) == 0.0 ? "ok 17\n" : "not ok 17\n";
91
92 # This can coredump if struct tm has a timezone field and we
93 # didn't detect it.  If this fails, try adding
94 # -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
95 # See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl 
96 print POSIX::strftime("ok 18 # %H:%M, on %D\n", localtime());
97
98 $| = 0;
99 # The following line assumes buffered output, which may be not true with EMX:
100 print '@#!*$@(!@#$' unless $^O eq 'os2';
101 _exit(0);