diff options
Diffstat (limited to 'spec/ruby/core/io/select_spec.rb')
| -rw-r--r-- | spec/ruby/core/io/select_spec.rb | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/spec/ruby/core/io/select_spec.rb b/spec/ruby/core/io/select_spec.rb index 3893e7620f..0a43fc6f5f 100644 --- a/spec/ruby/core/io/select_spec.rb +++ b/spec/ruby/core/io/select_spec.rb @@ -18,6 +18,10 @@ describe "IO.select" do @wr.syswrite("be ready") IO.pipe do |_, wr| result = IO.select [@rd], [wr], nil, 0 + unless result + # On some platforms (e.g., Windows), pipe readiness may not be immediate + result = IO.select [@rd], [wr], nil, 2 + end result.should == [[@rd], [wr], []] end end @@ -91,28 +95,38 @@ describe "IO.select" do end it "raises TypeError if supplied objects are not IO" do - -> { IO.select([Object.new]) }.should raise_error(TypeError) - -> { IO.select(nil, [Object.new]) }.should raise_error(TypeError) + -> { IO.select([Object.new]) }.should.raise(TypeError) + -> { IO.select(nil, [Object.new]) }.should.raise(TypeError) obj = mock("io") obj.should_receive(:to_io).any_number_of_times.and_return(nil) - -> { IO.select([obj]) }.should raise_error(TypeError) - -> { IO.select(nil, [obj]) }.should raise_error(TypeError) + -> { IO.select([obj]) }.should.raise(TypeError) + -> { IO.select(nil, [obj]) }.should.raise(TypeError) end it "raises a TypeError if the specified timeout value is not Numeric" do - -> { IO.select([@rd], nil, nil, Object.new) }.should raise_error(TypeError) + -> { IO.select([@rd], nil, nil, Object.new) }.should.raise(TypeError) end it "raises TypeError if the first three arguments are not Arrays" do - -> { IO.select(Object.new)}.should raise_error(TypeError) - -> { IO.select(nil, Object.new)}.should raise_error(TypeError) - -> { IO.select(nil, nil, Object.new)}.should raise_error(TypeError) + -> { IO.select(Object.new)}.should.raise(TypeError) + -> { IO.select(nil, Object.new)}.should.raise(TypeError) + -> { IO.select(nil, nil, Object.new)}.should.raise(TypeError) end it "raises an ArgumentError when passed a negative timeout" do - -> { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError) + -> { IO.select(nil, nil, nil, -5)}.should.raise(ArgumentError, "time interval must not be negative") + end + + ruby_version_is "4.0" do + it "raises an ArgumentError when passed negative infinity as timeout" do + -> { IO.select(nil, nil, nil, -Float::INFINITY)}.should.raise(ArgumentError, "time interval must not be negative") + end + end + + it "raises an RangeError when passed NaN as timeout" do + -> { IO.select(nil, nil, nil, Float::NAN)}.should.raise(RangeError, "NaN out of Time range") end describe "returns the available descriptors when the file descriptor" do @@ -149,16 +163,28 @@ describe "IO.select" do end end -describe "IO.select when passed nil for timeout" do - it "sleeps forever and sets the thread status to 'sleep'" do - t = Thread.new do - IO.select(nil, nil, nil, nil) +describe "IO.select with infinite timeout" do + describe :io_select_infinite_timeout, shared: true do + it "sleeps forever and sets the thread status to 'sleep'" do + t = Thread.new do + IO.select(nil, nil, nil, @method) + end + + Thread.pass while t.status && t.status != "sleep" + t.join unless t.status + t.status.should == "sleep" + t.kill + t.join end + end - Thread.pass while t.status && t.status != "sleep" - t.join unless t.status - t.status.should == "sleep" - t.kill - t.join + describe "IO.select when passed nil for timeout" do + it_behaves_like :io_select_infinite_timeout, nil + end + + ruby_version_is "4.0" do + describe "IO.select when passed Float::INFINITY for timeout" do + it_behaves_like :io_select_infinite_timeout, Float::INFINITY + end end end |
