mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f6f769d26d
(1) Class name: RubyVM::FrameInfo -> RubyVM::Backtrace::Location. (2) Method name: RubyVM::FrameInfo.caller -> Kernel.caller_locations. (3) Instance methods of RubyVM::FrameInfo (RubyVM::Backtrace::Location) (3-1) name -> label (3-2) basename -> base_label (basename is confusing with File.basename) (3-3) line_no -> lineno (We have already similar name File#lineno, commented by kou [ruby-dev:45686]). (3-4) filename -> path. (3-5) filepath -> absolute_path. (3-5) iseq -> removed (we will make other APIs to access iseq and other information of frame for debugging). * test/ruby/test_backtrace.rb: apply above changes. And apply comment from kou [ruby-dev:45686]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
105 lines
2.2 KiB
Ruby
105 lines
2.2 KiB
Ruby
|
|
require 'test/unit'
|
|
|
|
class TestBacktrace < Test::Unit::TestCase
|
|
def test_exception
|
|
bt = Fiber.new{
|
|
begin
|
|
raise
|
|
rescue => e
|
|
e.backtrace
|
|
end
|
|
}.resume
|
|
assert_equal(1, bt.size)
|
|
assert_match(/.+:\d+:.+/, bt[0])
|
|
end
|
|
|
|
def test_caller_lev
|
|
cs = []
|
|
Fiber.new{
|
|
Proc.new{
|
|
cs << caller(0)
|
|
cs << caller(1)
|
|
cs << caller(2)
|
|
cs << caller(3)
|
|
cs << caller(4)
|
|
cs << caller(5)
|
|
}.call
|
|
}.resume
|
|
assert_equal(3, cs[0].size)
|
|
assert_equal(2, cs[1].size)
|
|
assert_equal(1, cs[2].size)
|
|
assert_equal(0, cs[3].size)
|
|
assert_equal(nil, cs[4])
|
|
|
|
#
|
|
max = 10
|
|
rec = lambda{|n|
|
|
if n > 0
|
|
1.times{
|
|
rec[n-1]
|
|
}
|
|
else
|
|
(max*3).times{|i|
|
|
total_size = caller(0).size
|
|
c = caller(i)
|
|
if c
|
|
assert_equal(total_size - i, caller(i).size, "[ruby-dev:45673]")
|
|
end
|
|
}
|
|
end
|
|
}
|
|
bt = Fiber.new{
|
|
rec[max]
|
|
}.resume
|
|
end
|
|
|
|
def test_caller_lev_and_n
|
|
m = 10
|
|
rec = lambda{|n|
|
|
if n < 0
|
|
(m*6).times{|lev|
|
|
(m*6).times{|n|
|
|
t = caller(0).size
|
|
r = caller(lev, n)
|
|
r = r.size if r.respond_to? :size
|
|
|
|
# STDERR.puts [t, lev, n, r].inspect
|
|
if n == 0
|
|
assert_equal(0, r, [t, lev, n, r].inspect)
|
|
elsif t < lev
|
|
assert_equal(nil, r, [t, lev, n, r].inspect)
|
|
else
|
|
if t - lev > n
|
|
assert_equal(n, r, [t, lev, n, r].inspect)
|
|
else
|
|
assert_equal(t - lev, r, [t, lev, n, r].inspect)
|
|
end
|
|
end
|
|
}
|
|
}
|
|
else
|
|
rec[n-1]
|
|
end
|
|
}
|
|
rec[m]
|
|
end
|
|
|
|
def test_caller_locations
|
|
locs = caller_locations(0); cs = caller(0).map{|line|
|
|
path, lineno, label_str = line.split(':')
|
|
unless label_str
|
|
label_str = lineno
|
|
lineno = 0
|
|
end
|
|
lineno = lineno.to_i
|
|
if /in `(.+?)\'/ =~ label_str
|
|
label = $1
|
|
else
|
|
label = nil
|
|
end
|
|
[path, lineno, label]
|
|
}
|
|
assert_equal(locs.map{|loc| [loc.path, loc.lineno, loc.label]}, cs)
|
|
end
|
|
end
|