diff options
author | Koichi Sasada <[email protected]> | 2023-08-01 17:25:20 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2023-08-01 22:46:17 +0900 |
commit | d68c01fd314ebd6dc1d89c95a2734fad4f0953b0 (patch) | |
tree | b8d8794f59990f635eaf984119519f0a9cd51bd1 /test/ruby/test_settracefunc.rb | |
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/test_settracefunc.rb')
-rw-r--r-- | test/ruby/test_settracefunc.rb | 47 |
1 files changed, 47 insertions, 0 deletions
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 |