]> granicus.if.org Git - python/commitdiff
Add test cases to make sure we get the right SyntaxError message for
authorFred Drake <fdrake@acm.org>
Fri, 8 Sep 2000 16:32:34 +0000 (16:32 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 8 Sep 2000 16:32:34 +0000 (16:32 +0000)
various illegal uses of "continue".

Lib/test/output/test_exceptions
Lib/test/test_exceptions.py

index 9e021d26795cba4f7ebbf9f7c23c36cca4523e50..8ce0154b9d6137f445b7776b936369cdeebe5b6f 100644 (file)
@@ -27,6 +27,16 @@ RuntimeError
 (not used any more?)
 spam
 SyntaxError
+'continue' not supported inside 'try' clause
+ok
+'continue' not supported inside 'try' clause
+ok
+'continue' not supported inside 'try' clause
+ok
+'continue' not properly in loop
+ok
+'continue' not properly in loop
+ok
 spam
 IndentationError
 spam
index 7ee203c44757fbd4ad393d2f91835738846fa4d1..076f4704e44d5aec77e0a2226cd351d0fae4292a 100644 (file)
@@ -86,6 +86,55 @@ r(SyntaxError)
 try: exec '/\n'
 except SyntaxError: pass
 
+# make sure the right exception message is raised for each of these
+# code fragments:
+
+def ckmsg(src, msg):
+    try:
+        compile(src, '<fragment>', 'exec')
+    except SyntaxError, e:
+        print e.msg
+        if e.msg == msg:
+            print "ok"
+        else:
+            print "expected:", msg
+    else:
+        print "failed to get expected SyntaxError"
+
+s = '''\
+while 1:
+    try:
+        continue
+    except:
+        pass
+'''
+ckmsg(s, "'continue' not supported inside 'try' clause")
+s = '''\
+while 1:
+    try:
+        continue
+    finally:
+        pass
+'''
+ckmsg(s, "'continue' not supported inside 'try' clause")
+s = '''\
+while 1:
+    try:
+        if 1:
+            continue
+    finally:
+        pass
+'''
+ckmsg(s, "'continue' not supported inside 'try' clause")
+s = '''\
+try:
+    continue
+except:
+    pass
+'''
+ckmsg(s, "'continue' not properly in loop")
+ckmsg("continue\n", "'continue' not properly in loop")
+
 r(IndentationError)
 
 r(TabError)