diff options
-rw-r--r-- | lib/system.nim | 7 | ||||
-rw-r--r-- | tests/assert/tfailedassert_stacktrace.nim | 19 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/system.nim b/lib/system.nim index 4552c6304..caa6e9bfd 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -3784,8 +3784,11 @@ template assertImpl(cond: bool, msg = "", enabled: static[bool]) = bind instantiationInfo mixin failedAssertImpl when enabled: - if not cond: - failedAssertImpl(loc & " `" & astToStr(cond) & "` " & msg) + # for stacktrace; fixes #8928 ; Note: `fullPaths = true` is correct + # here, regardless of --excessiveStackTrace + {.line: instantiationInfo(fullPaths = true).}: + if not cond: + failedAssertImpl(loc & " `" & astToStr(cond) & "` " & msg) template assert*(cond: bool, msg = "") = ## Raises ``AssertionError`` with `msg` if `cond` is false. Note diff --git a/tests/assert/tfailedassert_stacktrace.nim b/tests/assert/tfailedassert_stacktrace.nim new file mode 100644 index 000000000..a3edeb9bf --- /dev/null +++ b/tests/assert/tfailedassert_stacktrace.nim @@ -0,0 +1,19 @@ +discard """ + output: ''' +tfailedassert_stacktrace.nim(16) tfailedassert_stacktrace +tfailedassert_stacktrace.nim(15) foo +system.nim(3777) failedAssertImpl +system.nim(3770) raiseAssert +system.nim(2817) sysFatal +''' +""" + + + +try: + proc foo() = + assert(false) + foo() +except AssertionError: + let e = getCurrentException() + echo e.getStackTrace |