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

23
tests/assert/tassert.nim Normal file
View file

@ -0,0 +1,23 @@
discard """
file: "tassert.nim"
outputsub: "assertion failure!this shall be always written"
exitcode: "1"
"""
# test assert and exception handling
proc callB() = assert(False)
proc callA() = callB()
proc callC() = callA()
try:
callC()
except EAssertionFailed:
write(stdout, "assertion failure!")
except:
write(stdout, "unknown exception!")
finally:
system.write(stdout, "this shall be always written")
assert(false) #OUT assertion failure!this shall be always written

View file

@ -0,0 +1,51 @@
discard """
output: '''
WARNING: false first asseertion from bar
ERROR: false second assertion from bar
-1
tests/run/tfailedassert.nim:27 false assertion from foo
'''
"""
type
TLineInfo = tuple[filename: string, line: int]
TMyError = object of E_Base
lineinfo: TLineInfo
EMyError = ref TMyError
# module-wide policy to change the failed assert
# exception type in order to include a lineinfo
onFailedAssert(msg):
var e = new(TMyError)
e.msg = msg
e.lineinfo = instantiationInfo(-2)
raise e
proc foo =
assert(false, "assertion from foo")
proc bar: int =
# local overrides that are active only
# in this proc
onFailedAssert(msg): echo "WARNING: " & msg
assert(false, "first asseertion from bar")
onFailedAssert(msg):
echo "ERROR: " & msg
return -1
assert(false, "second assertion from bar")
return 10
echo("")
echo(bar())
try:
foo()
except:
let e = EMyError(getCurrentException())
echo e.lineinfo.filename, ":", e.lineinfo.line, " ", e.msg

View file

@ -0,0 +1 @@
import utemplates, uclosures

View file

@ -0,0 +1,13 @@
discard """
output: "x == 45ugh"
"""
template myAssert(cond: expr) =
when rand(3) < 3:
let c = cond.astToStr
if not cond:
echo c, "ugh"
var x = 454
myAssert(x == 45)