aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarcelo Pereira <marcelovitor.pereira@gmail.com>2022-07-29 15:09:54 +0200
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-07-15 15:24:43 +0900
commitf15123c34ce80f3928612befe2a9aaf4c9d27fda (patch)
treedb2cb9f714fdf997585334c370dd3c570ff71b80 /test
parent82cd70ef935e6aac8cc929af24fb21c2157524f7 (diff)
downloadruby-f15123c34ce80f3928612befe2a9aaf4c9d27fda.tar.gz
Fix stack trace for rescued StopIteration
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_enumerator.rb20
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