-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doAssert, assert now print full path of failing line on error (#8555)
- Loading branch information
1 parent
81f920a
commit 3a62617
Showing
6 changed files
with
108 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## helpers used system.nim and other modules, avoids code duplication while | ||
## also minimizing symbols exposed in system.nim | ||
# | ||
# TODO: move other things here that should not be exposed in system.nim | ||
|
||
proc lineInfoToString(file: string, line, column: int): string = | ||
file & "(" & $line & ", " & $column & ")" | ||
|
||
proc `$`(info: type(instantiationInfo(0))): string = | ||
# The +1 is needed here | ||
lineInfoToString(info.fileName, info.line, info.column+1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from strutils import endsWith, split | ||
from ospaths import isAbsolute | ||
|
||
proc checkMsg*(msg, expectedEnd, name: string)= | ||
let filePrefix = msg.split(' ', maxSplit = 1)[0] | ||
if not filePrefix.isAbsolute: | ||
echo name, ":not absolute: `", msg & "`" | ||
elif not msg.endsWith expectedEnd: | ||
echo name, ":expected suffix:\n`" & expectedEnd & "`\ngot:\n`" & msg & "`" | ||
else: | ||
echo name, ":ok" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
discard """ | ||
cmd: "nim $target -d:release $options $file" | ||
output: ''' | ||
assertion occured!!!!!! false | ||
test1:ok | ||
test2:ok | ||
''' | ||
""" | ||
|
||
import testhelper | ||
|
||
onFailedAssert(msg): | ||
checkMsg(msg, "tfaileddoassert.nim(15, 9) `a == 2` foo", "test1") | ||
|
||
var a = 1 | ||
doAssert(a == 2, "foo") | ||
|
||
onFailedAssert(msg): | ||
echo("assertion occured!!!!!! ", msg) | ||
checkMsg(msg, "tfaileddoassert.nim(20, 10) `a == 3` ", "test2") | ||
|
||
doAssert(1 == 2) | ||
doAssert a == 3 |