diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-27 20:38:57 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-11-27 20:38:57 +0000 |
commit | 50441014ffd3645f258e56b9415b7787c910408b (patch) | |
tree | 3d5eef5ad1ea7e389dc51fc87437664b984ac184 /spec/ruby/core | |
parent | 49cd16bfaf4f03885058ce748119bc8ea2de735a (diff) |
Update to ruby/spec@cdd6ff7
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core')
48 files changed, 439 insertions, 25 deletions
diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb index b57e16ec94..8180ce38be 100644 --- a/spec/ruby/core/dir/home_spec.rb +++ b/spec/ruby/core/dir/home_spec.rb @@ -15,8 +15,8 @@ describe "Dir.home" do end platform_is_not :windows do - it "returns the named user's home directory as a string if called with an argument" do - Dir.home(ENV['USER']).should == ENV['HOME'] + it "returns the named user's home directory, from the user database, as a string if called with an argument" do + Dir.home(ENV['USER']).should == `echo ~#{ENV['USER']}`.chomp end end diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb index 99279aec85..b7363fefa9 100644 --- a/spec/ruby/core/file/expand_path_spec.rb +++ b/spec/ruby/core/file/expand_path_spec.rb @@ -88,7 +88,8 @@ describe "File.expand_path" do platform_is_not :windows do before do - @home = ENV['HOME'].chomp('/') + @var_home = ENV['HOME'].chomp('/') + @db_home = `echo ~#{ENV['USER']}`.chomp end # FIXME: these are insane! @@ -107,9 +108,9 @@ describe "File.expand_path" do File.expand_path('./////').should == Dir.pwd File.expand_path('.').should == Dir.pwd File.expand_path(Dir.pwd).should == Dir.pwd - File.expand_path('~/').should == @home - File.expand_path('~/..badfilename').should == "#{@home}/..badfilename" - File.expand_path('~/a','~/b').should == "#{@home}/a" + File.expand_path('~/').should == @var_home + File.expand_path('~/..badfilename').should == "#{@var_home}/..badfilename" + File.expand_path('~/a','~/b').should == "#{@var_home}/a" File.expand_path('..').should == File.dirname(Dir.pwd) end @@ -126,8 +127,11 @@ describe "File.expand_path" do end it "expands ~ENV['USER'] to the user's home directory" do - File.expand_path("~#{ENV['USER']}").should == @home - File.expand_path("~#{ENV['USER']}/a").should == "#{@home}/a" + File.expand_path("~#{ENV['USER']}").should == @db_home + end + + it "expands ~ENV['USER']/a to a in the user's home directory" do + File.expand_path("~#{ENV['USER']}/a").should == "#{@db_home}/a" end it "does not expand ~ENV['USER'] when it's not at the start" do @@ -135,7 +139,7 @@ describe "File.expand_path" do end it "expands ../foo with ~/dir as base dir to /path/to/user/home/foo" do - File.expand_path('../foo', '~/dir').should == "#{@home}/foo" + File.expand_path('../foo', '~/dir').should == "#{@var_home}/foo" end end @@ -239,4 +243,19 @@ platform_is_not :windows do lambda { File.expand_path("~") }.should raise_error(ArgumentError) end end + + describe "File.expand_path with a non-absolute HOME" do + before :each do + @home = ENV["HOME"] + end + + after :each do + ENV["HOME"] = @home + end + + it "raises an ArgumentError" do + ENV["HOME"] = "non-absolute" + lambda { File.expand_path("~") }.should raise_error(ArgumentError, 'non-absolute home') + end + end end diff --git a/spec/ruby/core/gc/count_spec.rb b/spec/ruby/core/gc/count_spec.rb index 11648ac9be..af2fbbe713 100644 --- a/spec/ruby/core/gc/count_spec.rb +++ b/spec/ruby/core/gc/count_spec.rb @@ -4,4 +4,14 @@ describe "GC.count" do it "returns an integer" do GC.count.should be_kind_of(Integer) end + + it "increases as collections are run" do + count_before = GC.count + i = 0 + while GC.count <= count_before and i < 10 + GC.start + i += 1 + end + GC.count.should > count_before + end end diff --git a/spec/ruby/core/hash/shift_spec.rb b/spec/ruby/core/hash/shift_spec.rb index 9421a77537..8cf3f4025a 100644 --- a/spec/ruby/core/hash/shift_spec.rb +++ b/spec/ruby/core/hash/shift_spec.rb @@ -61,4 +61,19 @@ describe "Hash#shift" do lambda { HashSpecs.frozen_hash.shift }.should raise_error(frozen_error_class) lambda { HashSpecs.empty_frozen_hash.shift }.should raise_error(frozen_error_class) end + + it "works when the hash is at capacity" do + # We try a wide range of sizes in hopes that this will cover all implementationss base Hash size. + results = [] + 1.upto(100) do |n| + h = {} + n.times do |i| + h[i] = i + end + h.shift + results << h.size + end + + results.should == 0.upto(99).to_a + end end diff --git a/spec/ruby/core/integer/gcd_spec.rb b/spec/ruby/core/integer/gcd_spec.rb index 69f711d4c5..238bf66cc0 100644 --- a/spec/ruby/core/integer/gcd_spec.rb +++ b/spec/ruby/core/integer/gcd_spec.rb @@ -43,6 +43,17 @@ describe "Integer#gcd" do bignum.gcd(99).should == 99 end + it "doesn't cause an integer overflow" do + [2 ** (1.size * 8 - 2), 0x8000000000000000].each do |max| + [max - 1, max, max + 1].each do |num| + num.gcd(num).should == num + (-num).gcd(num).should == num + (-num).gcd(-num).should == num + num.gcd(-num).should == num + end + end + end + it "raises an ArgumentError if not given an argument" do lambda { 12.gcd }.should raise_error(ArgumentError) end diff --git a/spec/ruby/core/io/syswrite_spec.rb b/spec/ruby/core/io/syswrite_spec.rb index 1b1477bc6e..a4dc8328aa 100644 --- a/spec/ruby/core/io/syswrite_spec.rb +++ b/spec/ruby/core/io/syswrite_spec.rb @@ -55,7 +55,7 @@ describe "IO#syswrite on a pipe" do r, w = IO.pipe begin w.nonblock = true - larger_than_pipe_capacity = 100 * 1024 + larger_than_pipe_capacity = 2 * 1024 * 1024 written = w.syswrite("a"*larger_than_pipe_capacity) written.should > 0 written.should < larger_than_pipe_capacity diff --git a/spec/ruby/core/io/ungetbyte_spec.rb b/spec/ruby/core/io/ungetbyte_spec.rb index b7de1b7a6d..2639d24c45 100644 --- a/spec/ruby/core/io/ungetbyte_spec.rb +++ b/spec/ruby/core/io/ungetbyte_spec.rb @@ -50,7 +50,7 @@ describe "IO#ungetbyte" do end ruby_version_is '2.6' do - it "is an RangeError if the integr is not in 8bit" do + it "is an RangeError if the integer is not in 8bit" do for i in [4095, 0x4f7574206f6620636861722072616e6765] do lambda { @io.ungetbyte(i) }.should raise_error(RangeError) end diff --git a/spec/ruby/core/main/using_spec.rb b/spec/ruby/core/main/using_spec.rb index 922ce58cbd..1fb812f5cc 100644 --- a/spec/ruby/core/main/using_spec.rb +++ b/spec/ruby/core/main/using_spec.rb @@ -6,6 +6,7 @@ describe "main.using" do lambda do eval('using', TOPLEVEL_BINDING) end.should raise_error(ArgumentError) + lambda do eval('using "foo"', TOPLEVEL_BINDING) end.should raise_error(TypeError) diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb index 3fa493b1da..97ea0a706d 100644 --- a/spec/ruby/core/module/refine_spec.rb +++ b/spec/ruby/core/module/refine_spec.rb @@ -717,4 +717,19 @@ describe "Module#refine" do result.should == "hello from refinement" end end + + it 'does not list methods defined only in refinement' do + refine_object = Module.new do + refine Object do + def refinement_only_method + end + end + end + spec = self + klass = Class.new { instance_methods.should_not spec.send(:include, :refinement_only_method) } + instance = klass.new + instance.methods.should_not include :refinement_only_method + instance.respond_to?(:refinement_only_method).should == false + -> { instance.method :refinement_only_method }.should raise_error(NameError) + end end diff --git a/spec/ruby/core/mutex/lock_spec.rb b/spec/ruby/core/mutex/lock_spec.rb index a272b16a32..a1a2972d8c 100644 --- a/spec/ruby/core/mutex/lock_spec.rb +++ b/spec/ruby/core/mutex/lock_spec.rb @@ -11,22 +11,15 @@ describe "Mutex#lock" do m.unlock end - it "waits if the lock is not available" do + it "blocks the caller if already locked" do m = Mutex.new - m.lock + lambda { m.lock }.should block_caller + end - th = Thread.new do - m.lock - ScratchPad.record :after_lock - end - - Thread.pass while th.status and th.status != "sleep" - - ScratchPad.recorded.should be_nil - m.unlock - th.join - ScratchPad.recorded.should == :after_lock + it "does not block the caller if not locked" do + m = Mutex.new + lambda { m.lock }.should_not block_caller end # Unable to find a specific ticket but behavior change may be diff --git a/spec/ruby/core/mutex/synchronize_spec.rb b/spec/ruby/core/mutex/synchronize_spec.rb index 206b14e828..e3dad508b8 100644 --- a/spec/ruby/core/mutex/synchronize_spec.rb +++ b/spec/ruby/core/mutex/synchronize_spec.rb @@ -24,4 +24,43 @@ describe "Mutex#synchronize" do th.join m1.locked?.should be_false end + + it "blocks the caller if already locked" do + m = Mutex.new + m.lock + lambda { m.synchronize { } }.should block_caller + end + + it "does not block the caller if not locked" do + m = Mutex.new + lambda { m.synchronize { } }.should_not block_caller + end + + it "blocks the caller if another thread is also in the synchronize block" do + m = Mutex.new + q1 = Queue.new + q2 = Queue.new + + t = Thread.new { + m.synchronize { + q1.push :ready + q2.pop + } + } + + q1.pop.should == :ready + + lambda { m.synchronize { } }.should block_caller + + q2.push :done + t.join + end + + it "is not recursive" do + m = Mutex.new + + m.synchronize do + lambda { m.synchronize { } }.should raise_error(ThreadError) + end + end end diff --git a/spec/ruby/core/process/clock_gettime_spec.rb b/spec/ruby/core/process/clock_gettime_spec.rb new file mode 100644 index 0000000000..165f0db730 --- /dev/null +++ b/spec/ruby/core/process/clock_gettime_spec.rb @@ -0,0 +1,35 @@ +require_relative '../../spec_helper' + +describe "Process.clock_gettime" do + describe 'time units' do + it 'handles a fixed set of time units' do + [:nanosecond, :microsecond, :millisecond, :second].each do |unit| + Process.clock_gettime(Process::CLOCK_MONOTONIC, unit).should be_kind_of(Integer) + end + + [:float_microsecond, :float_millisecond, :float_second].each do |unit| + Process.clock_gettime(Process::CLOCK_MONOTONIC, unit).should be_an_instance_of(Float) + end + end + + it 'raises an ArgumentError for an invalid time unit' do + lambda { Process.clock_gettime(Process::CLOCK_MONOTONIC, :bad) }.should raise_error(ArgumentError) + end + + it 'defaults to :float_second' do + t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC) + t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) + + t1.should be_an_instance_of(Float) + t2.should be_close(t1, 2.0) # 2.0 is chosen arbitrarily to allow for time skew without admitting failure cases, which would be off by an order of magnitude. + end + + it 'uses the default time unit (:float_second) when passed nil' do + t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC, nil) + t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second) + + t1.should be_an_instance_of(Float) + t2.should be_close(t1, 2.0) # 2.0 is chosen arbitrarily to allow for time skew without admitting failure cases, which would be off by an order of magnitude. + end + end +end diff --git a/spec/ruby/core/queue/append_spec.rb b/spec/ruby/core/queue/append_spec.rb new file mode 100644 index 0000000000..34165a7506 --- /dev/null +++ b/spec/ruby/core/queue/append_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/enque' + +describe "Queue#<<" do + it_behaves_like :queue_enq, :<<, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/clear_spec.rb b/spec/ruby/core/queue/clear_spec.rb new file mode 100644 index 0000000000..3245e4cb83 --- /dev/null +++ b/spec/ruby/core/queue/clear_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/clear' + +describe "Queue#clear" do + it_behaves_like :queue_clear, :clear, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/close_spec.rb b/spec/ruby/core/queue/close_spec.rb new file mode 100644 index 0000000000..c0d774cd74 --- /dev/null +++ b/spec/ruby/core/queue/close_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/close' + +describe "Queue#close" do + it_behaves_like :queue_close, :close, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/closed_spec.rb b/spec/ruby/core/queue/closed_spec.rb new file mode 100644 index 0000000000..10d552996d --- /dev/null +++ b/spec/ruby/core/queue/closed_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/closed' + +describe "Queue#closed?" do + it_behaves_like :queue_closed?, :closed?, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/deq_spec.rb b/spec/ruby/core/queue/deq_spec.rb new file mode 100644 index 0000000000..9510978eac --- /dev/null +++ b/spec/ruby/core/queue/deq_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/deque' + +describe "Queue#deq" do + it_behaves_like :queue_deq, :deq, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/empty_spec.rb b/spec/ruby/core/queue/empty_spec.rb new file mode 100644 index 0000000000..55ca777466 --- /dev/null +++ b/spec/ruby/core/queue/empty_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/empty' + +describe "Queue#empty?" do + it_behaves_like :queue_empty?, :empty?, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/enq_spec.rb b/spec/ruby/core/queue/enq_spec.rb new file mode 100644 index 0000000000..c69c496fbc --- /dev/null +++ b/spec/ruby/core/queue/enq_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/enque' + +describe "Queue#enq" do + it_behaves_like :queue_enq, :enq, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/length_spec.rb b/spec/ruby/core/queue/length_spec.rb new file mode 100644 index 0000000000..25399b2b76 --- /dev/null +++ b/spec/ruby/core/queue/length_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/length' + +describe "Queue#length" do + it_behaves_like :queue_length, :length, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/num_waiting_spec.rb b/spec/ruby/core/queue/num_waiting_spec.rb new file mode 100644 index 0000000000..edc0c37a82 --- /dev/null +++ b/spec/ruby/core/queue/num_waiting_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/num_waiting' + +describe "Queue#num_waiting" do + it_behaves_like :queue_num_waiting, :num_waiting, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/pop_spec.rb b/spec/ruby/core/queue/pop_spec.rb new file mode 100644 index 0000000000..1ce9231685 --- /dev/null +++ b/spec/ruby/core/queue/pop_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/deque' + +describe "Queue#pop" do + it_behaves_like :queue_deq, :pop, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/push_spec.rb b/spec/ruby/core/queue/push_spec.rb new file mode 100644 index 0000000000..e936f9d282 --- /dev/null +++ b/spec/ruby/core/queue/push_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/enque' + +describe "Queue#push" do + it_behaves_like :queue_enq, :push, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/shift_spec.rb b/spec/ruby/core/queue/shift_spec.rb new file mode 100644 index 0000000000..f84058e1df --- /dev/null +++ b/spec/ruby/core/queue/shift_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/deque' + +describe "Queue#shift" do + it_behaves_like :queue_deq, :shift, -> { Queue.new } +end diff --git a/spec/ruby/core/queue/size_spec.rb b/spec/ruby/core/queue/size_spec.rb new file mode 100644 index 0000000000..f528dfe797 --- /dev/null +++ b/spec/ruby/core/queue/size_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/length' + +describe "Queue#size" do + it_behaves_like :queue_length, :size, -> { Queue.new } +end diff --git a/spec/ruby/core/signal/list_spec.rb b/spec/ruby/core/signal/list_spec.rb index 2af9c50597..56ad6828fe 100644 --- a/spec/ruby/core/signal/list_spec.rb +++ b/spec/ruby/core/signal/list_spec.rb @@ -61,4 +61,8 @@ describe "Signal.list" do it "includes the EXIT key with a value of zero" do Signal.list["EXIT"].should == 0 end + + it "includes the KILL key with a value of nine" do + Signal.list["KILL"].should == 9 + end end diff --git a/spec/ruby/core/sizedqueue/append_spec.rb b/spec/ruby/core/sizedqueue/append_spec.rb new file mode 100644 index 0000000000..ff96b46d2c --- /dev/null +++ b/spec/ruby/core/sizedqueue/append_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/enque' +require_relative '../../shared/sizedqueue/enque' + +describe "SizedQueue#<<" do + it_behaves_like :queue_enq, :<<, -> { SizedQueue.new(10) } +end + +describe "SizedQueue#<<" do + it_behaves_like :sizedqueue_enq, :<<, ->(n) { SizedQueue.new(n) } +end diff --git a/spec/ruby/core/sizedqueue/clear_spec.rb b/spec/ruby/core/sizedqueue/clear_spec.rb new file mode 100644 index 0000000000..abae01c6c0 --- /dev/null +++ b/spec/ruby/core/sizedqueue/clear_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/clear' + +describe "SizedQueue#clear" do + it_behaves_like :queue_clear, :clear, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/close_spec.rb b/spec/ruby/core/sizedqueue/close_spec.rb new file mode 100644 index 0000000000..0e0af851cb --- /dev/null +++ b/spec/ruby/core/sizedqueue/close_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/close' + +describe "SizedQueue#close" do + it_behaves_like :queue_close, :close, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/closed_spec.rb b/spec/ruby/core/sizedqueue/closed_spec.rb new file mode 100644 index 0000000000..4b90da1faa --- /dev/null +++ b/spec/ruby/core/sizedqueue/closed_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/closed' + +describe "SizedQueue#closed?" do + it_behaves_like :queue_closed?, :closed?, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/deq_spec.rb b/spec/ruby/core/sizedqueue/deq_spec.rb new file mode 100644 index 0000000000..5e1bd9f746 --- /dev/null +++ b/spec/ruby/core/sizedqueue/deq_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/deque' + +describe "SizedQueue#deq" do + it_behaves_like :queue_deq, :deq, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/empty_spec.rb b/spec/ruby/core/sizedqueue/empty_spec.rb new file mode 100644 index 0000000000..9b0d4ff013 --- /dev/null +++ b/spec/ruby/core/sizedqueue/empty_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/empty' + +describe "SizedQueue#empty?" do + it_behaves_like :queue_empty?, :empty?, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/enq_spec.rb b/spec/ruby/core/sizedqueue/enq_spec.rb new file mode 100644 index 0000000000..11c65ec14d --- /dev/null +++ b/spec/ruby/core/sizedqueue/enq_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/enque' +require_relative '../../shared/sizedqueue/enque' + +describe "SizedQueue#enq" do + it_behaves_like :queue_enq, :enq, -> { SizedQueue.new(10) } +end + +describe "SizedQueue#enq" do + it_behaves_like :sizedqueue_enq, :enq, ->(n) { SizedQueue.new(n) } +end diff --git a/spec/ruby/core/sizedqueue/length_spec.rb b/spec/ruby/core/sizedqueue/length_spec.rb new file mode 100644 index 0000000000..b93e7f8997 --- /dev/null +++ b/spec/ruby/core/sizedqueue/length_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/length' + +describe "SizedQueue#length" do + it_behaves_like :queue_length, :length, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/max_spec.rb b/spec/ruby/core/sizedqueue/max_spec.rb new file mode 100644 index 0000000000..b65a67eeb0 --- /dev/null +++ b/spec/ruby/core/sizedqueue/max_spec.rb @@ -0,0 +1,10 @@ +require_relative '../../spec_helper' +require_relative '../../shared/sizedqueue/max' + +describe "SizedQueue#max" do + it_behaves_like :sizedqueue_max, :max, ->(n) { SizedQueue.new(n) } +end + +describe "SizedQueue#max=" do + it_behaves_like :sizedqueue_max=, :max=, ->(n) { SizedQueue.new(n) } +end diff --git a/spec/ruby/core/sizedqueue/new_spec.rb b/spec/ruby/core/sizedqueue/new_spec.rb new file mode 100644 index 0000000000..8febbfa63b --- /dev/null +++ b/spec/ruby/core/sizedqueue/new_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/sizedqueue/new' + +describe "SizedQueue.new" do + it_behaves_like :sizedqueue_new, :new, ->(*n) { SizedQueue.new(*n) } +end diff --git a/spec/ruby/core/sizedqueue/num_waiting_spec.rb b/spec/ruby/core/sizedqueue/num_waiting_spec.rb new file mode 100644 index 0000000000..cbbbb2d062 --- /dev/null +++ b/spec/ruby/core/sizedqueue/num_waiting_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/sizedqueue/num_waiting' + +describe "SizedQueue#num_waiting" do + it_behaves_like :sizedqueue_num_waiting, :new, ->(n) { SizedQueue.new(n) } +end diff --git a/spec/ruby/core/sizedqueue/pop_spec.rb b/spec/ruby/core/sizedqueue/pop_spec.rb new file mode 100644 index 0000000000..a0cf6f509c --- /dev/null +++ b/spec/ruby/core/sizedqueue/pop_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/deque' + +describe "SizedQueue#pop" do + it_behaves_like :queue_deq, :pop, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/push_spec.rb b/spec/ruby/core/sizedqueue/push_spec.rb new file mode 100644 index 0000000000..5f92c5a2b7 --- /dev/null +++ b/spec/ruby/core/sizedqueue/push_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/enque' +require_relative '../../shared/sizedqueue/enque' + +describe "SizedQueue#push" do + it_behaves_like :queue_enq, :push, -> { SizedQueue.new(10) } +end + +describe "SizedQueue#push" do + it_behaves_like :sizedqueue_enq, :push, ->(n) { SizedQueue.new(n) } +end diff --git a/spec/ruby/core/sizedqueue/shift_spec.rb b/spec/ruby/core/sizedqueue/shift_spec.rb new file mode 100644 index 0000000000..5138e68258 --- /dev/null +++ b/spec/ruby/core/sizedqueue/shift_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/deque' + +describe "SizedQueue#shift" do + it_behaves_like :queue_deq, :shift, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/sizedqueue/size_spec.rb b/spec/ruby/core/sizedqueue/size_spec.rb new file mode 100644 index 0000000000..dfa76faabe --- /dev/null +++ b/spec/ruby/core/sizedqueue/size_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../spec_helper' +require_relative '../../shared/queue/length' + +describe "SizedQueue#size" do + it_behaves_like :queue_length, :size, -> { SizedQueue.new(10) } +end diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb index 7c33489779..01231e85fb 100644 --- a/spec/ruby/core/struct/new_spec.rb +++ b/spec/ruby/core/struct/new_spec.rb @@ -130,6 +130,17 @@ describe "Struct.new" do it "fails with too many arguments" do lambda { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError) end + + it "passes a hash as a normal argument" do + type = Struct.new(:args) + + obj = type.new(keyword: :arg) + obj2 = type.new(*[{keyword: :arg}]) + + obj.should == obj2 + obj.args.should == {keyword: :arg} + obj2.args.should == {keyword: :arg} + end end ruby_version_is "2.5" do @@ -163,6 +174,12 @@ describe "Struct.new" do @struct_with_kwa.new("elefant", 4) }.should raise_error(ArgumentError, /wrong number of arguments/) end + + it "raises ArgumentError when passed a single non-hash argument" do + -> { + @struct_with_kwa.new("elefant") + }.should raise_error(ArgumentError, /wrong number of arguments/) + end end end diff --git a/spec/ruby/core/thread/exclusive_spec.rb b/spec/ruby/core/thread/exclusive_spec.rb index 522a43cac5..9de427fb52 100644 --- a/spec/ruby/core/thread/exclusive_spec.rb +++ b/spec/ruby/core/thread/exclusive_spec.rb @@ -14,5 +14,29 @@ describe "Thread.exclusive" do Thread.exclusive { :result }.should == :result end - it "needs to be reviewed for spec completeness" + it "blocks the caller if another thread is also in an exclusive block" do + m = Mutex.new + q1 = Queue.new + q2 = Queue.new + + t = Thread.new { + Thread.exclusive { + q1.push :ready + q2.pop + } + } + + q1.pop.should == :ready + + lambda { Thread.exclusive { } }.should block_caller + + q2.push :done + t.join + end + + it "is not recursive" do + Thread.exclusive do + lambda { Thread.exclusive { } }.should raise_error(ThreadError) + end + end end diff --git a/spec/ruby/core/thread/raise_spec.rb b/spec/ruby/core/thread/raise_spec.rb index 0b18369cb9..38571854ef 100644 --- a/spec/ruby/core/thread/raise_spec.rb +++ b/spec/ruby/core/thread/raise_spec.rb @@ -78,6 +78,30 @@ describe "Thread#raise on a sleeping thread" do end -> { t.value }.should raise_error(RuntimeError) end + + it "re-raises a previously rescued exception without overwriting the backtrace" do + t = Thread.new do + -> { # To make sure there is at least one entry in the call stack + begin + sleep + rescue => e + e + end + }.call + end + + ThreadSpecs.spin_until_sleeping(t) + + begin + initial_raise_line = __LINE__; raise 'raised' + rescue => raised + raise_again_line = __LINE__; t.raise raised + raised_again = t.value + + raised_again.backtrace.first.should include("#{__FILE__}:#{initial_raise_line}:") + raised_again.backtrace.first.should_not include("#{__FILE__}:#{raise_again_line}:") + end + end end describe "Thread#raise on a running thread" do diff --git a/spec/ruby/core/time/nsec_spec.rb b/spec/ruby/core/time/nsec_spec.rb index fb3df6394c..9338eb435a 100644 --- a/spec/ruby/core/time/nsec_spec.rb +++ b/spec/ruby/core/time/nsec_spec.rb @@ -24,4 +24,8 @@ describe "Time#nsec" do it "returns the nanoseconds part of a Time constructed with an Rational number of microseconds" do Time.at(0, Rational(99, 10)).nsec.should == 9900 end + + it "returns a positive value for dates before the epoch" do + Time.utc(1969, 11, 12, 13, 18, 57, 404240).nsec.should == 404240000 + end end diff --git a/spec/ruby/core/time/shared/time_params.rb b/spec/ruby/core/time/shared/time_params.rb index 120d8d3af1..39245116b0 100644 --- a/spec/ruby/core/time/shared/time_params.rb +++ b/spec/ruby/core/time/shared/time_params.rb @@ -230,6 +230,10 @@ describe :time_params_microseconds, shared: true do t.usec.should == 123 end + it "raises an ArgumentError for out of range microsecond" do + lambda { Time.send(@method, 2000, 1, 1, 20, 15, 1, 1000000) }.should raise_error(ArgumentError) + end + it "handles fractional microseconds as a Float" do t = Time.send(@method, 2000, 1, 1, 20, 15, 1, 1.75) t.usec.should == 1 diff --git a/spec/ruby/core/time/usec_spec.rb b/spec/ruby/core/time/usec_spec.rb index 44cd2047e7..6ea52f5e79 100644 --- a/spec/ruby/core/time/usec_spec.rb +++ b/spec/ruby/core/time/usec_spec.rb @@ -36,4 +36,8 @@ describe "Time#usec" do it "returns the microseconds for time created by Time#local" do Time.local(1,2,3,4,5,Rational(6.78)).usec.should == 780000 end + + it "returns a positive value for dates before the epoch" do + Time.utc(1969, 11, 12, 13, 18, 57, 404240).usec.should == 404240 + end end diff --git a/spec/ruby/core/warning/warn_spec.rb b/spec/ruby/core/warning/warn_spec.rb index 9ebe018d8f..2844d97e76 100644 --- a/spec/ruby/core/warning/warn_spec.rb +++ b/spec/ruby/core/warning/warn_spec.rb @@ -8,6 +8,14 @@ describe "Warning.warn" do }.should complain("Chunky bacon!") end + it "does not add a newline" do + ruby_exe("Warning.warn('test')", args: "2>&1").should == "test" + end + + it "returns nil" do + ruby_exe("p Warning.warn('test')", args: "2>&1").should == "testnil\n" + end + it "extends itself" do Warning.singleton_class.ancestors.should include(Warning) end |