Debian Codegraph @

test/-ext-/debug/test_debug.rb

raw
1 # frozen_string_literal: false
2 require 'test/unit'
3 require '-test-/debug'
4
5 class TestDebug < Test::Unit::TestCase
6
7 def binds_check(binds, msg = nil)
8 count = Hash.new(0)
9 assert_instance_of(Array, binds, msg)
10 binds.each{|(_self, bind, klass, iseq, loc)|
11 if _self == self
12 count[:self] += 1
13 end
14
15 if bind
16 assert_instance_of(Binding, bind, msg)
17 count[:bind] += 1
18 end
19
20 if klass
21 assert(klass.instance_of?(Module) || klass.instance_of?(Class), msg)
22 count[:class] += 1
23 end
24
25 if iseq
26 count[:iseq] += 1
27 assert_instance_of(RubyVM::InstructionSequence, iseq, msg)
28
29 # check same location
30 assert_equal(loc.path, iseq.path, msg)
31 assert_equal(loc.absolute_path, iseq.absolute_path, msg)
32 assert_equal(loc.label, iseq.label, msg)
33 assert_operator(loc.lineno, :>=, iseq.first_lineno, msg)
34 end
35
36 assert_instance_of(Thread::Backtrace::Location, loc, msg)
37
38 }
39 assert_operator(0, :<, count[:self], msg)
40 assert_operator(0, :<, count[:bind], msg)
41 assert_operator(0, :<, count[:iseq], msg)
42 assert_operator(0, :<, count[:class], msg)
43 end
44
45 def test_inspector_open
46 binds = Bug::Debug.inspector
47 binds_check binds
48 end
49
50 def inspector_in_eval
51 eval("Bug::Debug.inspector")
52 end
53
54 def test_inspector_open_in_eval
55 bug7635 = '[ruby-core:51640]'
56 binds = inspector_in_eval
57 binds_check binds, bug7635
58 end
59
60 class MyRelation
61 include Enumerable
62
63 def each
64 yield :each_entry
65 end
66 end
67
68 def test_lazy_block
69 x = MyRelation.new.any? do
70 Bug::Debug.inspector
71 true
72 end
73 assert_equal true, x, '[Bug #15105]'
74 end
75 end