diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-12-28 23:53:48 +0200 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-12-28 23:53:48 +0200 |
commit | eb1d23c0c745c64225e8db22f62d8ebf596f4448 (patch) | |
tree | 2cb9a88374d255c38c94409bf7e13ad1879033dd /tests | |
parent | 5d75ce2f2eec8d4ec6f152105a144abcf73e4a37 (diff) | |
download | Nim-eb1d23c0c745c64225e8db22f62d8ebf596f4448.tar.gz |
fixes #787
Diffstat (limited to 'tests')
-rw-r--r-- | tests/run/tfailedassert.nim | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/run/tfailedassert.nim b/tests/run/tfailedassert.nim new file mode 100644 index 000000000..0e536cffd --- /dev/null +++ b/tests/run/tfailedassert.nim @@ -0,0 +1,51 @@ +discard """ + output: ''' +WARNING: false first asseertion from bar +ERROR: false second assertion from bar +-1 +tests/run/tfailedassert.nim:40 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 + |