parent
52bee6baba
commit
bf973d29da
2 changed files with 19 additions and 8 deletions
|
|
@ -3741,23 +3741,23 @@ template assert*(cond: bool, msg = "") =
|
||||||
## The compiler may not generate any code at all for ``assert`` if it is
|
## 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``
|
## advised to do so through the ``-d:release`` or ``--assertions:off``
|
||||||
## `command line switches <nimc.html#command-line-switches>`_.
|
## `command line switches <nimc.html#command-line-switches>`_.
|
||||||
|
# NOTE: `true` is correct here; --excessiveStackTrace:on will control whether
|
||||||
|
# or not to output full paths.
|
||||||
bind instantiationInfo
|
bind instantiationInfo
|
||||||
mixin failedAssertImpl
|
mixin failedAssertImpl
|
||||||
when compileOption("assertions"):
|
{.line: instantiationInfo(fullPaths = true).}:
|
||||||
{.line.}:
|
when compileOption("assertions"):
|
||||||
if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg)
|
if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg)
|
||||||
|
|
||||||
template doAssert*(cond: bool, msg = "") =
|
template doAssert*(cond: bool, msg = "") =
|
||||||
## same as `assert` but is always turned on and not affected by the
|
## same as `assert` but is always turned on and not affected by the
|
||||||
## ``--assertions`` command line switch.
|
## ``--assertions`` command line switch.
|
||||||
bind instantiationInfo
|
|
||||||
# NOTE: `true` is correct here; --excessiveStackTrace:on will control whether
|
# NOTE: `true` is correct here; --excessiveStackTrace:on will control whether
|
||||||
# or not to output full paths.
|
# or not to output full paths.
|
||||||
{.line: instantiationInfo(-1, true).}:
|
bind instantiationInfo
|
||||||
if not cond:
|
mixin failedAssertImpl
|
||||||
raiseAssert(astToStr(cond) & ' ' &
|
{.line: instantiationInfo(fullPaths = true).}:
|
||||||
instantiationInfo(-1, false).fileName & '(' &
|
if not cond: failedAssertImpl(astToStr(cond) & ' ' & msg)
|
||||||
$instantiationInfo(-1, false).line & ") " & msg)
|
|
||||||
|
|
||||||
iterator items*[T](a: seq[T]): T {.inline.} =
|
iterator items*[T](a: seq[T]): T {.inline.} =
|
||||||
## iterates over each item of `a`.
|
## iterates over each item of `a`.
|
||||||
|
|
|
||||||
11
tests/assert/tfaileddoassert.nim
Normal file
11
tests/assert/tfaileddoassert.nim
Normal file
|
|
@ -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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue