From 72e48bd05fac4b5fd813f68a692a044a2a85f797 Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Fri, 8 Sep 2000 16:32:34 +0000 Subject: [PATCH] Add test cases to make sure we get the right SyntaxError message for various illegal uses of "continue". --- Lib/test/output/test_exceptions | 10 +++++++ Lib/test/test_exceptions.py | 49 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/Lib/test/output/test_exceptions b/Lib/test/output/test_exceptions index 9e021d2679..8ce0154b9d 100644 --- a/Lib/test/output/test_exceptions +++ b/Lib/test/output/test_exceptions @@ -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 diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 7ee203c447..076f4704e4 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -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, '', '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) -- 2.50.1