summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCarl Friedrich Bolz-Tereick <cfbolz@gmx.de>2021-08-28 18:33:50 (GMT)
committerGitHub <noreply@github.com>2021-08-28 18:33:50 (GMT)
commiteb263f9a356f5c5f21b8d5ce20bac92f31c40cad (patch)
tree715a8eb82393741b0effbc0bec0cb7d50e46c936 /Lib
parent206b21ed9f64fedff67bfea7cf73e423e3e32393 (diff)
downloadcpython-eb263f9a356f5c5f21b8d5ce20bac92f31c40cad.zip
cpython-eb263f9a356f5c5f21b8d5ce20bac92f31c40cad.tar.gz
cpython-eb263f9a356f5c5f21b8d5ce20bac92f31c40cad.tar.bz2
bpo-25130: Make unit-test about restricting the maximum number of nested blocks cpython-only (GH-28002)
PyPy and potentially other implementations have different or no contraints on the number of blocks that can be statically nested. move the test that checks for this behaviour into a unit test and mark it as CPython-only.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_syntax.py67
1 files changed, 35 insertions, 32 deletions
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 43780ce..be8be89 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -629,38 +629,6 @@ isn't, there should be a syntax error.
...
SyntaxError: 'break' outside loop
-This raises a SyntaxError, it used to raise a SystemError.
-Context for this change can be found on issue #27514
-
-In 2.5 there was a missing exception and an assert was triggered in a debug
-build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514
-
- >>> while 1:
- ... while 2:
- ... while 3:
- ... while 4:
- ... while 5:
- ... while 6:
- ... while 8:
- ... while 9:
- ... while 10:
- ... while 11:
- ... while 12:
- ... while 13:
- ... while 14:
- ... while 15:
- ... while 16:
- ... while 17:
- ... while 18:
- ... while 19:
- ... while 20:
- ... while 21:
- ... while 22:
- ... break
- Traceback (most recent call last):
- ...
- SyntaxError: too many statically nested blocks
-
Misuse of the nonlocal and global statement can lead to a few unique syntax errors.
>>> def f():
@@ -1550,6 +1518,41 @@ case(34)
lineno=3
)
+ @support.cpython_only
+ def test_syntax_error_on_deeply_nested_blocks(self):
+ # This raises a SyntaxError, it used to raise a SystemError. Context
+ # for this change can be found on issue #27514
+
+ # In 2.5 there was a missing exception and an assert was triggered in a
+ # debug build. The number of blocks must be greater than CO_MAXBLOCKS.
+ # SF #1565514
+
+ source = """
+while 1:
+ while 2:
+ while 3:
+ while 4:
+ while 5:
+ while 6:
+ while 8:
+ while 9:
+ while 10:
+ while 11:
+ while 12:
+ while 13:
+ while 14:
+ while 15:
+ while 16:
+ while 17:
+ while 18:
+ while 19:
+ while 20:
+ while 21:
+ while 22:
+ break
+"""
+ self._check_error(source, "too many statically nested blocks")
+
def test_main():
support.run_unittest(SyntaxTestCase)