diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-23 14:46:59 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-12-23 14:46:59 +0000 |
commit | 3044138bd734cf94e09250ac1bcb0886c26cdb27 (patch) | |
tree | e1a0a176fc78504dfb88c9c009ca5badf4d21801 /test | |
parent | ac40fc997b6b27c4f61084d9f6fae83ea251d614 (diff) | |
download | ruby-3044138bd734cf94e09250ac1bcb0886c26cdb27.tar.gz |
RubyVM::InstructionSequence#trace_points.
* iseq.c (iseqw_trace_points): add `RubyVM::InstructionSequence#trace_points`
method for tools which want to manipulate ISeq (and traces).
* test/ruby/test_iseq.rb: add a test for this method.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_iseq.rb | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 2f23f78e23..74691854d9 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -281,27 +281,31 @@ class TestISeq < Test::Unit::TestCase end end - def test_each_child - iseq = ISeq.compile <<-EOS - class C - def foo - begin - rescue - p :rescue - ensure - p :ensure - end - end - def bar - 1.times{ - 2.times{ - } - } - end - end - class D < C - end + def sample_iseq + ISeq.compile <<-EOS.gsub(/^.*?: /, "") + 1: class C + 2: def foo + 3: begin + 4: rescue + 5: p :rescue + 6: ensure + 7: p :ensure + 8: end + 9: end + 10: def bar + 11: 1.times{ + 12: 2.times{ + 13: } + 14: } + 15: end + 16: end + 17: class D < C + 18: end EOS + end + + def test_each_child + iseq = sample_iseq collect_iseq = lambda{|iseq| iseqs = [] @@ -321,4 +325,36 @@ class TestISeq < Test::Unit::TestCase assert_equal expected, collect_iseq.call(iseq) end + + def test_trace_points + collect_iseq = lambda{|iseq| + iseqs = [] + iseq.each_child{|child_iseq| + iseqs << collect_iseq.call(child_iseq) + } + [["#{iseq.label}@#{iseq.first_lineno}", iseq.trace_points], *iseqs.sort_by{|k, *| k}] + } + assert_equal [["<compiled>@1", [[1, :line], + [17, :line]]], + [["<class:C>@1", [[1, :class], + [2, :line], + [10, :line], + [16, :end]]], + [["bar@10", [[10, :call], + [11, :line], + [15, :return]]], + [["block in bar@11", [[11, :b_call], + [12, :line], + [14, :b_return]]], + [["block (2 levels) in bar@12", [[12, :b_call], + [13, :b_return]]]]]], + [["foo@2", [[2, :call], + [4, :line], + [7, :line], + [9, :return]]], + [["ensure in foo@2", [[7, :line]]]], + [["rescue in foo@4", [[5, :line]]]]]], + [["<class:D>@17", [[17, :class], + [18, :end]]]]], collect_iseq.call(sample_iseq) + end end |