From 18c5f9d44dde37c0fae5585a604c6027825252d2 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 15 Jul 2019 10:15:01 +0100 Subject: bpo-37500: Make sure dead code does not generate bytecode but also detect syntax errors (GH-14612) https://bugs.python.org/issue37500 Add a new field to the compiler structure that allows to be configured so no bytecode is emitted. In this way is possible to detect errors by walking the nodes while preserving optimizations. https://bugs.python.org/issue37500 --- Lib/test/test_syntax.py | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'Lib/test/test_syntax.py') diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 8451c072f6..3829746f17 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -697,18 +697,47 @@ class SyntaxTestCase(unittest.TestCase): self._check_error("break", "outside loop") def test_yield_outside_function(self): - self._check_error("if 0: yield", "outside function") - self._check_error("class C:\n if 0: yield", "outside function") + self._check_error("if 0: yield", "outside function") + self._check_error("if 0: yield\nelse: x=1", "outside function") + self._check_error("if 1: pass\nelse: yield", "outside function") + self._check_error("while 0: yield", "outside function") + self._check_error("while 0: yield\nelse: x=1", "outside function") + self._check_error("class C:\n if 0: yield", "outside function") + self._check_error("class C:\n if 1: pass\n else: yield", + "outside function") + self._check_error("class C:\n while 0: yield", "outside function") + self._check_error("class C:\n while 0: yield\n else: x = 1", + "outside function") def test_return_outside_function(self): - self._check_error("if 0: return", "outside function") - self._check_error("class C:\n if 0: return", "outside function") + self._check_error("if 0: return", "outside function") + self._check_error("if 0: return\nelse: x=1", "outside function") + self._check_error("if 1: pass\nelse: return", "outside function") + self._check_error("while 0: return", "outside function") + self._check_error("class C:\n if 0: return", "outside function") + self._check_error("class C:\n while 0: return", "outside function") + self._check_error("class C:\n while 0: return\n else: x=1", + "outside function") + self._check_error("class C:\n if 0: return\n else: x= 1", + "outside function") + self._check_error("class C:\n if 1: pass\n else: return", + "outside function") def test_break_outside_loop(self): - self._check_error("if 0: break", "outside loop") + self._check_error("if 0: break", "outside loop") + self._check_error("if 0: break\nelse: x=1", "outside loop") + self._check_error("if 1: pass\nelse: break", "outside loop") + self._check_error("class C:\n if 0: break", "outside loop") + self._check_error("class C:\n if 1: pass\n else: break", + "outside loop") def test_continue_outside_loop(self): - self._check_error("if 0: continue", "not properly in loop") + self._check_error("if 0: continue", "not properly in loop") + self._check_error("if 0: continue\nelse: x=1", "not properly in loop") + self._check_error("if 1: pass\nelse: continue", "not properly in loop") + self._check_error("class C:\n if 0: continue", "not properly in loop") + self._check_error("class C:\n if 1: pass\n else: continue", + "not properly in loop") def test_unexpected_indent(self): self._check_error("foo()\n bar()\n", "unexpected indent", -- cgit v1.2.1