-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Unscoped info feature #1522
Unscoped info feature #1522
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1522 +/- ##
==========================================
+ Coverage 80.58% 80.61% +0.03%
==========================================
Files 121 121
Lines 3383 3389 +6
==========================================
+ Hits 2726 2732 +6
Misses 657 657 |
Codecov Report
@@ Coverage Diff @@
## master #1522 +/- ##
==========================================
+ Coverage 80.55% 80.63% +0.07%
==========================================
Files 121 121
Lines 3389 3391 +2
==========================================
+ Hits 2730 2734 +4
+ Misses 659 657 -2 |
I modified PR per #983 (comment). It seems to work as intended, however, WARN/FAIL/FAIL_CHECK/SUCCEED also clears unscoped info messages since they all eventually call |
|
Please add also documentation about this macro to docs/logging.md. Also it might be good to add an example to the examples. If you add the example add link to it in the documentation. |
Not really. I mixed two things. I'd prefer to have a variation of ordinary info messages that are not locally scoped (a variation of unscoped info messages not reset at each assertion in other words) so that it would behave exactly like INFO, but it could be created from helper functions different from INFO. Unscoped info doesn't behave this way by design. I understand it may be cumbersome to maintain many variations of info, so I am not pushing for this to be maintained officially. I think "unscoped info" is somewhat a counter-intuitive name for something scoped to assertions though. I see where you are coming from, that unscoped info is something existed before, but you may consider renaming before reintroducing it given that "info" isn't also referred as "scoped info" any more. Something like "assertive info" or "assertion info" sounds more intuitive to me, but then again I never used unscoped info when it existed (I recently started using Catch2).
Sure. I will add some documentation. I didn't see any stand alone examples just for logging messages, so I plan to add some inline examples to the documentation quoting from test cases. |
@JoeyGrajciar Please check the documentation I added. Do you want me to squash everything or leave it as-is? |
26edcbd
to
907117b
Compare
docs/logging.md
Outdated
This macro can be used for reporting information from helper functions or inner scopes because lifetime of `UNSCOPED_INFO` is limited by the assertion following whereas lifetime of `INFO` is limited by its own scope. An example: | ||
In other words, lifetime of `UNSCOPED_INFO` is limited by the following assertion (or by the end of test case/section, whichever comes first) whereas lifetime of `INFO` is limited by its own scope. | ||
|
||
These make this macro useful for reporting information from helper functions or inner scopes. An example: |
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.
These make this macro
is about differences to INFO
? Probably it might be written like These differences make this macro
or That makes this macro
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, it refers to properties explained just above. It sounds okay to me, but feel free to rephrase it and push.
I am back, gonna take a look on this. |
I had a hell of a time reasoning through this, and, apart from some cosmetic things that I can just push by myself, I have two remarks:
TEST_CASE("foo") {
int how_many = 0;
SECTION("3 elements") { how_many = 3; }
SECTION("5 elements") { how_many = 5; }
...
} As an example, our current codebase actually has multiple instances of this pattern.
|
I'm not sure if I understood this use case correctly. What would be the use of I agree with |
Multiple After some deliberation, I think I agree with just fixing |
Okay, I got what you meant with sections above. I will try removing message scope clear at the end of each section, but this change alone probably won't be enough if test cases are ran multiple times to iterate over sections and there are other assertions on that path before reaching the next section, which is quite likely. In this case, it may be hard to implement this without serious refactoring or ugly workarounds.
Good thing you brought this up. I think I need to add another check against I am going to make above changes, update docs and rebase it against master, hopefully sometime this weekend. |
I added some cosmetic changes that you can just squash down. |
This adds UNSCOPED_INFO macro, creating a log message that is stored until the end of next assertion or the end of test case, whichever comes first. These messages are not scoped locally, unlike messages created by INFO macro.
Update approval tests as new tests are added for messaging.
This solution didn't work out as I expected unfortunately. I don't have much idea about how to implement it without major changes either. So, I will depend this behavior being not overly important.
It turns out this was being handled correctly already. I splitted commits into three parts. If there are no other changes requested, it is ready to merge. ps. I rebased it against master. I've just realized some tests are failing on appveyor due to some unrelated changes inherited from the tip of the master. |
Yeah, sorry about that. For some reason, the tests are run in a slightly different order on Windows than they are run on Linux. I'll need to look into it, but didn't have the time just yet. |
No problem at all. I doesn't affect me. I just wanted to note it since PR fails to pass appveyor checks. |
Merged, thanks. |
Thanks. |
Description
Add assertion scoped information messaging functionality. Newly introduced
ASSERTION_INFO
macro stores messages kept until next assertion expression, that is, they are cleared right until afterassertionEnd
every time. This enables passing info message across helper functions in assertion scope, which is not allowed currently due to local scope ofINFO
macro.If this looks reasonable, I will go ahead and add complementary
SECTION_INFO
andTEST_CASE_INFO
macros following the same logic for sections and test cases respectively.I've added a few test cases and updated approval tests accordingly. Please verify correctness of approval tests. They looked good to me.
GitHub Issues
Related to #415, #983.