mirror of https://github.com/python/cpython
Add test for syntax error on "x = 1 + 1".
Move check_syntax() function into test_support.
This commit is contained in:
parent
c348cd7518
commit
4779399e9f
|
@ -14,7 +14,6 @@ expr_input
|
||||||
eval_input
|
eval_input
|
||||||
funcdef
|
funcdef
|
||||||
lambdef
|
lambdef
|
||||||
SyntaxError expected for "lambda x: x = 2"
|
|
||||||
simple_stmt
|
simple_stmt
|
||||||
expr_stmt
|
expr_stmt
|
||||||
print_stmt
|
print_stmt
|
||||||
|
@ -26,8 +25,6 @@ extended print_stmt
|
||||||
1 2 3
|
1 2 3
|
||||||
1 1 1
|
1 1 1
|
||||||
hello world
|
hello world
|
||||||
SyntaxError expected for "print ,"
|
|
||||||
SyntaxError expected for "print >> x,"
|
|
||||||
del_stmt
|
del_stmt
|
||||||
pass_stmt
|
pass_stmt
|
||||||
flow_stmt
|
flow_stmt
|
||||||
|
@ -62,6 +59,4 @@ classdef
|
||||||
[(1, 'Apple'), (1, 'Banana'), (1, 'Coconut'), (2, 'Apple'), (2, 'Banana'), (2, 'Coconut'), (3, 'Apple'), (3, 'Banana'), (3, 'Coconut'), (4, 'Apple'), (4, 'Banana'), (4, 'Coconut'), (5, 'Apple'), (5, 'Banana'), (5, 'Coconut')]
|
[(1, 'Apple'), (1, 'Banana'), (1, 'Coconut'), (2, 'Apple'), (2, 'Banana'), (2, 'Coconut'), (3, 'Apple'), (3, 'Banana'), (3, 'Coconut'), (4, 'Apple'), (4, 'Banana'), (4, 'Coconut'), (5, 'Apple'), (5, 'Banana'), (5, 'Coconut')]
|
||||||
[(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), (5, 'Banana'), (5, 'Coconut')]
|
[(1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), (5, 'Banana'), (5, 'Coconut')]
|
||||||
[0, 0, 0]
|
[0, 0, 0]
|
||||||
SyntaxError expected for "[i, s for i in nums for s in strs]"
|
|
||||||
SyntaxError expected for "[x if y]"
|
|
||||||
[('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'), ('Macdonalds', 'Cheeseburger')]
|
[('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'), ('Macdonalds', 'Cheeseburger')]
|
||||||
|
|
|
@ -3,14 +3,6 @@
|
||||||
|
|
||||||
from test_support import *
|
from test_support import *
|
||||||
|
|
||||||
def check_syntax(statement):
|
|
||||||
try:
|
|
||||||
compile(statement, '<string>', 'exec')
|
|
||||||
except SyntaxError:
|
|
||||||
print 'SyntaxError expected for "%s"' % statement
|
|
||||||
else:
|
|
||||||
print 'Missing SyntaxError: "%s"' % statement
|
|
||||||
|
|
||||||
print '1. Parser'
|
print '1. Parser'
|
||||||
|
|
||||||
print '1.1 Tokens'
|
print '1.1 Tokens'
|
||||||
|
@ -280,6 +272,9 @@ x, y, z = 1, 2, 3
|
||||||
abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4)
|
abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4)
|
||||||
# NB these variables are deleted below
|
# NB these variables are deleted below
|
||||||
|
|
||||||
|
check_syntax("x + 1 = 1")
|
||||||
|
check_syntax("a + 1 = b + 2")
|
||||||
|
|
||||||
print 'print_stmt' # 'print' (test ',')* [test]
|
print 'print_stmt' # 'print' (test ',')* [test]
|
||||||
print 1, 2, 3
|
print 1, 2, 3
|
||||||
print 1, 2, 3,
|
print 1, 2, 3,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from test.test_support import verify, TestFailed
|
from test.test_support import verify, TestFailed, check_syntax
|
||||||
|
|
||||||
print "1. simple nesting"
|
print "1. simple nesting"
|
||||||
|
|
||||||
|
@ -177,14 +177,6 @@ verify(f(6) == 720)
|
||||||
|
|
||||||
print "11. unoptimized namespaces"
|
print "11. unoptimized namespaces"
|
||||||
|
|
||||||
def check_syntax(s):
|
|
||||||
try:
|
|
||||||
compile(s, '?', 'exec')
|
|
||||||
except SyntaxError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise TestFailed
|
|
||||||
|
|
||||||
check_syntax("""def unoptimized_clash1(strip):
|
check_syntax("""def unoptimized_clash1(strip):
|
||||||
def f(s):
|
def f(s):
|
||||||
from string import *
|
from string import *
|
||||||
|
|
|
@ -79,3 +79,12 @@ def verify(condition, reason='test failed'):
|
||||||
|
|
||||||
if not condition:
|
if not condition:
|
||||||
raise TestFailed(reason)
|
raise TestFailed(reason)
|
||||||
|
|
||||||
|
def check_syntax(statement):
|
||||||
|
try:
|
||||||
|
compile(statement, '<string>', 'exec')
|
||||||
|
except SyntaxError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print 'Missing SyntaxError: "%s"' % statement
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue