Skip to content

Commit fe711e5

Browse files
committed
Test for a more informative message when a Java StackOverflowError is raised
1 parent 5fea93f commit fe711e5

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lib/test/test_exceptions_jy.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"""
55
from test import test_support
66
import unittest
7+
from javatests import StackOverflowErrorTest
8+
79

810
class C:
911
def __str__(self):
@@ -41,6 +43,19 @@ def testBugFix1149372(self):
4143
return
4244
unittest.fail("if __str__ raises an exception, re-raise")
4345

46+
def test_wrap_StackOverflowError(self):
47+
with self.assertRaises(RuntimeError) as cm:
48+
StackOverflowErrorTest.throwStackOverflowError()
49+
self.assertEqual(
50+
cm.exception.message,
51+
"maximum recursion depth exceeded (Java StackOverflowError)")
52+
53+
with self.assertRaises(RuntimeError) as cm:
54+
StackOverflowErrorTest.causeStackOverflowError()
55+
self.assertEqual(
56+
cm.exception.message,
57+
"maximum recursion depth exceeded (Java StackOverflowError)")
58+
4459

4560
def test_main():
4661
test_support.run_unittest(ExceptionsTestCase)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package javatests;
2+
3+
public class StackOverflowErrorTest {
4+
5+
public static void throwStackOverflowError() {
6+
throw new StackOverflowError();
7+
}
8+
9+
public static void causeStackOverflowError() {
10+
causeStackOverflowError();
11+
}
12+
}

0 commit comments

Comments
 (0)