From bf973d29da48fc6e6d6eeedce3adda84e0b45a64 Mon Sep 17 00:00:00 2001 From: awr1 <41453959+awr1@users.noreply.github.com> Date: Thu, 23 Aug 2018 03:20:58 -0500 Subject: [PATCH] Fixes #8719 (onFailedAssert now works for doAssert) (#8731) --- lib/system.nim | 16 ++++++++-------- tests/assert/tfaileddoassert.nim | 11 +++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 tests/assert/tfaileddoassert.nim diff --git a/lib/system.nim b/lib/system.nim index d61924a5b1..73804b9739 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3741,23 +3741,23 @@ template assert*(cond: bool, msg = "") = ## The compiler may not generate any code at all for ``assert`` if it is ## advised to do so through the ``-d:release`` or ``--assertions:off`` ## `command line switches `_. + # NOTE: `true` is correct here; --excessiveStackTrace:on will control whether + # or not to output full paths. bind instantiationInfo mixin failedAssertImpl - when compileOption("assertions"): - {.line.}: + {.line: instantiationInfo(fullPaths = true).}: + when compileOption("assertions"): if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg) template doAssert*(cond: bool, msg = "") = ## same as `assert` but is always turned on and not affected by the ## ``--assertions`` command line switch. - bind instantiationInfo # NOTE: `true` is correct here; --excessiveStackTrace:on will control whether # or not to output full paths. - {.line: instantiationInfo(-1, true).}: - if not cond: - raiseAssert(astToStr(cond) & ' ' & - instantiationInfo(-1, false).fileName & '(' & - $instantiationInfo(-1, false).line & ") " & msg) + bind instantiationInfo + mixin failedAssertImpl + {.line: instantiationInfo(fullPaths = true).}: + if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg) iterator items*[T](a: seq[T]): T {.inline.} = ## iterates over each item of `a`. diff --git a/tests/assert/tfaileddoassert.nim b/tests/assert/tfaileddoassert.nim new file mode 100644 index 0000000000..3195fb406b --- /dev/null +++ b/tests/assert/tfaileddoassert.nim @@ -0,0 +1,11 @@ +discard """ + cmd: "nim $target -d:release $options $file" + output: ''' +assertion occured!!!!!! false +''' +""" + +onFailedAssert(msg): + echo("assertion occured!!!!!! ", msg) + +doAssert(1 == 2)