diff options
author | Jeremy Evans <code@jeremyevans.net> | 2022-01-14 13:02:46 -0800 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2022-02-17 08:54:07 -0800 |
commit | 4c366ec9775eb6acb3fcb3b88038d051512c75a2 (patch) | |
tree | b36d45da1bdb3ccce9ca0d9d4a86852c23fa9299 /test | |
parent | 4113862c0068a8a95d752f5fdf14980f92cd41d7 (diff) |
Add Thread.each_caller_location
This method takes a block and yields Thread::Backtrace::Location
objects to the block. It does not take arguments, and always
starts at the default frame that caller_locations would start at.
Implements [Feature #16663]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5445
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_backtrace.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb index aa79db24cb..bb0562c0bb 100644 --- a/test/ruby/test_backtrace.rb +++ b/test/ruby/test_backtrace.rb @@ -154,6 +154,35 @@ class TestBacktrace < Test::Unit::TestCase assert_equal caller(0), caller(0, nil) end + def test_each_backtrace_location + i = 0 + cl = caller_locations(1, 1)[0]; ecl = Thread.each_caller_location{|x| i+=1; break x if i == 1} + assert_equal(cl.to_s, ecl.to_s) + assert_kind_of(Thread::Backtrace::Location, ecl) + + i = 0 + ary = [] + cllr = caller_locations(1, 2); last = Thread.each_caller_location{|x| ary << x; i+=1; break x if i == 2} + assert_equal(cllr.map(&:to_s), ary.map(&:to_s)) + assert_kind_of(Thread::Backtrace::Location, last) + + i = 0 + ary = [] + ->{->{ + cllr = caller_locations(1, 2); last = Thread.each_caller_location{|x| ary << x; i+=1; break x if i == 2} + }.()}.() + assert_equal(cllr.map(&:to_s), ary.map(&:to_s)) + assert_kind_of(Thread::Backtrace::Location, last) + + cllr = caller_locations(1, 2); ary = Thread.to_enum(:each_caller_location).to_a[2..3] + assert_equal(cllr.map(&:to_s), ary.map(&:to_s)) + + ecl = Thread.to_enum(:each_caller_location) + assert_raise(StopIteration) { + ecl.next + } + end + def test_caller_locations_first_label def self.label caller_locations.first.label |