On this page
assertions
Imports
Procs
-
proc raiseAssert(msg: string) {...}{.noinline, noreturn, nosinks, raises: [], tags: [].} - Source Edit
-
proc failedAssertImpl(msg: string) {...}{.raises: [], tags: [].} - Source Edit
Templates
-
template assert(cond: untyped; msg = "") -
Raises
AssertionDefectwithmsgifcondis false. Note thatAssertionDefectis hidden from the effect system, so it doesn't produce{.raises: [AssertionDefect].}. This exception is only supposed to be caught by unit testing frameworks.The compiler may not generate any code at all for
assertif it is advised to do so through the-d:dangeror--assertions:offcommand line switches.
Source Editstatic: assert 1 == 9, "This assertion generates code when not built with -d:danger or --assertions:off" -
template doAssert(cond: untyped; msg = "") -
Similar to
assertbut is always turned on regardless of--assertions.
Source Editstatic: doAssert 1 == 9, "This assertion generates code when built with/without -d:danger or --assertions:off" -
template onFailedAssert(msg, code: untyped): untyped {...}{.dirty.} -
Sets an assertion failure handler that will intercept any assert statements following
onFailedAssertin the current module scope.
Source Edit# 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 -
template doAssertRaises(exception: typedesc; code: untyped) -
Raises
AssertionDefectif specifiedcodedoes not raise the specified exception. Example:
Source EditdoAssertRaises(ValueError): raise newException(ValueError, "Hello World")
© 2006–2021 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/assertions.html