This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Get t/uni/cache.t working under minitest
[perl5.git] / t / op / sselect.t
CommitLineData
729c079f
NC
1#!./perl
2
b3d9788e 3my $hires;
729c079f
NC
4BEGIN {
5 chdir 't' if -d 't';
6 @INC = ('.', '../lib');
b3d9788e 7 $hires = eval 'use Time::HiResx "time"; 1';
729c079f
NC
8}
9
10require 'test.pl';
11
90eaaf02 12plan (15);
729c079f
NC
13
14my $blank = "";
15eval {select undef, $blank, $blank, 0};
8075d46e 16is ($@, "", 'select undef $blank $blank 0');
729c079f 17eval {select $blank, undef, $blank, 0};
8075d46e 18is ($@, "", 'select $blank undef $blank 0');
729c079f 19eval {select $blank, $blank, undef, 0};
8075d46e 20is ($@, "", 'select $blank $blank undef 0');
729c079f
NC
21
22eval {select "", $blank, $blank, 0};
8075d46e 23is ($@, "", 'select "" $blank $blank 0');
729c079f 24eval {select $blank, "", $blank, 0};
8075d46e 25is ($@, "", 'select $blank "" $blank 0');
729c079f 26eval {select $blank, $blank, "", 0};
8075d46e 27is ($@, "", 'select $blank $blank "" 0');
15547071 28
ba3062ae
FC
29# Test with read-only copy-on-write empty string
30my($rocow) = keys%{{""=>undef}};
31Internals::SvREADONLY($rocow,1);
32eval {select $rocow, $blank, $blank, 0};
33is ($@, "", 'select $rocow $blank $blank 0');
34eval {select $blank, $rocow, $blank, 0};
35is ($@, "", 'select $blank $rocow $blank 0');
36eval {select $blank, $blank, $rocow, 0};
37is ($@, "", 'select $blank $blank $rocow 0');
38
15547071 39eval {select "a", $blank, $blank, 0};
8075d46e
DM
40like ($@, qr/^Modification of a read-only value attempted/,
41 'select "a" $blank $blank 0');
15547071 42eval {select $blank, "a", $blank, 0};
8075d46e
DM
43like ($@, qr/^Modification of a read-only value attempted/,
44 'select $blank "a" $blank 0');
15547071 45eval {select $blank, $blank, "a", 0};
8075d46e
DM
46like ($@, qr/^Modification of a read-only value attempted/,
47 'select $blank $blank "a" 0');
e4d771f5 48
b3d9788e 49my $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
60my $under = $hires ? 0.1 : 1;
61
62my $t0 = time;
e4d771f5 63select(undef, undef, undef, $sleep);
b3d9788e
DM
64my $t1 = time;
65my $diff = $t1-$t0;
66ok($diff >= $sleep-$under, "select(u,u,u,\$sleep): at least $sleep seconds have passed");
67note("diff=$diff under=$under");
e4d771f5
JD
68
69my $empty = "";
70vec($empty,0,1) = 0;
b3d9788e 71$t0 = time;
e4d771f5 72select($empty, undef, undef, $sleep);
b3d9788e
DM
73$t1 = time;
74$diff = $t1-$t0;
75ok($diff >= $sleep-$under, "select(\$e,u,u,\$sleep): at least $sleep seconds have passed");
76note("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}