diff options
| author | Koichi Sasada <ko1@atdot.net> | 2023-08-01 17:25:20 +0900 |
|---|---|---|
| committer | Koichi Sasada <ko1@atdot.net> | 2023-08-01 22:46:17 +0900 |
| commit | d68c01fd314ebd6dc1d89c95a2734fad4f0953b0 (patch) | |
| tree | b8d8794f59990f635eaf984119519f0a9cd51bd1 /test/ruby | |
| parent | f11ac06337fc56104172c3241393fd95d3a6c60d (diff) | |
support `rescue` event for TracePoint
fix [Feature #19572]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8150
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_iseq.rb | 3 | ||||
| -rw-r--r-- | test/ruby/test_settracefunc.rb | 47 |
2 files changed, 49 insertions, 1 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 682fa52570..4ff808418f 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -497,7 +497,8 @@ class TestISeq < Test::Unit::TestCase [7, :line], [9, :return]]], [["ensure in foo@2", [[7, :line]]]], - [["rescue in foo@4", [[5, :line]]]]]], + [["rescue in foo@4", [[5, :line], + [5, :rescue]]]]]], [["<class:D>@17", [[17, :class], [18, :end]]]]], collect_iseq.call(sample_iseq) end diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index c5e0f328e2..951faa69d8 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -2749,4 +2749,51 @@ CODE raise_line = lines.shift assert_equal [], lines end + + def helper_can_rescue + begin + raise __LINE__.to_s + rescue SyntaxError + :ng + rescue + :ok + end + end + + def helper_can_rescue_empty_body + begin + raise __LINE__.to_s + rescue SyntaxError + :ng + rescue + end + end + + def test_tp_rescue_event + lines = [] + TracePoint.new(:rescue){|tp| + next unless target_thread? + lines << [tp.lineno, tp.raised_exception] + }.enable{ + helper_can_rescue + } + + line, err, = lines.pop + assert_equal [], lines + assert err.kind_of?(RuntimeError) + assert_equal err.message.to_i + 4, line + + lines = [] + TracePoint.new(:rescue){|tp| + next unless target_thread? + lines << [tp.lineno, tp.raised_exception] + }.enable{ + helper_can_rescue_empty_body + } + + line, err, = lines.pop + assert_equal [], lines + assert err.kind_of?(RuntimeError) + assert_equal err.message.to_i + 3, line + end end |
