-
-
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
Report generator states for failed assertions #2509
base: devel
Are you sure you want to change the base?
Report generator states for failed assertions #2509
Conversation
09c6bd4
to
b45b106
Compare
@@ -8,10 +8,12 @@ | |||
#ifndef CATCH_INTERFACES_REPORTER_HPP_INCLUDED | |||
#define CATCH_INTERFACES_REPORTER_HPP_INCLUDED | |||
|
|||
#include "catch2/interfaces/catch_interfaces_capture.hpp" |
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.
Those probably shouldn't be here, I believe my IDE auto imported those 🙄
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
return; | ||
} | ||
|
||
stream << "with " << pluralise(stats.generatorInfos.size(), "generator"_sr) << "\n"; |
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 newline should be just a character. Same below. Will fix.
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.
@@ -319,6 +319,16 @@ namespace Catch { | |||
return tracker; | |||
} | |||
|
|||
void RunContext::trackGeneratorState( GeneratorInfo info ) { | |||
// Avoid redundant entries, in case a generator is used within a loop. |
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 added the unique name to the info, so this comparison should be fine even if we have more than one generator with the same arguments on the same line. Both of them should show up. This should be tested. Where would the test go? I assume some test that runs through via the approval tests.
@@ -228,6 +228,9 @@ Generators.tests.cpp:<line number>: PASSED: | |||
REQUIRE( counter < 7 ) | |||
with expansion: | |||
3 < 7 | |||
with 1 generator | |||
line:267: GENERATE(1, 2) |
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.
Unfortunately, we can't print the variable name the generator value is assigned to, like in CAPTURE
. This is why I decided to print the GENERATE
call including the arguments. Since this can be quite long, I put the value into a separate line. Another option would be to elide long descriptions in the middle, e.g. GENERATE(values{1, 2, ..., 10 })
.
We could also offer an optional user description, but this would probably need a dedicated macro to not introduce a breaking change. Alternatively, something like GENERATE(1, 2) << "UserDescription"
could work.
@@ -219,6 +220,7 @@ namespace Detail { | |||
} | |||
|
|||
auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker.getGenerator() ); | |||
getResultCapture().trackGeneratorState(GeneratorInfo(generatorName, argumentsDescription, lineInfo, generator.currentElementAsString())); |
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 was wondering if there's maybe a "cheaper" or better way to only get the generator states, if the test fails.
@@ -319,6 +319,16 @@ namespace Catch { | |||
return tracker; | |||
} | |||
|
|||
void RunContext::trackGeneratorState( GeneratorInfo const& info ) { | |||
// Avoid redundant entries, in case a generator is used within a loop. | |||
if ( std::find( m_generatorInfos.cbegin(), |
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.
Since info.name
is already unique, we could use find_if
based on the name only. Saves extra some comparisons.
@horenmar is there anything I can do to make this PR move forward? I'm happy to address change requests or fix tests. In case this implementation is approaching the problem in the completely wrong way, I'm also happy to decline this PR. |
7760d2e
to
a83fbae
Compare
I don't think this is a workable approach. The issue I have with it is that I don't see how it would support something like the I will write up what I think is a better one later this week, but the jumping off point is a recently added generator feature: 48f3226, but there is also an issue with this approach: #2453, that I am not 100% sure on the resolution-of. |
My full thoughts about this:
|
Thanks for putting some thought into this! I already assumed that Good point on doing this all on demand. I was wondering the same I guess the problem with extending Do you think it's worth for me to further look into this? I'm happy to put more effort into this feature and help you out with it, if you believe it makes sense. |
Right, sorry. I initially only skimmed the PR, and when I found out that you are now taking string of the args to The cost to extending The other option is to add In either case Also I think that the default action of a reporter should be to just use generator indices, and there being an option to get the full element strings. The full element strings are likely to be quite noisy in practice, so they should not be used unless the user asks for them. |
Description
As a user of catch I often came across the situation that I wanted to know what the generator values were when a test failed. I'm aware of the CAPTURE API, but I always wanted something automatic.
I'm not entirely certain what kind of format would be preferred, so I'm happy to change and implement it for other reporters too. Currently, I've only implemented this for the console reporter.
Some approval tests don't pass even though I haven't touched these reporters. Any help is appreciated.
GitHub Issues
#2366