2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-01-29 03:25:32 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require '-test-/debug'
|
|
|
|
|
|
|
|
class TestDebug < Test::Unit::TestCase
|
|
|
|
|
2013-10-14 15:14:27 -04:00
|
|
|
def binds_check(binds, msg = nil)
|
2013-01-29 03:25:32 -05:00
|
|
|
count = Hash.new(0)
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_instance_of(Array, binds, msg)
|
2013-01-29 03:25:32 -05:00
|
|
|
binds.each{|(_self, bind, klass, iseq, loc)|
|
|
|
|
if _self == self
|
|
|
|
count[:self] += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if bind
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_instance_of(Binding, bind, msg)
|
2013-01-29 03:25:32 -05:00
|
|
|
count[:bind] += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if klass
|
2013-10-14 15:14:27 -04:00
|
|
|
assert(klass.instance_of?(Module) || klass.instance_of?(Class), msg)
|
2013-01-29 03:25:32 -05:00
|
|
|
count[:class] += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if iseq
|
|
|
|
count[:iseq] += 1
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_instance_of(RubyVM::InstructionSequence, iseq, msg)
|
2013-01-29 03:25:32 -05:00
|
|
|
|
|
|
|
# check same location
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_equal(loc.path, iseq.path, msg)
|
|
|
|
assert_equal(loc.absolute_path, iseq.absolute_path, msg)
|
|
|
|
assert_equal(loc.label, iseq.label, msg)
|
|
|
|
assert_operator(loc.lineno, :>=, iseq.first_lineno, msg)
|
2013-01-29 03:25:32 -05:00
|
|
|
end
|
|
|
|
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_instance_of(Thread::Backtrace::Location, loc, msg)
|
2013-01-29 03:25:32 -05:00
|
|
|
|
|
|
|
}
|
2013-10-14 15:14:27 -04:00
|
|
|
assert_operator(0, :<, count[:self], msg)
|
|
|
|
assert_operator(0, :<, count[:bind], msg)
|
|
|
|
assert_operator(0, :<, count[:iseq], msg)
|
|
|
|
assert_operator(0, :<, count[:class], msg)
|
2013-01-29 03:25:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_inspector_open
|
|
|
|
binds = Bug::Debug.inspector
|
|
|
|
binds_check binds
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspector_in_eval
|
|
|
|
eval("Bug::Debug.inspector")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_inspector_open_in_eval
|
|
|
|
bug7635 = '[ruby-core:51640]'
|
|
|
|
binds = inspector_in_eval
|
2013-10-14 15:14:27 -04:00
|
|
|
binds_check binds, bug7635
|
2013-01-29 03:25:32 -05:00
|
|
|
end
|
|
|
|
end
|