Skip to content
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

Merged
merged 3 commits into from
Mar 6, 2019
Merged

Unscoped info feature #1522

merged 3 commits into from
Mar 6, 2019

Conversation

ozars
Copy link
Contributor

@ozars ozars commented Feb 1, 2019

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 after assertionEnd every time. This enables passing info message across helper functions in assertion scope, which is not allowed currently due to local scope of INFO macro.

If this looks reasonable, I will go ahead and add complementary SECTION_INFO and TEST_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.

@ozars ozars changed the title Scoped info feat Scoped info feature Feb 1, 2019
@codecov
Copy link

codecov bot commented Feb 1, 2019

Codecov Report

Merging #1522 into master will increase coverage by 0.03%.
The diff coverage is 100%.

@@            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
Copy link

codecov bot commented Feb 1, 2019

Codecov Report

Merging #1522 into master will increase coverage by 0.07%.
The diff coverage is 100%.

@@            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

@ozars ozars changed the title Scoped info feature Unscoped info feature Feb 1, 2019
@ozars
Copy link
Contributor Author

ozars commented Feb 1, 2019

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 RunContext::assertionEnded. I am not sure if this should be expected behavior. It makes sense to me to disable clearing on WARN and keep it for other three. Suggestions?

@JoeyGrajciar
Copy link
Contributor

FAIL, FAIL_CHECK, SUCCEED and WARN are basically assertions. First three are to explicitly end the test case. WARN is special one which does not explicitly end the run but continues on failure. I guess that WARN was made like that to display the message even if the test passes. Is it really needed to have those unscoped info messages kept even after WARN?

@JoeyGrajciar
Copy link
Contributor

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.

@ozars
Copy link
Contributor Author

ozars commented Feb 2, 2019

Is it really needed to have those unscoped info messages kept even after WARN?

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).

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.

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.

@ozars
Copy link
Contributor Author

ozars commented Feb 4, 2019

@JoeyGrajciar Please check the documentation I added.

Do you want me to squash everything or leave it as-is?

docs/logging.md Outdated Show resolved Hide resolved
docs/logging.md Outdated Show resolved Hide resolved
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:
Copy link
Contributor

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

Copy link
Contributor Author

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.

@horenmar
Copy link
Member

I am back, gonna take a look on this.

@horenmar
Copy link
Member

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:

  • I am not sure that unscoped messages should be cleared at the end of a SECTION. IMO, an unscoped message that is unused by the end of a section is the result of an ad-hoc reimplementation of generators with sections:
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.

  • Under current implementation, WARN will also remove all UNSCOPED_INFOs preceding it, because it is internally implemented as an assertion with specific property set. I don't think this is optimal, and instead I would suggest resurrecting the logic using IStreamingReporter::assertionEnded return value, see catch_interfaces_reporter.h lines 193-194, and catch_run_context.cpp lines 146-168.

@ozars
Copy link
Contributor Author

ozars commented Feb 23, 2019

I am not sure that unscoped messages should be cleared at the end of a SECTION. IMO, an unscoped message that is unused by the end of a section is the result of an ad-hoc reimplementation of generators with sections:

TEST_CASE("foo") {
    int how_many = 0;
    SECTION("3 elements") { how_many = 3; }
    SECTION("5 elements") { how_many = 5; }
    ...
}

I'm not sure if I understood this use case correctly. What would be the use of SECTION without any assertions in it? Also wouldn't it be semantically more reasonable to put unscoped info in between two sections instead of just before the end of the first section if one wants some info to be printed for the second section?

I agree with WARN case. I will update accordingly.

@horenmar
Copy link
Member

Multiple SECTIONs were a way to simulate generators before Catch's generators were finished. The idea is that only one sibling section is run at a time, so it will set a new value for the variable in each run, so the complicated assertion code can be shared. That's not overly important though.

After some deliberation, I think I agree with just fixing WARN for now, because there are even more places that need some rework, e.g. the logic in RunContext::handleExpr for short-circuiting would need to handle this properly -- in the end it is probably better to get the feature in now and rewrite it later.

@ozars
Copy link
Contributor Author

ozars commented Mar 1, 2019

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.

e.g. the logic in RunContext::handleExpr for short-circuiting

Good thing you brought this up. I think I need to add another check against WARN in RunContext::assertionPassed for the same reason. Also just so you know, I found out by chance that current tests don't cover the execution path for that short-circuit. See the comment in above commit 093b3b8.

I am going to make above changes, update docs and rebase it against master, hopefully sometime this weekend.

@horenmar
Copy link
Member

horenmar commented Mar 2, 2019

I added some cosmetic changes that you can just squash down.

@ozars ozars force-pushed the scoped-info-feat branch from 2c31077 to a9f10f6 Compare March 4, 2019 00:44
ozars added 3 commits March 3, 2019 18:45
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.
@ozars ozars force-pushed the scoped-info-feat branch from a9f10f6 to be895cd Compare March 4, 2019 00:49
@ozars
Copy link
Contributor Author

ozars commented Mar 4, 2019

I will try removing message scope clear at the end of each section

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.

I think I need to add another check against WARN in RunContext::assertionPassed for the same reason.

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.

@horenmar
Copy link
Member

horenmar commented Mar 5, 2019

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.

@ozars
Copy link
Contributor Author

ozars commented Mar 6, 2019

No problem at all. I doesn't affect me. I just wanted to note it since PR fails to pass appveyor checks.

@horenmar horenmar merged commit 1701325 into catchorg:master Mar 6, 2019
@horenmar
Copy link
Member

horenmar commented Mar 6, 2019

Merged, thanks.

@ozars
Copy link
Contributor Author

ozars commented Mar 7, 2019

Thanks.

@ozars ozars deleted the scoped-info-feat branch March 7, 2019 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants