diff options
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r-- | Lib/test/test_ast.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 480089aa8a..9734218c21 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -793,6 +793,27 @@ class AST_Tests(unittest.TestCase): return self enum._test_simple_enum(_Precedence, ast._Precedence) + @support.cpython_only + def test_ast_recursion_limit(self): + fail_depth = sys.getrecursionlimit() * 3 + crash_depth = sys.getrecursionlimit() * 300 + success_depth = int(fail_depth * 0.75) + + def check_limit(prefix, repeated): + expect_ok = prefix + repeated * success_depth + ast.parse(expect_ok) + for depth in (fail_depth, crash_depth): + broken = prefix + repeated * depth + details = "Compiling ({!r} + {!r} * {})".format( + prefix, repeated, depth) + with self.assertRaises(RecursionError, msg=details): + ast.parse(broken) + + check_limit("a", "()") + check_limit("a", ".b") + check_limit("a", "[0]") + check_limit("a", "*a") + class ASTHelpers_Test(unittest.TestCase): maxDiff = None |