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

Skip to content

Commit 80d373c

Browse files
committed
Test case for SF bugs #463359 and #462937, added to test_grammar for lack of
a better place. Excessively fragile code, but at least it breaks when something in this area changes!
1 parent 65279d0 commit 80d373c

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lib/test/output/test_grammar

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ break_stmt
3232
continue_stmt
3333
continue + try/except ok
3434
continue + try/finally ok
35+
testing continue and break in try/except in loop
3536
return_stmt
3637
raise_stmt
3738
import_stmt

Lib/test/test_grammar.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,33 @@ def tellme(file=None):
358358
msg = "continue + try/finally ok"
359359
print msg
360360

361+
362+
# This test warrants an explanation. It is a test specifically for SF bugs
363+
# #463359 and #462937. The bug is that a 'break' statement executed or
364+
# exception raised inside a try/except inside a loop, *after* a continue
365+
# statement has been executed in that loop, will cause the wrong number of
366+
# arguments to be popped off the stack and the instruction pointer reset to
367+
# a very small number (usually 0.) Because of this, the following test
368+
# *must* written as a function, and the tracking vars *must* be function
369+
# arguments with default values. Otherwise, the test will loop and loop.
370+
371+
print "testing continue and break in try/except in loop"
372+
def test_break_continue_loop(extra_burning_oil = 1, count=0):
373+
big_hippo = 2
374+
while big_hippo:
375+
count += 1
376+
try:
377+
if extra_burning_oil and big_hippo == 1:
378+
extra_burning_oil -= 1
379+
break
380+
big_hippo -= 1
381+
continue
382+
except:
383+
raise
384+
if count > 2 or big_hippo <> 1:
385+
print "continue then break in try/except in loop broken!"
386+
test_break_continue_loop()
387+
361388
print 'return_stmt' # 'return' [testlist]
362389
def g1(): return
363390
def g2(): return 1

0 commit comments

Comments
 (0)