* assertions: properly fix #11545 * tests/assert: enable excessiveStackTrace * tests/assert: add test case for #11545 * tfailedassert_stacktrace: disable excessiveStackTrace * assertions: weird workaround for failing tests This fixes megatest on *nix, but have no idea why
This commit is contained in:
parent
bd55c862a6
commit
2c10b246ec
5 changed files with 22 additions and 7 deletions
|
|
@ -27,13 +27,15 @@ proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||||
Hide(raiseAssert)(msg)
|
Hide(raiseAssert)(msg)
|
||||||
|
|
||||||
template assertImpl(cond: bool, msg: string, expr: string, enabled: static[bool]) =
|
template assertImpl(cond: bool, msg: string, expr: string, enabled: static[bool]) =
|
||||||
const loc = $instantiationInfo(-1, true)
|
const
|
||||||
|
loc = instantiationInfo(fullPaths = compileOption("excessiveStackTrace"))
|
||||||
|
ploc = $loc
|
||||||
bind instantiationInfo
|
bind instantiationInfo
|
||||||
mixin failedAssertImpl
|
mixin failedAssertImpl
|
||||||
when enabled:
|
when enabled:
|
||||||
{.line: instantiationInfo(fullPaths = compileOption("excessiveStackTrace")).}:
|
{.line: loc.}:
|
||||||
if not cond:
|
if not cond:
|
||||||
failedAssertImpl(loc & " `" & expr & "` " & msg)
|
failedAssertImpl(ploc & " `" & expr & "` " & msg)
|
||||||
|
|
||||||
template assert*(cond: untyped, msg = "") =
|
template assert*(cond: untyped, msg = "") =
|
||||||
## Raises ``AssertionError`` with `msg` if `cond` is false. Note
|
## Raises ``AssertionError`` with `msg` if `cond` is false. Note
|
||||||
|
|
|
||||||
1
tests/assert/config.nims
Normal file
1
tests/assert/config.nims
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
--excessiveStackTrace:on
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
from strutils import endsWith, split
|
from strutils import endsWith, split
|
||||||
from os import isAbsolute
|
from os import isAbsolute
|
||||||
|
|
||||||
proc checkMsg*(msg, expectedEnd, name: string)=
|
proc checkMsg*(msg, expectedEnd, name: string, absolute = true)=
|
||||||
let filePrefix = msg.split(' ', maxSplit = 1)[0]
|
let filePrefix = msg.split(' ', maxSplit = 1)[0]
|
||||||
if not filePrefix.isAbsolute:
|
if absolute and not filePrefix.isAbsolute:
|
||||||
echo name, ":not absolute: `", msg & "`"
|
echo name, ":not absolute: `", msg & "`"
|
||||||
elif not msg.endsWith expectedEnd:
|
elif not msg.endsWith expectedEnd:
|
||||||
echo name, ":expected suffix:\n`" & expectedEnd & "`\ngot:\n`" & msg & "`"
|
echo name, ":expected suffix:\n`" & expectedEnd & "`\ngot:\n`" & msg & "`"
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
|
cmd: "nim $target $options --excessiveStackTrace:off $file"
|
||||||
output: '''true'''
|
output: '''true'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
const expected = """
|
const expected = """
|
||||||
tfailedassert_stacktrace.nim(34) tfailedassert_stacktrace
|
tfailedassert_stacktrace.nim(35) tfailedassert_stacktrace
|
||||||
tfailedassert_stacktrace.nim(33) foo
|
tfailedassert_stacktrace.nim(34) foo
|
||||||
assertions.nim(*) failedAssertImpl
|
assertions.nim(*) failedAssertImpl
|
||||||
assertions.nim(*) raiseAssert
|
assertions.nim(*) raiseAssert
|
||||||
fatal.nim(*) sysFatal"""
|
fatal.nim(*) sysFatal"""
|
||||||
|
|
|
||||||
11
tests/assert/trelativeassert.nim
Normal file
11
tests/assert/trelativeassert.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
discard """
|
||||||
|
cmd: "nim $target $options --excessiveStackTrace:off $file"
|
||||||
|
output: '''
|
||||||
|
test:ok
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
import testhelper
|
||||||
|
try:
|
||||||
|
doAssert(false, "msg")
|
||||||
|
except AssertionError as e:
|
||||||
|
checkMsg(e.msg, "trelativeassert.nim(9, 11) `false` msg", "test", false)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue