diff options
Diffstat (limited to 'spec/ruby/core/thread')
-rw-r--r-- | spec/ruby/core/thread/backtrace_locations_spec.rb | 23 | ||||
-rw-r--r-- | spec/ruby/core/thread/backtrace_spec.rb | 34 |
2 files changed, 48 insertions, 9 deletions
diff --git a/spec/ruby/core/thread/backtrace_locations_spec.rb b/spec/ruby/core/thread/backtrace_locations_spec.rb index 211858899c..ead4be2d8c 100644 --- a/spec/ruby/core/thread/backtrace_locations_spec.rb +++ b/spec/ruby/core/thread/backtrace_locations_spec.rb @@ -22,28 +22,33 @@ describe "Thread#backtrace_locations" do it "can be called with a number of locations to omit" do locations1 = Thread.current.backtrace_locations locations2 = Thread.current.backtrace_locations(2) - locations1[2..-1].length.should == locations2.length - locations1[2..-1].map(&:to_s).should == locations2.map(&:to_s) + locations2.length.should == locations1[2..-1].length + locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s) end it "can be called with a maximum number of locations to return as second parameter" do locations1 = Thread.current.backtrace_locations locations2 = Thread.current.backtrace_locations(2, 3) - locations1[2..4].map(&:to_s).should == locations2.map(&:to_s) + locations2.map(&:to_s).should == locations1[2..4].map(&:to_s) end it "can be called with a range" do locations1 = Thread.current.backtrace_locations locations2 = Thread.current.backtrace_locations(2..4) - locations1[2..4].map(&:to_s).should == locations2.map(&:to_s) + locations2.map(&:to_s).should == locations1[2..4].map(&:to_s) end it "can be called with a range whose end is negative" do - locations1 = Thread.current.backtrace_locations - locations2 = Thread.current.backtrace_locations(2..-1) - locations3 = Thread.current.backtrace_locations(2..-2) - locations1[2..-1].map(&:to_s).should == locations2.map(&:to_s) - locations1[2..-2].map(&:to_s).should == locations3.map(&:to_s) + Thread.current.backtrace_locations(2..-1).map(&:to_s).should == Thread.current.backtrace_locations[2..-1].map(&:to_s) + Thread.current.backtrace_locations(2..-2).map(&:to_s).should == Thread.current.backtrace_locations[2..-2].map(&:to_s) + end + + ruby_version_is "2.6" do + it "can be called with an endless range" do + locations1 = Thread.current.backtrace_locations(0) + locations2 = Thread.current.backtrace_locations(eval("(2..)")) + locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s) + end end it "returns nil if omitting more locations than available" do diff --git a/spec/ruby/core/thread/backtrace_spec.rb b/spec/ruby/core/thread/backtrace_spec.rb index 84ed574d5c..9001b1b7eb 100644 --- a/spec/ruby/core/thread/backtrace_spec.rb +++ b/spec/ruby/core/thread/backtrace_spec.rb @@ -32,4 +32,38 @@ describe "Thread#backtrace" do t.join backtrace.should be_kind_of(Array) end + + it "can be called with a number of locations to omit" do + locations1 = Thread.current.backtrace + locations2 = Thread.current.backtrace(2) + locations1[2..-1].length.should == locations2.length + locations1[2..-1].map(&:to_s).should == locations2.map(&:to_s) + end + + it "can be called with a maximum number of locations to return as second parameter" do + locations1 = Thread.current.backtrace + locations2 = Thread.current.backtrace(2, 3) + locations1[2..4].map(&:to_s).should == locations2.map(&:to_s) + end + + it "can be called with a range" do + locations1 = Thread.current.backtrace + locations2 = Thread.current.backtrace(2..4) + locations1[2..4].map(&:to_s).should == locations2.map(&:to_s) + end + + it "can be called with a range whose end is negative" do + Thread.current.backtrace(2..-1).should == Thread.current.backtrace[2..-1] + Thread.current.backtrace(2..-2).should == Thread.current.backtrace[2..-2] + end + + it "returns nil if omitting more locations than available" do + Thread.current.backtrace(100).should == nil + Thread.current.backtrace(100..-1).should == nil + end + + it "returns [] if omitting exactly the number of locations available" do + omit = Thread.current.backtrace.length + Thread.current.backtrace(omit).should == [] + end end |