This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make the test more portable.
[perl5.git] / t / lib / io_poll.t
CommitLineData
cf7fe8a2
GS
1#!./perl
2
3BEGIN {
4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
93430cb4 6 unshift @INC, '../lib' if -d '../lib';
cf7fe8a2
GS
7 }
8}
9
0994c4d0
JH
10if ($^O eq 'mpeix') {
11 print "1..0 # Skip: broken on MPE/iX\n";
12 exit 0;
13}
14
cf7fe8a2
GS
15select(STDERR); $| = 1;
16select(STDOUT); $| = 1;
17
c8aac497 18print "1..9\n";
cf7fe8a2
GS
19
20use IO::Handle;
21use IO::Poll qw(/POLL/);
22
23my $poll = new IO::Poll;
24
25my $stdout = \*STDOUT;
26my $dupout = IO::Handle->new_from_fd(fileno($stdout),"w");
27
28$poll->mask($stdout => POLLOUT);
29
30print "not "
31 unless $poll->mask($stdout) == POLLOUT;
32print "ok 1\n";
33
34$poll->mask($dupout => POLLPRI);
35
36print "not "
37 unless $poll->mask($dupout) == POLLPRI;
38print "ok 2\n";
39
40$poll->poll(0.1);
41
f63ceb1c
GS
42if ($^O eq 'MSWin32') {
43print "ok 3 # skipped, doesn't work on non-socket fds\n";
44print "ok 4 # skipped, doesn't work on non-socket fds\n";
45}
46else {
cf7fe8a2
GS
47print "not "
48 unless $poll->events($stdout) == POLLOUT;
49print "ok 3\n";
50
51print "not "
52 if $poll->events($dupout);
53print "ok 4\n";
f63ceb1c 54}
cf7fe8a2
GS
55
56my @h = $poll->handles;
57print "not "
58 unless @h == 2;
59print "ok 5\n";
60
61$poll->remove($stdout);
62
63@h = $poll->handles;
64
65print "not "
66 unless @h == 1;
67print "ok 6\n";
68
69print "not "
70 if $poll->mask($stdout);
71print "ok 7\n";
72
73$poll->poll(0.1);
74
75print "not "
76 if $poll->events($stdout);
77print "ok 8\n";
c8aac497
GS
78
79$poll->remove($dupout);
80print "not "
81 if $poll->handles;
82print "ok 9\n";