Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72e48bd

Browse files
committed
Add test cases to make sure we get the right SyntaxError message for
various illegal uses of "continue".
1 parent fd1f1be commit 72e48bd

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lib/test/output/test_exceptions

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ RuntimeError
2727
(not used any more?)
2828
spam
2929
SyntaxError
30+
'continue' not supported inside 'try' clause
31+
ok
32+
'continue' not supported inside 'try' clause
33+
ok
34+
'continue' not supported inside 'try' clause
35+
ok
36+
'continue' not properly in loop
37+
ok
38+
'continue' not properly in loop
39+
ok
3040
spam
3141
IndentationError
3242
spam

Lib/test/test_exceptions.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,55 @@ def r(thing):
8686
try: exec '/\n'
8787
except SyntaxError: pass
8888

89+
# make sure the right exception message is raised for each of these
90+
# code fragments:
91+
92+
def ckmsg(src, msg):
93+
try:
94+
compile(src, '<fragment>', 'exec')
95+
except SyntaxError, e:
96+
print e.msg
97+
if e.msg == msg:
98+
print "ok"
99+
else:
100+
print "expected:", msg
101+
else:
102+
print "failed to get expected SyntaxError"
103+
104+
s = '''\
105+
while 1:
106+
try:
107+
continue
108+
except:
109+
pass
110+
'''
111+
ckmsg(s, "'continue' not supported inside 'try' clause")
112+
s = '''\
113+
while 1:
114+
try:
115+
continue
116+
finally:
117+
pass
118+
'''
119+
ckmsg(s, "'continue' not supported inside 'try' clause")
120+
s = '''\
121+
while 1:
122+
try:
123+
if 1:
124+
continue
125+
finally:
126+
pass
127+
'''
128+
ckmsg(s, "'continue' not supported inside 'try' clause")
129+
s = '''\
130+
try:
131+
continue
132+
except:
133+
pass
134+
'''
135+
ckmsg(s, "'continue' not properly in loop")
136+
ckmsg("continue\n", "'continue' not properly in loop")
137+
89138
r(IndentationError)
90139

91140
r(TabError)

0 commit comments

Comments
 (0)