summaryrefslogtreecommitdiff
path: root/test/ruby/test_exception.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2021-06-16 10:23:11 -0700
committerJeremy Evans <code@jeremyevans.net>2021-07-27 10:47:53 -0700
commita6dc48f86a8ee7b1f713105b5c7136824d6b5720 (patch)
treeab6b8fec1d72e9b285aaea8019c30e896cc27f18 /test/ruby/test_exception.rb
parent230111802c2b9dcb8f391b489ff52a9dc0b41b87 (diff)
downloadruby-a6dc48f86a8ee7b1f713105b5c7136824d6b5720.tar.gz
Fix infinite loop in ensure after NoMemoryError
VM patch from wanabe. Test based on example from buzztaiki (Taiki Sugawara). Test fails when compiles with -DRUBY_DEBUG, as that can can use rb_bug instead of NoMemoryError, which doesn't allow testing this case. Test also fails on MingW, as RangeError is used instead of NoMemoryError. Skip the test in either case. Fixes [Bug #15779]
Diffstat (limited to 'test/ruby/test_exception.rb')
-rw-r--r--test/ruby/test_exception.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 62da13d1b9..0e1d280a9b 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -560,6 +560,31 @@ end.join
end;
end
+ def test_ensure_after_nomemoryerror
+ assert_separately([], "'a' * 1_000_000_000_000_000_000")
+ rescue NoMemoryError
+ assert_raise(NoMemoryError) do
+ assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
+ bug15779 = bug15779 = '[ruby-core:92342]'
+ begin;
+ require 'open-uri'
+
+ begin
+ 'a' * 1_000_000_000_000_000_000
+ ensure
+ URI.open('http://www.ruby-lang.org/')
+ end
+ end;
+ end
+ rescue Minitest::Assertion
+ # Possibly compiled with -DRUBY_DEBUG, in which
+ # case rb_bug is used instead of NoMemoryError,
+ # and we cannot test ensure after NoMemoryError.
+ rescue RangeError
+ # MingW can raise RangeError instead of NoMemoryError,
+ # so we cannot test this case.
+ end
+
def test_equal
bug5865 = '[ruby-core:41979]'
assert_equal(RuntimeError.new("a"), RuntimeError.new("a"), bug5865)