-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Testament] Extend and document message testing aids #19996
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
Conversation
e890e31 to
86f3a99
Compare
84801cd to
bfebbb6
Compare
[skip ci] # tests depend on nim-lang#19996
bfebbb6 to
30d134e
Compare
a2bb779 to
8fb4d7e
Compare
| @@ -1,12 +1,5 @@ | |||
| discard """ | |||
| cmd: "nim check $file" | |||
| errormsg: "not all cases are covered; missing: {A, B}" | |||
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.
errormsg currently overrides nimout, so I got rid of both in this test and inlined the messages.
| @@ -1,15 +1,14 @@ | |||
| discard """ | |||
| cmd: "nim check $file" | |||
| errormsg: "number out of range: '300'u8'" | |||
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.
Again, errormsg currently overrides nimout, so I got rid of both in this test and inlined the messages.
|
@ringabout, thank you for letting me know this PR is confusing. I've tried to clarify it in the first comment. |
|
This is ready for review. Any questions or comments? |
* Enable inline msgs when not reject action. Eliminates the pain of changing the line and column numbers in `nimout` or `output` while making changes to the test. * Enable using inline msgs and nimout together. Allows ease of inline msgs for the test as well as testing msgs from other modules. * Add path separator and test filename variable interpolation in msgs. Eases handling path separators in the msgs. * Add some documentation.
cf4f191 to
39e552b
Compare
Co-authored-by: Clay Sweetser <[email protected]>
Co-authored-by: Clay Sweetser <[email protected]>
Co-authored-by: Clay Sweetser <[email protected]>
|
Personally, I'd merge this in now, but @Araq will need to give the final approval. |
|
@Varriount Thank you for taking the time to review it. |
|
Thanks for your hard work on this PR! Hint: mm: orc; threads: on; opt: speed; options: -d:release |
* [Testament] Extend and document message testing aids * Enable inline msgs when not reject action. Eliminates the pain of changing the line and column numbers in `nimout` or `output` while making changes to the test. * Enable using inline msgs and nimout together. Allows ease of inline msgs for the test as well as testing msgs from other modules. * Add path separator and test filename variable interpolation in msgs. Eases handling path separators in the msgs. * Add some documentation. * Fixed lots of broken tests * Fixed more broken tests * Support multiple inline messages per a line * Fix a broken test * Revert variable substitution in `output` * Remove uneeded params * Update doc/testament.md Co-authored-by: Clay Sweetser <[email protected]> * Update testament/specs.nim Co-authored-by: Clay Sweetser <[email protected]> * Update testament/specs.nim Co-authored-by: Clay Sweetser <[email protected]> * Fix indentation Co-authored-by: quantimnot <[email protected]> Co-authored-by: Clay Sweetser <[email protected]>
[skip ci] # tests depend on nim-lang#19996
Inline Messages
After discovering the inline messages feature of testament, I realized how it would remove
annoyances I've had testing messages. The inline error messages are very useful when building
up a suite of tests, because you don't have to keep changing the line location as your tests get
changed around. However, inline error messages don't support anything other than error messages
or when the test action is
reject. That behavior doesn't allow testing desired hints and warningswith a test action of
compileorrun.I extended the inline message feature by:
Supporting actions other than
reject. This affects these current tests:Inline message not checked because the action is not
reject:Nim/tests/pragmas/tvar_macro.nim
Lines 87 to 89 in 8fb4d7e
Nim/tests/strictnotnil/tnilcheck.nim
Lines 1 to 32 in 528b6d1
Supporting more than one message for a line. I'm making use of this in Fix some
styleCheckbugs #20095:Nim/tests/stylecheck/thint.nim
Lines 23 to 26 in f7cfcfe
This change is enabled by:
Adding a message delimiter
re";\s*tt\."(regex not actually used).Changing the message line determination from the caret's (
^) line - 1, to that of the opening inline message pattern#[tt..Supporting using it along with
nimout. This is useful for simultaneously testing inline messages and expected messages from imported modules. I make use of this in Add module patching (mocking) feature to compiler #19925 where I'm testing inline messages, messages raised in a nimscript, and messages raised in another module:Nim/tests/modules/tpatchModule.nim
Lines 1 to 23 in 1df0600
Fixed inline message parsing bug that broke multi-line messages. The bug is that newlines are dropped from inline messages:
Nim/testament/specs.nim
Lines 162 to 165 in 528b6d1
There is an existing test that is affected by this:
Nim/tests/effects/teffects1.nim
Lines 1 to 44 in 528b6d1
What actually happens in this case is:
The test spec and inline messages are parsed in
testament/specs:Nim/testament/specs.nim
Line 181 in 528b6d1
The test action is internally set to
reject, because at least one of the inline messages is anErrormessage:Nim/testament/specs.nim
Line 172 in 528b6d1
nimoutis ignored because the test action isrejectand there are inline messages:Nim/testament/testament.nim
Lines 545 to 547 in 528b6d1
Nim/testament/testament.nim
Lines 390 to 397 in 528b6d1
Compiler messages are compared with inline messages by checking if the actual message contains the inline message instead of if they are identical:
Nim/testament/testament.nim
Line 358 in 528b6d1
The message of concern in this test is:
Nim/tests/effects/teffects1.nim
Lines 6 to 7 in 528b6d1
The actual message has a newline and
.raise effects differ, but the inline message is missing that part:Nim/tests/effects/teffects1.nim
Lines 38 to 42 in 528b6d1
You can change the inline message to this and it will still pass:
Variable substitution for
nimout,errormsgand inline messagesPath separator and test filename variable substitution in
nimout,errormsgand inline messages. The path separator is needed to handle messages that contain native filesystem paths. I use this in #19925:Nim/tests/modules/tpatchModule.nim
Line 9 in 1df0600
Other Bugs
nimout,ccodecheckandmaxcodesizeare not handled whenoutputoroutputsubare defined.It's useful to be able to write a single test than can:
nimout.outputsub.ccodecheckandmaxcodesize.The changes for this were done here instead of another PR, because the changes to facilitate using inline messages with actions other than
rejectalso cleanly enabled this.Breaking Changes
Since this PR changes the behavior of
nimout,errormsgand inline messages to be interpolated by means ofstrutils.%, then the variable marker ($) needs escaped in messages that don't intend any variable substitution.I think this is a minor breaking change, but a new boolean spec field could be added (ex.
subMsg) that would only format those values when it is true.