Added test cases for return in except statements.
This commit is contained in:
parent
66675d174b
commit
ef379d0a10
2 changed files with 60 additions and 0 deletions
40
tests/exception/tnestedreturn.nim
Normal file
40
tests/exception/tnestedreturn.nim
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
discard """
|
||||||
|
file: "tnestedreturn.nim"
|
||||||
|
output: "A\nB\nC\n"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Various tests of return nested in double try/except statements
|
||||||
|
|
||||||
|
proc test1() =
|
||||||
|
|
||||||
|
finally: echo "A"
|
||||||
|
|
||||||
|
try:
|
||||||
|
raise newException(EOS, "Problem")
|
||||||
|
except EOS:
|
||||||
|
return
|
||||||
|
|
||||||
|
test1()
|
||||||
|
|
||||||
|
|
||||||
|
proc test2() =
|
||||||
|
|
||||||
|
finally: echo "B"
|
||||||
|
|
||||||
|
try:
|
||||||
|
return
|
||||||
|
except EOS:
|
||||||
|
discard
|
||||||
|
|
||||||
|
test2()
|
||||||
|
|
||||||
|
proc test3() =
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
raise newException(EOS, "Problem")
|
||||||
|
except EOS:
|
||||||
|
return
|
||||||
|
finally:
|
||||||
|
echo "C"
|
||||||
|
|
||||||
|
test3()
|
||||||
20
tests/exception/tnestedreturn2.nim
Normal file
20
tests/exception/tnestedreturn2.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
discard """
|
||||||
|
file: "tnestedreturn.nim"
|
||||||
|
outputsub: "Error: unhandled exception: Problem [EOS]"
|
||||||
|
exitcode: "1"
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc test4() =
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
raise newException(EOS, "Problem")
|
||||||
|
except EOS:
|
||||||
|
return
|
||||||
|
finally:
|
||||||
|
discard
|
||||||
|
|
||||||
|
# Should cause unhandled exception error,
|
||||||
|
# but could cause segmentation fault if
|
||||||
|
# exceptions are not handled properly.
|
||||||
|
test4()
|
||||||
|
raise newException(EOS, "Problem")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue