Commit | Line | Data |
---|---|---|
729c079f NC |
1 | #!./perl |
2 | ||
b3d9788e | 3 | my $hires; |
729c079f NC |
4 | BEGIN { |
5 | chdir 't' if -d 't'; | |
6 | @INC = ('.', '../lib'); | |
b3d9788e | 7 | $hires = eval 'use Time::HiResx "time"; 1'; |
729c079f NC |
8 | } |
9 | ||
10 | require 'test.pl'; | |
11 | ||
90eaaf02 | 12 | plan (15); |
729c079f NC |
13 | |
14 | my $blank = ""; | |
15 | eval {select undef, $blank, $blank, 0}; | |
8075d46e | 16 | is ($@, "", 'select undef $blank $blank 0'); |
729c079f | 17 | eval {select $blank, undef, $blank, 0}; |
8075d46e | 18 | is ($@, "", 'select $blank undef $blank 0'); |
729c079f | 19 | eval {select $blank, $blank, undef, 0}; |
8075d46e | 20 | is ($@, "", 'select $blank $blank undef 0'); |
729c079f NC |
21 | |
22 | eval {select "", $blank, $blank, 0}; | |
8075d46e | 23 | is ($@, "", 'select "" $blank $blank 0'); |
729c079f | 24 | eval {select $blank, "", $blank, 0}; |
8075d46e | 25 | is ($@, "", 'select $blank "" $blank 0'); |
729c079f | 26 | eval {select $blank, $blank, "", 0}; |
8075d46e | 27 | is ($@, "", 'select $blank $blank "" 0'); |
15547071 | 28 | |
ba3062ae FC |
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 | ||
15547071 | 39 | eval {select "a", $blank, $blank, 0}; |
8075d46e DM |
40 | like ($@, qr/^Modification of a read-only value attempted/, |
41 | 'select "a" $blank $blank 0'); | |
15547071 | 42 | eval {select $blank, "a", $blank, 0}; |
8075d46e DM |
43 | like ($@, qr/^Modification of a read-only value attempted/, |
44 | 'select $blank "a" $blank 0'); | |
15547071 | 45 | eval {select $blank, $blank, "a", 0}; |
8075d46e DM |
46 | like ($@, qr/^Modification of a read-only value attempted/, |
47 | 'select $blank $blank "a" 0'); | |
e4d771f5 | 48 | |
b3d9788e | 49 | my $sleep = 3; |
0ebb4f02 JD |
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. | |
b3d9788e DM |
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 | # | |
0ebb4f02 | 59 | |
b3d9788e DM |
60 | my $under = $hires ? 0.1 : 1; |
61 | ||
62 | my $t0 = time; | |
e4d771f5 | 63 | select(undef, undef, undef, $sleep); |
b3d9788e DM |
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"); | |
e4d771f5 JD |
68 | |
69 | my $empty = ""; | |
70 | vec($empty,0,1) = 0; | |
b3d9788e | 71 | $t0 = time; |
e4d771f5 | 72 | select($empty, undef, undef, $sleep); |
b3d9788e DM |
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"); | |
90eaaf02 EB |
77 | |
78 | # [perl #120102] CORE::select ignoring timeout var's magic | |
79 | ||
80 | { | |
81 | package RT120102; | |
82 | ||
83 | my $count = 0; | |
84 | ||
85 | sub TIESCALAR { bless [] } | |
86 | sub FETCH { $count++; 0.1 } | |
87 | ||
88 | my $sleep; | |
89 | ||
90 | tie $sleep, 'RT120102'; | |
91 | select (undef, undef, undef, $sleep); | |
92 | ::is($count, 1, 'RT120102'); | |
93 | } |