diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-07-29 22:11:21 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-07-29 22:11:21 +0200 |
commit | 6998d758248d778fa95b008c78d05473e48b8428 (patch) | |
tree | 8abc6926f647ea5f374a5b34c3a4820c5861e32e /spec/ruby/library | |
parent | 15d05f8120745a121b93fab9fd2addf5f094e8d2 (diff) |
Update to ruby/spec@b65d01f
Diffstat (limited to 'spec/ruby/library')
27 files changed, 468 insertions, 193 deletions
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index d56c0a664b..43a779b420 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -56,22 +56,11 @@ describe "Kernel#BigDecimal" do BigDecimal(initial).should == BigDecimal("123") end - ruby_version_is ""..."2.6" do - it "ignores trailing garbage" do - BigDecimal("123E45ruby").should == BigDecimal("123E45") - BigDecimal("123x45").should == BigDecimal("123") - BigDecimal("123.4%E5").should == BigDecimal("123.4") - BigDecimal("1E2E3E4E5E").should == BigDecimal("100") - end - end - - ruby_version_is "2.6" do - it "does not ignores trailing garbage" do - -> { BigDecimal("123E45ruby") }.should raise_error(ArgumentError) - -> { BigDecimal("123x45") }.should raise_error(ArgumentError) - -> { BigDecimal("123.4%E5") }.should raise_error(ArgumentError) - -> { BigDecimal("1E2E3E4E5E") }.should raise_error(ArgumentError) - end + it "does not ignores trailing garbage" do + -> { BigDecimal("123E45ruby") }.should raise_error(ArgumentError) + -> { BigDecimal("123x45") }.should raise_error(ArgumentError) + -> { BigDecimal("123.4%E5") }.should raise_error(ArgumentError) + -> { BigDecimal("1E2E3E4E5E") }.should raise_error(ArgumentError) end it "raises ArgumentError for invalid strings" do @@ -83,24 +72,12 @@ describe "Kernel#BigDecimal" do BigDecimal(".123").should == BigDecimal("0.123") end - ruby_version_is ""..."2.6" do - it "allows for underscores in all parts" do - reference = BigDecimal("12345.67E89") - - BigDecimal("12_345.67E89").should == reference - BigDecimal("1_2_3_4_5_._6____7_E89").should == reference - BigDecimal("12345_.67E_8__9_").should == reference - end - end - - ruby_version_is "2.6" do - it "process underscores as Float()" do - reference = BigDecimal("12345.67E89") + it "process underscores as Float()" do + reference = BigDecimal("12345.67E89") - BigDecimal("12_345.67E89").should == reference - -> { BigDecimal("1_2_3_4_5_._6____7_E89") }.should raise_error(ArgumentError) - -> { BigDecimal("12345_.67E_8__9_") }.should raise_error(ArgumentError) - end + BigDecimal("12_345.67E89").should == reference + -> { BigDecimal("1_2_3_4_5_._6____7_E89") }.should raise_error(ArgumentError) + -> { BigDecimal("12345_.67E_8__9_") }.should raise_error(ArgumentError) end it "accepts NaN and [+-]Infinity" do @@ -116,14 +93,12 @@ describe "Kernel#BigDecimal" do neg_inf.should < 0 end - ruby_version_is "2.6" do - describe "with exception: false" do - it "returns nil for invalid strings" do - BigDecimal("invalid", exception: false).should be_nil - BigDecimal("0invalid", exception: false).should be_nil - BigDecimal("invalid0", exception: false).should be_nil - BigDecimal("0.", exception: false).should be_nil - end + describe "with exception: false" do + it "returns nil for invalid strings" do + BigDecimal("invalid", exception: false).should be_nil + BigDecimal("0invalid", exception: false).should be_nil + BigDecimal("invalid0", exception: false).should be_nil + BigDecimal("0.", exception: false).should be_nil end end diff --git a/spec/ruby/library/bigdecimal/util_spec.rb b/spec/ruby/library/bigdecimal/util_spec.rb index f41e131144..fc67fcf200 100644 --- a/spec/ruby/library/bigdecimal/util_spec.rb +++ b/spec/ruby/library/bigdecimal/util_spec.rb @@ -27,10 +27,8 @@ describe "BigDecimal's util method definitions" do Rational(22, 7).to_d(3).should == BigDecimal(3.14, 3) end - ruby_version_is "2.6" do - it "should define #to_d on nil" do - nil.to_d.should == BigDecimal(0) - end + it "should define #to_d on nil" do + nil.to_d.should == BigDecimal(0) end end diff --git a/spec/ruby/library/erb/fixtures/classes.rb b/spec/ruby/library/erb/fixtures/classes.rb index 03da889941..e07a6ed68d 100644 --- a/spec/ruby/library/erb/fixtures/classes.rb +++ b/spec/ruby/library/erb/fixtures/classes.rb @@ -1,9 +1,5 @@ module ERBSpecs def self.new_erb(input, trim_mode: nil) - if ruby_version_is "2.6" - ERB.new(input, trim_mode: trim_mode) - else - ERB.new(input, nil, trim_mode) - end + ERB.new(input, trim_mode: trim_mode) end end diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb index 3bb870dd3f..f18e25939e 100644 --- a/spec/ruby/library/erb/new_spec.rb +++ b/spec/ruby/library/erb/new_spec.rb @@ -36,12 +36,10 @@ END end end - ruby_version_is "2.6" do - it "warns invalid trim_mode" do - -> do - ERBSpecs.new_erb(@eruby_str, trim_mode: '') - end.should complain(/Invalid ERB trim mode/) - end + it "warns invalid trim_mode" do + -> do + ERBSpecs.new_erb(@eruby_str, trim_mode: '') + end.should complain(/Invalid ERB trim mode/) end it "removes '\n' when trim_mode is 1 or '>'" do @@ -120,13 +118,8 @@ END it "changes '_erbout' variable name in the produced source" do input = @eruby_str - if RUBY_VERSION >= '2.6' - match_erbout = ERB.new(input, trim_mode: nil).src - match_buf = ERB.new(input, trim_mode: nil, eoutvar: 'buf').src - else - match_erbout = ERB.new(input, nil, nil).src - match_buf = ERB.new(input, nil, nil, 'buf').src - end + match_erbout = ERB.new(input, trim_mode: nil).src + match_buf = ERB.new(input, trim_mode: nil, eoutvar: 'buf').src match_erbout.gsub("_erbout", "buf").should == match_buf end diff --git a/spec/ruby/library/matrix/antisymmetric_spec.rb b/spec/ruby/library/matrix/antisymmetric_spec.rb index a0d1a5f69b..dcc3c30f3e 100644 --- a/spec/ruby/library/matrix/antisymmetric_spec.rb +++ b/spec/ruby/library/matrix/antisymmetric_spec.rb @@ -3,37 +3,35 @@ require_relative '../../spec_helper' ruby_version_is ""..."3.1" do require 'matrix' - ruby_version_is "2.6" do - describe "Matrix#antisymmetric?" do - it "returns true for an antisymmetric Matrix" do - Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true - end + describe "Matrix#antisymmetric?" do + it "returns true for an antisymmetric Matrix" do + Matrix[[0, -2, Complex(1, 3)], [2, 0, 5], [-Complex(1, 3), -5, 0]].antisymmetric?.should be_true + end - it "returns true for a 0x0 empty matrix" do - Matrix.empty.antisymmetric?.should be_true - end + it "returns true for a 0x0 empty matrix" do + Matrix.empty.antisymmetric?.should be_true + end - it "returns false for non-antisymmetric matrices" do - [ - Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], - Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element - Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong - ].each do |matrix| - matrix.antisymmetric?.should be_false - end + it "returns false for non-antisymmetric matrices" do + [ + Matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]], + Matrix[[1, -2, 3], [2, 0, 6], [-3, -6, 0]], # wrong diagonal element + Matrix[[0, 2, -3], [2, 0, 6], [-3, 6, 0]] # only signs wrong + ].each do |matrix| + matrix.antisymmetric?.should be_false end + end - it "raises an error for rectangular matrices" do - [ - Matrix[[0], [0]], - Matrix[[0, 0]], - Matrix.empty(0, 2), - Matrix.empty(2, 0), - ].each do |rectangular_matrix| - -> { - rectangular_matrix.antisymmetric? - }.should raise_error(Matrix::ErrDimensionMismatch) - end + it "raises an error for rectangular matrices" do + [ + Matrix[[0], [0]], + Matrix[[0, 0]], + Matrix.empty(0, 2), + Matrix.empty(2, 0), + ].each do |rectangular_matrix| + -> { + rectangular_matrix.antisymmetric? + }.should raise_error(Matrix::ErrDimensionMismatch) end end end diff --git a/spec/ruby/library/monitor/enter_spec.rb b/spec/ruby/library/monitor/enter_spec.rb new file mode 100644 index 0000000000..f523c42087 --- /dev/null +++ b/spec/ruby/library/monitor/enter_spec.rb @@ -0,0 +1,28 @@ +require_relative '../../spec_helper' +require 'monitor' + +describe "Monitor#enter" do + it "acquires the monitor" do + monitor = Monitor.new + 10.times do + wait_q = Queue.new + continue_q = Queue.new + + thread = Thread.new do + begin + monitor.enter + wait_q << true + continue_q.pop + ensure + monitor.exit + end + end + + wait_q.pop + monitor.mon_locked?.should == true + continue_q << true + thread.join + monitor.mon_locked?.should == false + end + end +end diff --git a/spec/ruby/library/monitor/new_cond_spec.rb b/spec/ruby/library/monitor/new_cond_spec.rb new file mode 100644 index 0000000000..ec25d3f8a2 --- /dev/null +++ b/spec/ruby/library/monitor/new_cond_spec.rb @@ -0,0 +1,88 @@ +require_relative '../../spec_helper' +require 'monitor' + +describe "Monitor#new_cond" do + it "creates a MonitorMixin::ConditionVariable" do + m = Monitor.new + c = m.new_cond + c.class.should == MonitorMixin::ConditionVariable + end + + it 'returns a condition variable which can be waited on by a thread holding the monitor' do + m = Monitor.new + c = m.new_cond + + 10.times do + + wait_q = Queue.new + thread = Thread.new do + m.synchronize do + wait_q << true + c.wait + end + :done + end + + wait_q.pop + + # Synchronize can't happen until the other thread is waiting. + m.synchronize { c.signal } + + thread.join + thread.value.should == :done + end + end + + it 'returns a condition variable which can be waited on by a thread holding the monitor inside multiple synchronize blocks' do + m = Monitor.new + c = m.new_cond + + 10.times do + + wait_q = Queue.new + thread = Thread.new do + m.synchronize do + m.synchronize do + wait_q << true + c.wait + end + end + :done + end + + wait_q.pop + + #No need to wait here as we cannot synchronize until the other thread is waiting. + m.synchronize { c.signal } + + thread.join + thread.value.should == :done + end + end + + it 'returns a condition variable which can be signalled by a thread holding the monitor inside multiple synchronize blocks' do + m = Monitor.new + c = m.new_cond + + 10.times do + + wait_q = Queue.new + thread = Thread.new do + m.synchronize do + wait_q << true + c.wait + end + :done + end + + wait_q.pop + + # Synchronize can't happen until the other thread is waiting. + m.synchronize { m.synchronize { c.signal } } + + thread.join + thread.value.should == :done + end + end + +end diff --git a/spec/ruby/library/monitor/synchronize_spec.rb b/spec/ruby/library/monitor/synchronize_spec.rb index d851b98d6c..d78393eb3a 100644 --- a/spec/ruby/library/monitor/synchronize_spec.rb +++ b/spec/ruby/library/monitor/synchronize_spec.rb @@ -7,24 +7,35 @@ describe "Monitor#synchronize" do monitor = Monitor.new 10.times do - locked = false + wait_q = Queue.new + continue_q = Queue.new thread = Thread.new do begin monitor.synchronize do - locked = true + wait_q << true # Do not wait here, we are trying to interrupt the ensure part of #synchronize end - sleep # wait for exception if it did not happen yet + continue_q.pop rescue exc_class monitor.should_not.mon_locked? :ok end end - Thread.pass until locked + wait_q.pop thread.raise exc_class, "interrupt" + continue_q << true thread.value.should == :ok end end + + it "raises a LocalJumpError if not passed a block" do + -> { Monitor.new.synchronize }.should raise_error(LocalJumpError) + end + + it "raises a thread error if the monitor is not owned on exiting the block" do + monitor = Monitor.new + -> { monitor.synchronize { monitor.exit } }.should raise_error(ThreadError) + end end diff --git a/spec/ruby/library/monitor/try_enter_spec.rb b/spec/ruby/library/monitor/try_enter_spec.rb new file mode 100644 index 0000000000..04b878f720 --- /dev/null +++ b/spec/ruby/library/monitor/try_enter_spec.rb @@ -0,0 +1,39 @@ +require_relative '../../spec_helper' +require 'monitor' + +describe "Monitor#try_enter" do + it "will acquire a monitor not held by another thread" do + monitor = Monitor.new + 10.times do + + thread = Thread.new do + val = monitor.try_enter + monitor.exit if val + val + end + + thread.join + thread.value.should == true + end + end + + it "will not acquire a monitor already held by another thread" do + monitor = Monitor.new + 10.times do + monitor.enter + begin + thread = Thread.new do + val = monitor.try_enter + monitor.exit if val + val + end + + thread.join + thread.value.should == false + ensure + monitor.exit + end + monitor.mon_locked?.should == false + end + end +end diff --git a/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb b/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb index 08347464ec..d576349a57 100644 --- a/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb +++ b/spec/ruby/library/net/http/HTTPClientExcepton_spec.rb @@ -1,14 +1,12 @@ require_relative '../../../spec_helper' require 'net/http' -ruby_version_is "2.6" do - describe "Net::HTTPClientException" do - it "is a subclass of Net::ProtoServerError" do - Net::HTTPClientException.should < Net::ProtoServerError - end +describe "Net::HTTPClientException" do + it "is a subclass of Net::ProtoServerError" do + Net::HTTPClientException.should < Net::ProtoServerError + end - it "includes the Net::HTTPExceptions module" do - Net::HTTPClientException.should < Net::HTTPExceptions - end + it "includes the Net::HTTPExceptions module" do + Net::HTTPClientException.should < Net::HTTPExceptions end end diff --git a/spec/ruby/library/net/http/HTTPServerException_spec.rb b/spec/ruby/library/net/http/HTTPServerException_spec.rb index 87841ab499..23b0657364 100644 --- a/spec/ruby/library/net/http/HTTPServerException_spec.rb +++ b/spec/ruby/library/net/http/HTTPServerException_spec.rb @@ -1,26 +1,12 @@ require_relative '../../../spec_helper' require 'net/http' -ruby_version_is ""..."2.6" do - describe "Net::HTTPServerException" do - it "is a subclass of Net::ProtoServerError" do - Net::HTTPServerException.should < Net::ProtoServerError - end - - it "includes the Net::HTTPExceptions module" do - Net::HTTPServerException.should < Net::HTTPExceptions - end +describe "Net::HTTPServerException" do + it "is a subclass of Net::ProtoServerError and is warned as deprecated" do + -> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/) end -end - -ruby_version_is "2.6" do - describe "Net::HTTPServerException" do - it "is a subclass of Net::ProtoServerError and is warned as deprecated" do - -> { Net::HTTPServerException.should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/) - end - it "includes the Net::HTTPExceptions module and is warned as deprecated" do - -> { Net::HTTPServerException.should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/) - end + it "includes the Net::HTTPExceptions module and is warned as deprecated" do + -> { Net::HTTPServerException.should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/) end end diff --git a/spec/ruby/library/net/http/http/fixtures/http_server.rb b/spec/ruby/library/net/http/http/fixtures/http_server.rb index a84e0d47d0..c06012cc86 100644 --- a/spec/ruby/library/net/http/http/fixtures/http_server.rb +++ b/spec/ruby/library/net/http/http/fixtures/http_server.rb @@ -63,8 +63,9 @@ module NetHTTPSpecs end def start_server + bind_address = platform_is(:windows) ? "localhost" : "127.0.0.1" server_config = { - BindAddress: "localhost", + BindAddress: bind_address, Port: 0, Logger: WEBrick::Log.new(NullWriter.new), AccessLog: [], diff --git a/spec/ruby/library/net/http/httpresponse/error_spec.rb b/spec/ruby/library/net/http/httpresponse/error_spec.rb index d2b2f53d89..89f4a47f60 100644 --- a/spec/ruby/library/net/http/httpresponse/error_spec.rb +++ b/spec/ruby/library/net/http/httpresponse/error_spec.rb @@ -16,12 +16,7 @@ describe "Net::HTTPResponse#error!" do -> { res.error! }.should raise_error(Net::HTTPRetriableError) res = Net::HTTPClientError.new("1.0", "4xx", "test response") - ruby_version_is ""..."2.6" do - -> { res.error! }.should raise_error(Net::HTTPServerException) - end - ruby_version_is "2.6" do - -> { res.error! }.should raise_error(Net::HTTPClientException) - end + -> { res.error! }.should raise_error(Net::HTTPClientException) res = Net::HTTPServerError.new("1.0", "5xx", "test response") -> { res.error! }.should raise_error(Net::HTTPFatalError) diff --git a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb b/spec/ruby/library/net/http/httpresponse/error_type_spec.rb index 6705f8b1aa..8885b7706b 100644 --- a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb +++ b/spec/ruby/library/net/http/httpresponse/error_type_spec.rb @@ -16,12 +16,7 @@ describe "Net::HTTPResponse#error_type" do res.error_type.should == Net::HTTPRetriableError res = Net::HTTPClientError.new("1.0", "4xx", "test response") - ruby_version_is ""..."2.6" do - res.error_type.should == Net::HTTPServerException - end - ruby_version_is "2.6" do - res.error_type.should == Net::HTTPClientException - end + res.error_type.should == Net::HTTPClientException res = Net::HTTPServerError.new("1.0", "5xx", "test response") res.error_type.should == Net::HTTPFatalError diff --git a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb b/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb index c0812cd322..0c9c11291f 100644 --- a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb +++ b/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb @@ -7,12 +7,7 @@ describe "Net::HTTPResponse.exception_type" do Net::HTTPInformation.exception_type.should == Net::HTTPError Net::HTTPSuccess.exception_type.should == Net::HTTPError Net::HTTPRedirection.exception_type.should == Net::HTTPRetriableError - ruby_version_is ""..."2.6" do - Net::HTTPClientError.exception_type.should == Net::HTTPServerException - end - ruby_version_is "2.6" do - Net::HTTPClientError.exception_type.should == Net::HTTPClientException - end + Net::HTTPClientError.exception_type.should == Net::HTTPClientException Net::HTTPServerError.exception_type.should == Net::HTTPFatalError end end diff --git a/spec/ruby/library/net/http/httpresponse/value_spec.rb b/spec/ruby/library/net/http/httpresponse/value_spec.rb index 4a5930d4e5..5cd58316ef 100644 --- a/spec/ruby/library/net/http/httpresponse/value_spec.rb +++ b/spec/ruby/library/net/http/httpresponse/value_spec.rb @@ -16,12 +16,7 @@ describe "Net::HTTPResponse#value" do -> { res.value }.should raise_error(Net::HTTPRetriableError) res = Net::HTTPClientError.new("1.0", "4xx", "test response") - ruby_version_is ""..."2.6" do - -> { res.value }.should raise_error(Net::HTTPServerException) - end - ruby_version_is "2.6" do - -> { res.value }.should raise_error(Net::HTTPClientException) - end + -> { res.value }.should raise_error(Net::HTTPClientException) res = Net::HTTPServerError.new("1.0", "5xx", "test response") -> { res.value }.should raise_error(Net::HTTPFatalError) diff --git a/spec/ruby/library/objectspace/memsize_of_all_spec.rb b/spec/ruby/library/objectspace/memsize_of_all_spec.rb new file mode 100644 index 0000000000..6898862e8f --- /dev/null +++ b/spec/ruby/library/objectspace/memsize_of_all_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require 'objspace' + +describe "ObjectSpace.memsize_of_all" do + it "returns a non-zero Integer for all objects" do + ObjectSpace.memsize_of_all.should be_kind_of(Integer) + ObjectSpace.memsize_of_all.should > 0 + end + + it "returns a non-zero Integer for Class" do + ObjectSpace.memsize_of_all(Class).should be_kind_of(Integer) + ObjectSpace.memsize_of_all(Class).should > 0 + end + + it "increases when a new object is allocated" do + before = ObjectSpace.memsize_of_all(Class) + o = Class.new + after = ObjectSpace.memsize_of_all(Class) + after.should > before + end +end diff --git a/spec/ruby/library/objectspace/memsize_of_spec.rb b/spec/ruby/library/objectspace/memsize_of_spec.rb index 36d845824d..eefafbb334 100644 --- a/spec/ruby/library/objectspace/memsize_of_spec.rb +++ b/spec/ruby/library/objectspace/memsize_of_spec.rb @@ -16,7 +16,7 @@ describe "ObjectSpace.memsize_of" do ObjectSpace.memsize_of(:abc).should == 0 end - it "returns an Integer for an Object" do + it "returns a positive Integer for an Object" do obj = Object.new ObjectSpace.memsize_of(obj).should be_kind_of(Integer) ObjectSpace.memsize_of(obj).should > 0 diff --git a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb new file mode 100644 index 0000000000..3100511dc9 --- /dev/null +++ b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb @@ -0,0 +1,131 @@ +require_relative '../../spec_helper' +require 'objspace' + +describe "ObjectSpace.trace_object_allocations" do + it "runs a block" do + ScratchPad.clear + ObjectSpace.trace_object_allocations do + ScratchPad.record :a + end + ScratchPad.recorded.should == :a + end + + it "records info for allocation_class_path" do + ObjectSpace.trace_object_allocations do + o = Object.new + ObjectSpace.allocation_class_path(o).should == "Class" + a = [1, 2, 3] + ObjectSpace.allocation_class_path(a).should == nil + end + end + + it "records info for allocation_generation" do + ObjectSpace.trace_object_allocations do + o = Object.new + ObjectSpace.allocation_generation(o).should.kind_of?(Integer) + a = [1, 2, 3] + ObjectSpace.allocation_generation(a).should.kind_of?(Integer) + end + end + + it "records info for allocation_method_id" do + ObjectSpace.trace_object_allocations do + o = Object.new + ObjectSpace.allocation_method_id(o).should == :new + a = [1, 2, 3] + ObjectSpace.allocation_method_id(a).should == nil + end + end + + it "records info for allocation_sourcefile" do + ObjectSpace.trace_object_allocations do + o = Object.new + ObjectSpace.allocation_sourcefile(o).should == __FILE__ + a = [1, 2, 3] + ObjectSpace.allocation_sourcefile(a).should == __FILE__ + end + end + + it "records info for allocation_sourceline" do + ObjectSpace.trace_object_allocations do + o = Object.new + ObjectSpace.allocation_sourceline(o).should == __LINE__ - 1 + a = [1, 2, 3] + ObjectSpace.allocation_sourceline(a).should == __LINE__ - 1 + end + end + + it "can be cleared using trace_object_allocations_clear" do + ObjectSpace.trace_object_allocations do + o = Object.new + ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.trace_object_allocations_clear + ObjectSpace.allocation_class_path(o).should be_nil + end + end + + it "does not clears allocation data after returning" do + o = nil + ObjectSpace.trace_object_allocations do + o = Object.new + end + ObjectSpace.allocation_class_path(o).should == "Class" + end + + it "can be used without a block using trace_object_allocations_start and _stop" do + ObjectSpace.trace_object_allocations_start + begin + o = Object.new + ObjectSpace.allocation_class_path(o).should == "Class" + a = [1, 2, 3] + ObjectSpace.allocation_class_path(a).should == nil + ensure + ObjectSpace.trace_object_allocations_stop + end + end + + it "does not clears allocation data after trace_object_allocations_stop" do + ObjectSpace.trace_object_allocations_start + begin + o = Object.new + ensure + ObjectSpace.trace_object_allocations_stop + end + ObjectSpace.allocation_class_path(o).should == "Class" + end + + it "can be nested" do + ObjectSpace.trace_object_allocations do + ObjectSpace.trace_object_allocations do + o = Object.new + ObjectSpace.allocation_class_path(o).should == "Class" + end + end + end + + it "can be nested without a block using trace_object_allocations_start and _stop" do + ObjectSpace.trace_object_allocations_start + begin + ObjectSpace.trace_object_allocations_start + begin + o = Object.new + ObjectSpace.allocation_class_path(o).should == "Class" + ensure + ObjectSpace.trace_object_allocations_stop + end + ensure + ObjectSpace.trace_object_allocations_stop + end + end + + it "can be nested with more _stop than _start" do + ObjectSpace.trace_object_allocations_start + begin + o = Object.new + ObjectSpace.allocation_class_path(o).should == "Class" + ObjectSpace.trace_object_allocations_stop + ensure + ObjectSpace.trace_object_allocations_stop + end + end +end diff --git a/spec/ruby/library/openstruct/to_h_spec.rb b/spec/ruby/library/openstruct/to_h_spec.rb index ebdec16174..6c272bcc71 100644 --- a/spec/ruby/library/openstruct/to_h_spec.rb +++ b/spec/ruby/library/openstruct/to_h_spec.rb @@ -27,44 +27,42 @@ describe "OpenStruct#to_h" do @os.age.should == 70 end - ruby_version_is "2.6" do - context "with block" do - it "converts [key, value] pairs returned by the block to a hash" do - h = @os.to_h { |k, v| [k.to_s, v*2] } - h.should == { "name" => "John SmithJohn Smith", "age" => 140, "pension" => 600 } - end + context "with block" do + it "converts [key, value] pairs returned by the block to a hash" do + h = @os.to_h { |k, v| [k.to_s, v*2] } + h.should == { "name" => "John SmithJohn Smith", "age" => 140, "pension" => 600 } + end - it "raises ArgumentError if block returns longer or shorter array" do - -> do - @os.to_h { |k, v| [k.to_s, v*2, 1] } - end.should raise_error(ArgumentError, /element has wrong array length/) + it "raises ArgumentError if block returns longer or shorter array" do + -> do + @os.to_h { |k, v| [k.to_s, v*2, 1] } + end.should raise_error(ArgumentError, /element has wrong array length/) - -> do - @os.to_h { |k, v| [k] } - end.should raise_error(ArgumentError, /element has wrong array length/) - end + -> do + @os.to_h { |k, v| [k] } + end.should raise_error(ArgumentError, /element has wrong array length/) + end - it "raises TypeError if block returns something other than Array" do - -> do - @os.to_h { |k, v| "not-array" } - end.should raise_error(TypeError, /wrong element type String/) - end + it "raises TypeError if block returns something other than Array" do + -> do + @os.to_h { |k, v| "not-array" } + end.should raise_error(TypeError, /wrong element type String/) + end - it "coerces returned pair to Array with #to_ary" do - x = mock('x') - x.stub!(:to_ary).and_return([:b, 'b']) + it "coerces returned pair to Array with #to_ary" do + x = mock('x') + x.stub!(:to_ary).and_return([:b, 'b']) - @os.to_h { |k| x }.should == { :b => 'b' } - end + @os.to_h { |k| x }.should == { :b => 'b' } + end - it "does not coerce returned pair to Array with #to_a" do - x = mock('x') - x.stub!(:to_a).and_return([:b, 'b']) + it "does not coerce returned pair to Array with #to_a" do + x = mock('x') + x.stub!(:to_a).and_return([:b, 'b']) - -> do - @os.to_h { |k| x } - end.should raise_error(TypeError, /wrong element type MockObject/) - end + -> do + @os.to_h { |k| x } + end.should raise_error(TypeError, /wrong element type MockObject/) end end end diff --git a/spec/ruby/library/rbconfig/unicode_version_spec.rb b/spec/ruby/library/rbconfig/unicode_version_spec.rb index a6dc6478ff..fe19b10293 100644 --- a/spec/ruby/library/rbconfig/unicode_version_spec.rb +++ b/spec/ruby/library/rbconfig/unicode_version_spec.rb @@ -2,12 +2,6 @@ require_relative '../../spec_helper' require 'rbconfig' describe "RbConfig::CONFIG['UNICODE_VERSION']" do - ruby_version_is "2.5"..."2.6" do - it "is 10.0.0 for Ruby 2.5" do - RbConfig::CONFIG['UNICODE_VERSION'].should == "10.0.0" - end - end - ruby_version_is "2.6"..."2.6.2" do it "is 11.0.0 for Ruby 2.6.0 and 2.6.1" do RbConfig::CONFIG['UNICODE_VERSION'].should == "11.0.0" diff --git a/spec/ruby/library/set/filter_spec.rb b/spec/ruby/library/set/filter_spec.rb index a4dfe70d52..779254ad68 100644 --- a/spec/ruby/library/set/filter_spec.rb +++ b/spec/ruby/library/set/filter_spec.rb @@ -1,8 +1,6 @@ require_relative '../../spec_helper' require_relative 'shared/select' -ruby_version_is "2.6" do - describe "Set#filter!" do - it_behaves_like :set_select_bang, :filter! - end +describe "Set#filter!" do + it_behaves_like :set_select_bang, :filter! end diff --git a/spec/ruby/library/set/sortedset/filter_spec.rb b/spec/ruby/library/set/sortedset/filter_spec.rb index c6d881de67..3b9dcb63c9 100644 --- a/spec/ruby/library/set/sortedset/filter_spec.rb +++ b/spec/ruby/library/set/sortedset/filter_spec.rb @@ -4,9 +4,7 @@ ruby_version_is ""..."3.0" do require_relative 'shared/select' require 'set' - ruby_version_is "2.6" do - describe "SortedSet#filter!" do - it_behaves_like :sorted_set_select_bang, :filter! - end + describe "SortedSet#filter!" do + it_behaves_like :sorted_set_select_bang, :filter! end end diff --git a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb index 0363f2f8de..b6ab8a9cea 100644 --- a/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb @@ -67,4 +67,25 @@ describe "Socket::BasicSocket#recv_nonblock" do }.should raise_error(IO::WaitReadable) end end + + SocketSpecs.each_ip_protocol do |family, ip_address| + describe 'using a connected but not bound socket' do + before do + @server = Socket.new(family, :STREAM) + end + + after do + @server.close + end + + it "raises Errno::ENOTCONN" do + -> { @server.recv_nonblock(1) }.should raise_error { |e| + [Errno::ENOTCONN, Errno::EINVAL].should.include?(e.class) + } + -> { @server.recv_nonblock(1, exception: false) }.should raise_error { |e| + [Errno::ENOTCONN, Errno::EINVAL].should.include?(e.class) + } + end + end + end end diff --git a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb index 8e6c232c59..cc4275c417 100644 --- a/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb @@ -114,6 +114,21 @@ describe 'BasicSocket#recvmsg_nonblock' do end platform_is_not :windows do + describe 'using a connected but not bound socket' do + before do + @server = Socket.new(family, :STREAM) + end + + after do + @server.close + end + + it "raises Errno::ENOTCONN" do + -> { @server.recvmsg_nonblock }.should raise_error(Errno::ENOTCONN) + -> { @server.recvmsg_nonblock(exception: false) }.should raise_error(Errno::ENOTCONN) + end + end + describe 'using a connected socket' do before do @client = Socket.new(family, :STREAM) diff --git a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb index c112f2ab4a..7acfc659bd 100644 --- a/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb @@ -18,7 +18,12 @@ describe 'BasicSocket#sendmsg_nonblock' do describe 'without a destination address' do it "raises #{SocketSpecs.dest_addr_req_error}" do - -> { @client.sendmsg_nonblock('hello') }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { + @client.sendmsg_nonblock('hello') + }.should raise_error(SocketSpecs.dest_addr_req_error) + -> { + @client.sendmsg_nonblock('hello', exception: false) + }.should raise_error(SocketSpecs.dest_addr_req_error) end end diff --git a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb index 3221f0b128..011622988c 100644 --- a/spec/ruby/library/socket/socket/accept_nonblock_spec.rb +++ b/spec/ruby/library/socket/socket/accept_nonblock_spec.rb @@ -46,6 +46,7 @@ describe 'Socket#accept_nonblock' do describe 'using an unbound socket' do it 'raises Errno::EINVAL' do -> { @server.accept_nonblock }.should raise_error(Errno::EINVAL) + -> { @server.accept_nonblock(exception: false) }.should raise_error(Errno::EINVAL) end end @@ -56,6 +57,7 @@ describe 'Socket#accept_nonblock' do it 'raises Errno::EINVAL' do -> { @server.accept_nonblock }.should raise_error(Errno::EINVAL) + -> { @server.accept_nonblock(exception: false) }.should raise_error(Errno::EINVAL) end end @@ -64,6 +66,7 @@ describe 'Socket#accept_nonblock' do @server.close -> { @server.accept_nonblock }.should raise_error(IOError) + -> { @server.accept_nonblock(exception: false) }.should raise_error(IOError) end end |