This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix O_CREAT without O_TRUNC in cpan/autodie/t/utf8_open.t
[perl5.git] / t / op / sselect.t
1 #!./perl
2
3 my $hires;
4 BEGIN {
5     chdir 't' if -d 't';
6     @INC = ('.', '../lib');
7     $hires = eval 'use Time::HiResx "time"; 1';
8 }
9
10 require 'test.pl';
11
12 plan (14);
13
14 my $blank = "";
15 eval {select undef, $blank, $blank, 0};
16 is ($@, "", 'select undef  $blank $blank 0');
17 eval {select $blank, undef, $blank, 0};
18 is ($@, "", 'select $blank undef  $blank 0');
19 eval {select $blank, $blank, undef, 0};
20 is ($@, "", 'select $blank $blank undef  0');
21
22 eval {select "", $blank, $blank, 0};
23 is ($@, "", 'select ""     $blank $blank 0');
24 eval {select $blank, "", $blank, 0};
25 is ($@, "", 'select $blank ""     $blank 0');
26 eval {select $blank, $blank, "", 0};
27 is ($@, "", 'select $blank $blank ""     0');
28
29 # Test with read-only copy-on-write empty string
30 my($rocow) = keys%{{""=>undef}};
31 Internals::SvREADONLY($rocow,1);
32 eval {select $rocow, $blank, $blank, 0};
33 is ($@, "", 'select $rocow     $blank $blank 0');
34 eval {select $blank, $rocow, $blank, 0};
35 is ($@, "", 'select $blank $rocow     $blank 0');
36 eval {select $blank, $blank, $rocow, 0};
37 is ($@, "", 'select $blank $blank $rocow     0');
38
39 eval {select "a", $blank, $blank, 0};
40 like ($@, qr/^Modification of a read-only value attempted/,
41             'select "a"    $blank $blank 0');
42 eval {select $blank, "a", $blank, 0};
43 like ($@, qr/^Modification of a read-only value attempted/,
44             'select $blank "a"    $blank 0');
45 eval {select $blank, $blank, "a", 0};
46 like ($@, qr/^Modification of a read-only value attempted/,
47             'select $blank $blank "a"    0');
48
49 my $sleep = 3;
50 # Actual sleep time on Windows may be rounded down to an integral
51 # multiple of the system clock tick interval.  Clock tick interval
52 # is configurable, but usually about 15.625 milliseconds.
53 # time() however (if we haven;t loaded Time::HiRes), doesn't return
54 # fractional values, so the observed delay may be 1 second short.
55 #
56 # There is also a report that old linux kernels may return 0.5ms early:
57 # <20110520081714.GC17549@mars.tony.develop-help.com>.
58 #
59
60 my $under = $hires ? 0.1 : 1;
61
62 my $t0 = time;
63 select(undef, undef, undef, $sleep);
64 my $t1 = time;
65 my $diff = $t1-$t0;
66 ok($diff >= $sleep-$under, "select(u,u,u,\$sleep):  at least $sleep seconds have passed");
67 note("diff=$diff under=$under");
68
69 my $empty = "";
70 vec($empty,0,1) = 0;
71 $t0 = time;
72 select($empty, undef, undef, $sleep);
73 $t1 = time;
74 $diff = $t1-$t0;
75 ok($diff >= $sleep-$under, "select(\$e,u,u,\$sleep): at least $sleep seconds have passed");
76 note("diff=$diff under=$under");