aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/library
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-04-28 23:20:11 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-04-28 23:20:11 +0200
commit79671ec57e59091260a0bc3d40a31d31d9c72a94 (patch)
tree2f59a8727b8f63f9e79d50352fa4f78a7cc00234 /spec/ruby/library
parent994833085ae06afbe94d30ab183d80e0234fbe14 (diff)
downloadruby-79671ec57e59091260a0bc3d40a31d31d9c72a94.tar.gz
Update to ruby/spec@7de852d
Diffstat (limited to 'spec/ruby/library')
-rw-r--r--spec/ruby/library/fiber/alive_spec.rb74
-rw-r--r--spec/ruby/library/fiber/current_spec.rb80
-rw-r--r--spec/ruby/library/fiber/resume_spec.rb16
-rw-r--r--spec/ruby/library/fiber/transfer_spec.rb136
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_address_spec.rb19
-rw-r--r--spec/ruby/library/socket/spec_helper.rb4
-rw-r--r--spec/ruby/library/stringio/getch_spec.rb16
7 files changed, 156 insertions, 189 deletions
diff --git a/spec/ruby/library/fiber/alive_spec.rb b/spec/ruby/library/fiber/alive_spec.rb
index 72663dd173..0c20a1c6b8 100644
--- a/spec/ruby/library/fiber/alive_spec.rb
+++ b/spec/ruby/library/fiber/alive_spec.rb
@@ -1,48 +1,46 @@
require_relative '../../spec_helper'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber#alive?" do
- it "returns true for a Fiber that hasn't had #resume called" do
- fiber = Fiber.new { true }
- fiber.alive?.should be_true
- end
+describe "Fiber#alive?" do
+ it "returns true for a Fiber that hasn't had #resume called" do
+ fiber = Fiber.new { true }
+ fiber.alive?.should be_true
+ end
- # FIXME: Better description?
- it "returns true for a Fiber that's yielded to the caller" do
- fiber = Fiber.new { Fiber.yield }
- fiber.resume
- fiber.alive?.should be_true
- end
+ # FIXME: Better description?
+ it "returns true for a Fiber that's yielded to the caller" do
+ fiber = Fiber.new { Fiber.yield }
+ fiber.resume
+ fiber.alive?.should be_true
+ end
- it "returns true when called from its Fiber" do
- fiber = Fiber.new { fiber.alive?.should be_true }
- fiber.resume
- end
+ it "returns true when called from its Fiber" do
+ fiber = Fiber.new { fiber.alive?.should be_true }
+ fiber.resume
+ end
- it "doesn't invoke the block associated with the Fiber" do
- offthehook = mock('do not call')
- offthehook.should_not_receive(:ring)
- fiber = Fiber.new { offthehook.ring }
- fiber.alive?
- end
+ it "doesn't invoke the block associated with the Fiber" do
+ offthehook = mock('do not call')
+ offthehook.should_not_receive(:ring)
+ fiber = Fiber.new { offthehook.ring }
+ fiber.alive?
+ end
- it "returns false for a Fiber that's dead" do
- fiber = Fiber.new { true }
- fiber.resume
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- end
+ it "returns false for a Fiber that's dead" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ lambda { fiber.resume }.should raise_error(FiberError)
+ fiber.alive?.should be_false
+ end
- it "always returns false for a dead Fiber" do
- fiber = Fiber.new { true }
- fiber.resume
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- fiber.alive?.should be_false
- end
+ it "always returns false for a dead Fiber" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ lambda { fiber.resume }.should raise_error(FiberError)
+ fiber.alive?.should be_false
+ lambda { fiber.resume }.should raise_error(FiberError)
+ fiber.alive?.should be_false
+ fiber.alive?.should be_false
end
end
diff --git a/spec/ruby/library/fiber/current_spec.rb b/spec/ruby/library/fiber/current_spec.rb
index 8b7fa7c4ca..52dff3dea1 100644
--- a/spec/ruby/library/fiber/current_spec.rb
+++ b/spec/ruby/library/fiber/current_spec.rb
@@ -1,53 +1,51 @@
require_relative '../../spec_helper'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber.current" do
- it "returns the root Fiber when called outside of a Fiber" do
- root = Fiber.current
- root.should be_an_instance_of(Fiber)
- # We can always transfer to the root Fiber; it will never die
- 5.times do
- root.transfer.should be_nil
- root.alive?.should be_true
- end
+describe "Fiber.current" do
+ it "returns the root Fiber when called outside of a Fiber" do
+ root = Fiber.current
+ root.should be_an_instance_of(Fiber)
+ # We can always transfer to the root Fiber; it will never die
+ 5.times do
+ root.transfer.should be_nil
+ root.alive?.should be_true
end
+ end
- it "returns the current Fiber when called from a Fiber" do
- fiber = Fiber.new do
- this = Fiber.current
- this.should be_an_instance_of(Fiber)
- this.should == fiber
- this.alive?.should be_true
- end
- fiber.resume
+ it "returns the current Fiber when called from a Fiber" do
+ fiber = Fiber.new do
+ this = Fiber.current
+ this.should be_an_instance_of(Fiber)
+ this.should == fiber
+ this.alive?.should be_true
end
+ fiber.resume
+ end
- it "returns the current Fiber when called from a Fiber that transferred to another" do
- states = []
- fiber = Fiber.new do
- states << :fiber
- this = Fiber.current
- this.should be_an_instance_of(Fiber)
- this.should == fiber
- this.alive?.should be_true
- end
-
- fiber2 = Fiber.new do
- states << :fiber2
- fiber.transfer
- flunk
- end
+ it "returns the current Fiber when called from a Fiber that transferred to another" do
+ states = []
+ fiber = Fiber.new do
+ states << :fiber
+ this = Fiber.current
+ this.should be_an_instance_of(Fiber)
+ this.should == fiber
+ this.alive?.should be_true
+ end
- fiber3 = Fiber.new do
- states << :fiber3
- fiber2.transfer
- flunk
- end
+ fiber2 = Fiber.new do
+ states << :fiber2
+ fiber.transfer
+ flunk
+ end
- fiber3.resume
- states.should == [:fiber3, :fiber2, :fiber]
+ fiber3 = Fiber.new do
+ states << :fiber3
+ fiber2.transfer
+ flunk
end
+
+ fiber3.resume
+ states.should == [:fiber3, :fiber2, :fiber]
end
end
diff --git a/spec/ruby/library/fiber/resume_spec.rb b/spec/ruby/library/fiber/resume_spec.rb
index 9789cf5b7c..3d86aed94e 100644
--- a/spec/ruby/library/fiber/resume_spec.rb
+++ b/spec/ruby/library/fiber/resume_spec.rb
@@ -1,14 +1,12 @@
require_relative '../../spec_helper'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber#resume" do
- it "raises a FiberError if the Fiber has transferred control to another Fiber" do
- fiber1 = Fiber.new { true }
- fiber2 = Fiber.new { fiber1.transfer; Fiber.yield }
- fiber2.resume
- lambda { fiber2.resume }.should raise_error(FiberError)
- end
+describe "Fiber#resume" do
+ it "raises a FiberError if the Fiber has transferred control to another Fiber" do
+ fiber1 = Fiber.new { true }
+ fiber2 = Fiber.new { fiber1.transfer; Fiber.yield }
+ fiber2.resume
+ lambda { fiber2.resume }.should raise_error(FiberError)
end
end
diff --git a/spec/ruby/library/fiber/transfer_spec.rb b/spec/ruby/library/fiber/transfer_spec.rb
index 22bb568840..1063bebeda 100644
--- a/spec/ruby/library/fiber/transfer_spec.rb
+++ b/spec/ruby/library/fiber/transfer_spec.rb
@@ -1,88 +1,86 @@
require_relative '../../spec_helper'
require_relative '../../shared/fiber/resume'
-with_feature :fiber_library do
- require 'fiber'
+require 'fiber'
- describe "Fiber#transfer" do
- it_behaves_like :fiber_resume, :transfer
+describe "Fiber#transfer" do
+ it_behaves_like :fiber_resume, :transfer
+end
+
+describe "Fiber#transfer" do
+ it "transfers control from one Fiber to another when called from a Fiber" do
+ fiber1 = Fiber.new { :fiber1 }
+ fiber2 = Fiber.new { fiber1.transfer; :fiber2 }
+ fiber2.resume.should == :fiber1
end
- describe "Fiber#transfer" do
- it "transfers control from one Fiber to another when called from a Fiber" do
- fiber1 = Fiber.new { :fiber1 }
- fiber2 = Fiber.new { fiber1.transfer; :fiber2 }
- fiber2.resume.should == :fiber1
- end
+ it "returns to the root Fiber when finished" do
+ f1 = Fiber.new { :fiber_1 }
+ f2 = Fiber.new { f1.transfer; :fiber_2 }
- it "returns to the root Fiber when finished" do
- f1 = Fiber.new { :fiber_1 }
- f2 = Fiber.new { f1.transfer; :fiber_2 }
+ f2.transfer.should == :fiber_1
+ f2.transfer.should == :fiber_2
+ end
- f2.transfer.should == :fiber_1
- f2.transfer.should == :fiber_2
- end
+ it "can be invoked from the same Fiber it transfers control to" do
+ states = []
+ fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
+ fiber.transfer
+ states.should == [:start, :end]
- it "can be invoked from the same Fiber it transfers control to" do
- states = []
- fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
- fiber.transfer
- states.should == [:start, :end]
+ states = []
+ fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
+ fiber.resume
+ states.should == [:start, :end]
+ end
- states = []
- fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
- fiber.resume
- states.should == [:start, :end]
- end
+ it "can transfer control to a Fiber that has transferred to another Fiber" do
+ states = []
+ fiber1 = Fiber.new { states << :fiber1 }
+ fiber2 = Fiber.new { states << :fiber2_start; fiber1.transfer; states << :fiber2_end}
+ fiber2.resume.should == [:fiber2_start, :fiber1]
+ fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end]
+ end
- it "can transfer control to a Fiber that has transferred to another Fiber" do
- states = []
- fiber1 = Fiber.new { states << :fiber1 }
- fiber2 = Fiber.new { states << :fiber2_start; fiber1.transfer; states << :fiber2_end}
- fiber2.resume.should == [:fiber2_start, :fiber1]
- fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end]
- end
+ it "raises a FiberError when transferring to a Fiber which resumes itself" do
+ fiber = Fiber.new { fiber.resume }
+ lambda { fiber.transfer }.should raise_error(FiberError)
+ end
- it "raises a FiberError when transferring to a Fiber which resumes itself" do
- fiber = Fiber.new { fiber.resume }
- lambda { fiber.transfer }.should raise_error(FiberError)
+ it "works if Fibers in different Threads each transfer to a Fiber in the same Thread" do
+ # This catches a bug where Fibers are running on a thread-pool
+ # and Fibers from a different Ruby Thread reuse the same native thread.
+ # Caching the Ruby Thread based on the native thread is not correct in that case,
+ # and the check for "fiber called across threads" in Fiber#transfer
+ # might be incorrect based on that.
+ 2.times do
+ Thread.new do
+ io_fiber = Fiber.new do |calling_fiber|
+ calling_fiber.transfer
+ end
+ io_fiber.transfer(Fiber.current)
+ value = Object.new
+ io_fiber.transfer(value).should equal value
+ end.join
end
+ end
- it "works if Fibers in different Threads each transfer to a Fiber in the same Thread" do
- # This catches a bug where Fibers are running on a thread-pool
- # and Fibers from a different Ruby Thread reuse the same native thread.
- # Caching the Ruby Thread based on the native thread is not correct in that case,
- # and the check for "fiber called across threads" in Fiber#transfer
- # might be incorrect based on that.
- 2.times do
- Thread.new do
- io_fiber = Fiber.new do |calling_fiber|
- calling_fiber.transfer
- end
- io_fiber.transfer(Fiber.current)
- value = Object.new
- io_fiber.transfer(value).should equal value
- end.join
+ it "transfers control between a non-main thread's root fiber to a child fiber and back again" do
+ states = []
+ thread = Thread.new do
+ f1 = Fiber.new do |f0|
+ states << 0
+ value2 = f0.transfer(1)
+ states << value2
+ 3
end
- end
-
- it "transfers control between a non-main thread's root fiber to a child fiber and back again" do
- states = []
- thread = Thread.new do
- f1 = Fiber.new do |f0|
- states << 0
- value2 = f0.transfer(1)
- states << value2
- 3
- end
- value1 = f1.transfer(Fiber.current)
- states << value1
- value3 = f1.transfer(2)
- states << value3
- end
- thread.join
- states.should == [0, 1, 2, 3]
+ value1 = f1.transfer(Fiber.current)
+ states << value1
+ value3 = f1.transfer(2)
+ states << value3
end
+ thread.join
+ states.should == [0, 1, 2, 3]
end
end
diff --git a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
index 004de37254..d53c00267a 100644
--- a/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
+++ b/spec/ruby/library/socket/addrinfo/ip_address_spec.rb
@@ -63,23 +63,4 @@ describe "Addrinfo#ip_address" do
@ips.include?(addr.ip_address).should == true
end
end
-
- # On MRI calling Addrinfo#ip_address with AF_UNSPEC as the address family is
- # supposed to raise a SocketError. MRI however doesn't provide a way to
- # actually initialize an Addrinfo with AF_UNSPEC, nor does it allow stubbing
- # of any methods since Addrinfo doesn't use any Ruby methods for checking the
- # IP address. As a result we can only run this test on Rubinius.
- with_feature :pure_ruby_addrinfo do
- describe 'with a non IPv4 or IPv6 address' do
- it 'raises SocketError' do
- sockaddr = Socket.sockaddr_in(80, '127.0.0.1')
- addr = Addrinfo.new(sockaddr)
-
- addr.stub!(:ipv4?).and_return(false)
- addr.stub!(:ipv6?).and_return(false)
-
- lambda { addr.ip_address }.should raise_error(SocketError)
- end
- end
- end
end
diff --git a/spec/ruby/library/socket/spec_helper.rb b/spec/ruby/library/socket/spec_helper.rb
index 8976937ac7..1121542dd5 100644
--- a/spec/ruby/library/socket/spec_helper.rb
+++ b/spec/ruby/library/socket/spec_helper.rb
@@ -1,10 +1,6 @@
require_relative '../../spec_helper'
require 'socket'
-if %w[rbx truffleruby].include?(RUBY_ENGINE)
- MSpec.enable_feature :pure_ruby_addrinfo
-end
-
MSpec.enable_feature :sock_packet if Socket.const_defined?(:SOCK_PACKET)
MSpec.enable_feature :unix_socket unless PlatformGuard.windows?
MSpec.enable_feature :udp_cork if Socket.const_defined?(:UDP_CORK)
diff --git a/spec/ruby/library/stringio/getch_spec.rb b/spec/ruby/library/stringio/getch_spec.rb
index 06670a178c..113b4971bf 100644
--- a/spec/ruby/library/stringio/getch_spec.rb
+++ b/spec/ruby/library/stringio/getch_spec.rb
@@ -17,15 +17,13 @@ describe "StringIO#getch" do
io.getch.should == ?a
end
- with_feature :encoding do
- it "increments #pos by the byte size of the character in multibyte strings" do
- io = StringIO.new("föóbar")
-
- io.getch; io.pos.should == 1 # "f" has byte size 1
- io.getch; io.pos.should == 3 # "ö" has byte size 2
- io.getch; io.pos.should == 5 # "ó" has byte size 2
- io.getch; io.pos.should == 6 # "b" has byte size 1
- end
+ it "increments #pos by the byte size of the character in multibyte strings" do
+ io = StringIO.new("föóbar")
+
+ io.getch; io.pos.should == 1 # "f" has byte size 1
+ io.getch; io.pos.should == 3 # "ö" has byte size 2
+ io.getch; io.pos.should == 5 # "ó" has byte size 2
+ io.getch; io.pos.should == 6 # "b" has byte size 1
end
it "returns nil at the end of the string" do