new tester; all tests categorized

This commit is contained in:
Araq 2014-01-13 02:10:03 +01:00
commit 20b5f31c03
481 changed files with 794 additions and 2506 deletions

View 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

View 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"

View 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()

View 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!

View 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

View 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

View 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

View 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()

View 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

View 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")

View 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")