-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rst test check messages (fix #17280) #17338
Conversation
tests/stdlib/trstgen.nim
Outdated
arg: string) = | ||
let mc = msgkind.whichMsgClass | ||
let a = $msgkind % arg | ||
let message = "$1($2, $3) $4: $5" % [$filename, $line, $col, $mc, a] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use toLocation
std/private/miscdollars
rationale: DRY, and enables #690 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed though it's weird that toLocation
omits column if it's 0. So I had to change starting column to 1, which would be worth doing anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wrote it this way to avoid spurious file.nim(1, 0)
messages when column is not generated in the 1st place (eg depending on nim's flags)
IMO it's fine because valid columns are assumed to be >= 1
tests/stdlib/trstgen.nim
Outdated
result = rstToHtml(input, rstOptions, defaultConfig(), testMsgHandler) | ||
except EParseError: | ||
discard | ||
template assertEqual(s1, s2: untyped) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use unittest.check or unittest.require, don't roll your own (and assertEqual has the multiple template evaluation bug)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I switched to check
, OK.
However for code
check(warnings8[] == @["input(4, 0) Warning: unknown substitution " &
"\'citation-som\'h"])
it seems very verbose:
/home/amakarov/tmp/Nim/tests/stdlib/trstgen.nim(941, 22): Check failed: warnings8[] ==
@["input(4, 0) Warning: unknown substitution " & "\'citation-som\'h"]
warnings8[] was @["input(4, 0) Warning: unknown substitution \'citation-som\'"]
@["input(4, 0) Warning: unknown substitution " & "\'citation-som\'h"] was @["input(4, 0) Warning: unknown substitution \'citation-som\'h"]
The constant in @[...]
is repeated 3 times. Do you think check
had better be improved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are 2 things going on here:
- you're using
&
which prevent's check's eliding ofwas
msg on lhs - check's eliding doesn't work for more complex literals like seq, see unittest.check error msg shows
was
on litteral-like expressions timotheecour/Nim#650
but just assume this will eventually be fixed, and use the shorter code as you did here (it only matters when things go wrong anyway, and just hurts a bit debug experience so it's fine)
76fb6b9
to
67a436c
Compare
# TODO: find out hot to configure proper exception instead of defect | ||
expect(AssertionDefect): | ||
let output5 = input5.toHtml | ||
var error5 = new string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of having to bump up a counter, use blocks so each test is independent in terms of variables in scope (makes it easier to move them around, add some without messing re-ordering, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I suggest to do a follow-up PR for trstgen.nim
:
- split to separate tests as you said
- use
dedent
in this test everywhere
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, in a different PR is ok, to make progress faster and reviewing easier :)
Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
doAssert error != nil, "unexpected RST error '" & message & "'" | ||
error[] = message | ||
# we check only first error because subsequent ones may be meaningless | ||
raise newException(EParseError, message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: why raise only to catch later? is this to stop on 1st error? can't we instead:
- either keep track of number of errors seen here and not overwrite
error[]
after it's been written to once - or add an option roStopOnFirstError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, just to stop on 1st error.
We can do all of that but there is little sense. In the 1st commit all errors were checked but I saw that they add little value to 1st error. Check for number of errors is better but that would be difficult to develop: if you broke tests around this number then you don't know immediately what those errors were :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what i meant was keeping track of number of errors so you only set error[]
for just the 1st emitted error, and then ignoring subsequent ones. but ok, it's a minor detail.
Also observed that columns in It appears that a start column of doc comment There is a little problem here: automatic cropping logic determines number of spaces after |
@@ -25,6 +25,7 @@ from std/private/globs import nativeToUnixPath | |||
const | |||
exportSection = skField | |||
docCmdSkip = "skip" | |||
DocColOffset = "## ".len # assuming that a space was added after ## |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in reply to
Also observed that columns in nim doc (on *.nim files) are shifted by 3.
(i prefer code comments to maintain threading)
take a look at https://gist.github.com/timotheecour/e53f06241914fa1e20a40f631edfae10
run nim doc -d:case1 main
(and -d:case2, -d:case3)
before this PR, line and column number is bad
after this PR, line and column number is also bad (maybe a bit worse?)
IMO we should report line and column numbers wrt source file, and not offset it by "## ".len
; unless I'm missing something it should be both simpler and more robust.
But I suggest merging this PR to make progress and addressing this inconsistent line/col numbering in followup PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the case1 is just incorrectly adjusted line in parseHeadline
. We can fix it with an appropriate test now.
The multiline case2 and case3 are more difficult, some investigation will be needed.
@@ -497,7 +499,9 @@ proc defaultMsgHandler*(filename: string, line, col: int, msgkind: MsgKind, | |||
arg: string) = | |||
let mc = msgkind.whichMsgClass | |||
let a = $msgkind % arg | |||
let message = "$1($2, $3) $4: $5" % [filename, $line, $col, $mc, a] | |||
var message: string | |||
toLocation(message, filename, line, col + ColRstOffset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in future PR we can add an outplace version of toLocation to make life simpler in here and elsewhere, useful wherever performance is not critical (like here). Or you could also use sugar.dup
@@ -1476,7 +1476,7 @@ $content | |||
# ---------- forum --------------------------------------------------------- | |||
|
|||
proc rstToHtml*(s: string, options: RstParseOptions, | |||
config: StringTableRef, line=1, column=1, | |||
config: StringTableRef, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of specifying line, col in all callers (and doing so incorrectly, see below with (1,1) instead of (LineRstInit,ColRstInit) which is (1,0), how about add an overload of rstParse
:
proc rstParse*(text, filename: string, hasToc: var bool, options: RstParseOptions, findFile: FindFileHandler = nil, msgHandler: MsgHandler = nil): PRstNode =
rstParse(line=LineRstInit,column=ColRstInit,...)
will simplify and make these correct:
compiler/docgen.nim:161:12: result = rstParse(text, filename, line, column, hasToc, rstOptions,
lib/packages/docutils/rst.nim:2593:6:proc rstParse*(text, filename: string,
lib/packages/docutils/rstgen.nim:1509:13: var rst = rstParse(s, filen, line=LineRstInit, column=ColRstInit,
lib/packages/docutils/rstgen.nim:1523:7: rstParse(rstSource, "", line=LineRstInit, column=ColRstInit,
tests/stdlib/trstgen.nim:425:30: rstGenera.renderRstToOut(rstParse(input10, "", 1, 1, option, {}), output10)
tests/stdlib/trstgen.nim:451:32: rstGenera11.renderRstToOut(rstParse(input11, "", 1, 1, option11, {}), output11)
tests/stdlib/trstgen.nim:480:32: rstGenera12.renderRstToOut(rstParse(input12, "", 1, 1, option12, {roSupportMarkdown}), output12)
tests/stdlib/trstgen.nim:577:30: rstGenera.renderRstToOut(rstParse(input1, "", 1, 1, option, {}), output1)
can be done in cleanup PR though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will be overloaded in the future.
Pure RST part should be already correct here. The problem with columns in
I tried to put the line and column of Doc comment itself to |
let's followup here: timotheecour#658 |
Check warnings and errors in RST test. Fixes #17280 using
symbolName
implemented in #17281.Depends on #17257 since printing of line numbers / columns were changed there. So review only the latest commit: f9c427a