This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
time() resolution is full seconds
[perl5.git] / t / op / sselect.t
CommitLineData
729c079f
NC
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = ('.', '../lib');
6}
7
8require 'test.pl';
9
e4d771f5 10plan (11);
729c079f
NC
11
12my $blank = "";
13eval {select undef, $blank, $blank, 0};
14is ($@, "");
15eval {select $blank, undef, $blank, 0};
16is ($@, "");
17eval {select $blank, $blank, undef, 0};
18is ($@, "");
19
20eval {select "", $blank, $blank, 0};
15547071 21is ($@, "");
729c079f 22eval {select $blank, "", $blank, 0};
15547071 23is ($@, "");
729c079f 24eval {select $blank, $blank, "", 0};
15547071
GA
25is ($@, "");
26
27eval {select "a", $blank, $blank, 0};
28like ($@, qr/^Modification of a read-only value attempted/);
29eval {select $blank, "a", $blank, 0};
30like ($@, qr/^Modification of a read-only value attempted/);
31eval {select $blank, $blank, "a", 0};
729c079f 32like ($@, qr/^Modification of a read-only value attempted/);
e4d771f5 33
2b983d1f 34my($sleep,$fudge) = (3,0);
0ebb4f02
JD
35# Actual sleep time on Windows may be rounded down to an integral
36# multiple of the system clock tick interval. Clock tick interval
37# is configurable, but usually about 15.625 milliseconds.
2b983d1f
JD
38# time() however doesn't return fractional values, so the observed
39# delay may be 1 second short.
40($sleep,$fudge) = (4,1) if $^O eq "MSWin32";
0ebb4f02 41
e4d771f5
JD
42my $t = time;
43select(undef, undef, undef, $sleep);
0ebb4f02 44ok(time-$t >= $sleep-$fudge, "$sleep seconds have passed");
e4d771f5
JD
45
46my $empty = "";
47vec($empty,0,1) = 0;
48$t = time;
49select($empty, undef, undef, $sleep);
0ebb4f02 50ok(time-$t >= $sleep-$fudge, "$sleep seconds have passed");