diff options
author | Marcelo Pereira <[email protected]> | 2022-07-29 15:09:54 +0200 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-07-15 15:24:43 +0900 |
commit | f15123c34ce80f3928612befe2a9aaf4c9d27fda (patch) | |
tree | db2cb9f714fdf997585334c370dd3c570ff71b80 /test/ruby/test_enumerator.rb | |
parent | 82cd70ef935e6aac8cc929af24fb21c2157524f7 (diff) |
Fix stack trace for rescued StopIteration
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6201
Diffstat (limited to 'test/ruby/test_enumerator.rb')
-rw-r--r-- | test/ruby/test_enumerator.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 010c1e4969..bbaa91b703 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -244,6 +244,26 @@ class TestEnumerator < Test::Unit::TestCase assert_equal(res, exc.result) end + def test_stopiteration_rescue + e = [1].each + res = e.each {} + e.next + exc0 = assert_raise(StopIteration) { e.peek } + assert_include(exc0.backtrace.first, "test_enumerator.rb:#{__LINE__-1}:") + assert_nil(exc0.cause) + assert_equal(res, exc0.result) + + exc1 = assert_raise(StopIteration) { e.next } + assert_include(exc1.backtrace.first, "test_enumerator.rb:#{__LINE__-1}:") + assert_same(exc0, exc1.cause) + assert_equal(res, exc1.result) + + exc2 = assert_raise(StopIteration) { e.next } + assert_include(exc2.backtrace.first, "test_enumerator.rb:#{__LINE__-1}:") + assert_same(exc0, exc2.cause) + assert_equal(res, exc2.result) + end + def test_next_values o = Object.new def o.each |