new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
30
tests/exception/tcontinuexc.nim
Normal file
30
tests/exception/tcontinuexc.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
discard """
|
||||
file: "tcontinuexc.nim"
|
||||
outputsub: "ECcaught"
|
||||
exitcode: "1"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
raise newException(ESomething, "Test")
|
||||
else:
|
||||
raise newException(EsomeotherErr, "bla")
|
||||
|
||||
try:
|
||||
for i in 0..3:
|
||||
try:
|
||||
genErrors("error!")
|
||||
except ESomething:
|
||||
stdout.write("E")
|
||||
stdout.write("C")
|
||||
raise newException(EsomeotherErr, "bla")
|
||||
finally:
|
||||
echo "caught"
|
||||
|
||||
#OUT ECcaught
|
||||
|
||||
|
||||
|
||||
66
tests/exception/texceptions.nim
Normal file
66
tests/exception/texceptions.nim
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
discard """
|
||||
output: '''
|
||||
BEFORE
|
||||
FINALLY
|
||||
|
||||
BEFORE
|
||||
EXCEPT
|
||||
FINALLY
|
||||
RECOVER
|
||||
|
||||
BEFORE
|
||||
EXCEPT
|
||||
FINALLY
|
||||
'''
|
||||
"""
|
||||
|
||||
echo ""
|
||||
|
||||
proc no_expcetion =
|
||||
try:
|
||||
echo "BEFORE"
|
||||
|
||||
except:
|
||||
echo "EXCEPT"
|
||||
raise
|
||||
|
||||
finally:
|
||||
echo "FINALLY"
|
||||
|
||||
try: no_expcetion()
|
||||
except: echo "RECOVER"
|
||||
|
||||
echo ""
|
||||
|
||||
proc reraise_in_except =
|
||||
try:
|
||||
echo "BEFORE"
|
||||
raise newException(EIO, "")
|
||||
|
||||
except EIO:
|
||||
echo "EXCEPT"
|
||||
raise
|
||||
|
||||
finally:
|
||||
echo "FINALLY"
|
||||
|
||||
try: reraise_in_except()
|
||||
except: echo "RECOVER"
|
||||
|
||||
echo ""
|
||||
|
||||
proc return_in_except =
|
||||
try:
|
||||
echo "BEFORE"
|
||||
raise newException(EIO, "")
|
||||
|
||||
except:
|
||||
echo "EXCEPT"
|
||||
return
|
||||
|
||||
finally:
|
||||
echo "FINALLY"
|
||||
|
||||
try: return_in_except()
|
||||
except: echo "RECOVER"
|
||||
|
||||
30
tests/exception/texcpt1.nim
Normal file
30
tests/exception/texcpt1.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
discard """
|
||||
outputsub: "-6"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
raise newException(ESomething, "Test")
|
||||
else:
|
||||
raise newException(EsomeotherErr, "bla")
|
||||
|
||||
proc raiseBla(): int =
|
||||
try:
|
||||
genErrors("errssor!")
|
||||
except ESomething:
|
||||
echo("Error happened")
|
||||
except:
|
||||
raise
|
||||
|
||||
proc blah(): int =
|
||||
try:
|
||||
result = raiseBla()
|
||||
except ESomeOtherErr:
|
||||
result = -6
|
||||
|
||||
echo blah()
|
||||
|
||||
|
||||
17
tests/exception/texcsub.nim
Normal file
17
tests/exception/texcsub.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
discard """
|
||||
file: "texcsub.nim"
|
||||
output: "caught!"
|
||||
"""
|
||||
# Test inheritance for exception matching:
|
||||
|
||||
try:
|
||||
raise newException(EOS, "dummy message")
|
||||
except E_Base:
|
||||
echo "caught!"
|
||||
except:
|
||||
echo "wtf!?"
|
||||
|
||||
#OUT caught!
|
||||
|
||||
|
||||
|
||||
19
tests/exception/tfinally.nim
Normal file
19
tests/exception/tfinally.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
discard """
|
||||
file: "tfinally.nim"
|
||||
output: "came\nhere\n3"
|
||||
"""
|
||||
# Test return in try statement:
|
||||
|
||||
proc main: int =
|
||||
try:
|
||||
try:
|
||||
return 1
|
||||
finally:
|
||||
echo("came")
|
||||
return 2
|
||||
finally:
|
||||
echo("here")
|
||||
return 3
|
||||
|
||||
echo main() #OUT came here 3
|
||||
|
||||
30
tests/exception/tfinally2.nim
Normal file
30
tests/exception/tfinally2.nim
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
discard """
|
||||
file: "tfinally2.nim"
|
||||
output: '''A
|
||||
B
|
||||
C
|
||||
D'''
|
||||
"""
|
||||
# Test break in try statement:
|
||||
|
||||
proc main: int =
|
||||
try:
|
||||
block AB:
|
||||
try:
|
||||
try:
|
||||
break AB
|
||||
finally:
|
||||
echo("A")
|
||||
echo("skipped")
|
||||
finally:
|
||||
block B:
|
||||
echo("B")
|
||||
echo("skipped")
|
||||
echo("C")
|
||||
finally:
|
||||
echo("D")
|
||||
|
||||
discard main() #OUT ABCD
|
||||
|
||||
|
||||
|
||||
18
tests/exception/tfinally3.nim
Normal file
18
tests/exception/tfinally3.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
discard """
|
||||
file: "tfinally3.nim"
|
||||
output: "false"
|
||||
"""
|
||||
# Test break in try statement:
|
||||
|
||||
proc main: bool =
|
||||
while true:
|
||||
try:
|
||||
return true
|
||||
finally:
|
||||
break
|
||||
return false
|
||||
|
||||
echo main() #OUT false
|
||||
|
||||
|
||||
|
||||
34
tests/exception/tonraise.nim
Normal file
34
tests/exception/tonraise.nim
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
discard """
|
||||
output: '''i: 1
|
||||
success'''
|
||||
"""
|
||||
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
raise newException(ESomething, "Test")
|
||||
else:
|
||||
raise newException(EsomeotherErr, "bla")
|
||||
|
||||
proc foo() =
|
||||
var i = 0
|
||||
try:
|
||||
inc i
|
||||
onRaise(proc (e: ref E_Base): bool =
|
||||
echo "i: ", i)
|
||||
genErrors("errssor!")
|
||||
except ESomething:
|
||||
echo("ESomething happened")
|
||||
except:
|
||||
echo("Some other error happened")
|
||||
|
||||
# test that raise handler is gone:
|
||||
try:
|
||||
genErrors("error!")
|
||||
except ESomething:
|
||||
echo "success"
|
||||
|
||||
foo()
|
||||
24
tests/exception/treraise.nim
Normal file
24
tests/exception/treraise.nim
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
discard """
|
||||
file: "treraise.nim"
|
||||
outputsub: "Error: unhandled exception: bla [ESomeOtherErr]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
raise newException(ESomething, "Test")
|
||||
else:
|
||||
raise newException(EsomeotherErr, "bla")
|
||||
|
||||
try:
|
||||
genErrors("errssor!")
|
||||
except ESomething:
|
||||
echo("Error happened")
|
||||
except:
|
||||
raise
|
||||
|
||||
|
||||
|
||||
23
tests/exception/tunhandledexc.nim
Normal file
23
tests/exception/tunhandledexc.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
discard """
|
||||
file: "tunhandledexc.nim"
|
||||
outputsub: "Error: unhandled exception: bla [ESomeOtherErr]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
type
|
||||
ESomething = object of E_Base
|
||||
ESomeOtherErr = object of E_Base
|
||||
|
||||
proc genErrors(s: string) =
|
||||
if s == "error!":
|
||||
raise newException(ESomething, "Test")
|
||||
else:
|
||||
raise newException(EsomeotherErr, "bla")
|
||||
|
||||
when True:
|
||||
try:
|
||||
genErrors("errssor!")
|
||||
except ESomething:
|
||||
echo("Error happened")
|
||||
|
||||
|
||||
|
||||
13
tests/exception/twrongexc.nim
Normal file
13
tests/exception/twrongexc.nim
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
discard """
|
||||
file: "twrongexc.nim"
|
||||
outputsub: "Error: unhandled exception: [EInvalidValue]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
try:
|
||||
raise newException(EInvalidValue, "")
|
||||
except EOverflow:
|
||||
echo("Error caught")
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue