-
-
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
Generator::currentElementAsString breaks compilation of a lot of our tests #2453
Comments
That's an interesting use case for The reason for |
It has saved us so many times that I wouldn't want to live without it. The problem with stringification is that it can break so easily. Maybe through a refactoring, a header that defines Not to mention the problem of ODR violations, where forgetting an include in one compilation unit can break stringification in all other compilation units too. This can be extremely difficult to diagnose, and again this is nicely solved in our setup.
Yes, I understand all that, and it would indeed be nice if reporting for generater-based tests would have more information about which row is failing. However, I'm not convinced that stringifying the entire generator element is the right solution. As shown in my example above, generator elements can often consist of a mixture of inputs and expected outputs (and sometimes even other unrelated stuff), and it's really only the inputs that are required to identify the generator row. The current crutch of using |
I'd be interested in suggestions how to work around the issue (apart from "don't abuse Subclassing I experimented with using a custom tuple type that has a custom I'd also be interested in thoughts about my previous comment, regarding the approach of stringifying the entire generator element to identify it. I find this problematic for the given reasons, and I think it would be worth rethinking the approach. For example, maybe there could be a way to attach description strings to generator elements (somehow), and reporters would use those if available, or fallback to the index if not. |
Maybe an alternative could be to offer a more straightforward solution to allow compilation to fail if a type cannot be stringified. And if that solution supports somehow checking the context (e.g. a non-stringifiable type used in a |
I gave this some thought for #2509. I still believe that the ability to print out stringified generator states is too valuable to give up, so, here are two options I see for this (apart from ignoring it, because this is not the intended use of fallback stringifier 😃).
|
Thanks for looking into this! We solved our problem a while ago by actually implementing all the missing stringifiers for all the types we use in GENERATE statements, so it's no longer a pressing issue for us. I'd be ok with simply closing this issue for now. Depending on how #2509 turns out, the biggest issue might not be getting everything to compile at all, but output that is too noisy. In the example from the issue description above, only |
Agreed, I intend the default output to be just the "indices" of active generators, but let the users ask for full stringification. Luckily, there is now a way to pass options to individual reporters, which this option can use. |
In 48f3226, a new method
currentElementAsString
was added to generators. As far as I can tell, it isn't used for anything.The problem is that this breaks compilation of a lot of our tests, with no obvious workaround. The reason is that we define
CATCH_CONFIG_FALLBACK_STRINGIFIER
to a non-existing symbol in order to catch mistakes where failingCHECK
s wouldn't stringify correctly. This is very useful, and actually I think it should be the default.But this now causes compilation failures for
GENERATE
statements where the type that's generated isn't stringifiable.To illustrate, here's a common pattern that we tend to use a lot in our tests:
In this example,
InputType1
andInputType2
are stringifiable, and have to be because of theCAPTURE
.SomeHelper
might, for example, be astd::function
.ExpectedOutput1
andExpectedOutput2
only need to be stringifiable if they appear in aCHECK
statement, which they often do, but don't necessarily have to.I'd appreciate advice how to work around this. I suppose I could subclass
FixedValuesGenerator
with an overwrittenstringifyImpl
method (which would onlyassert(false)
?), but this seems like a lot of work.For now we revert 48f3226 locally, but this is not a satisfactory long-term solution either, of course.
The text was updated successfully, but these errors were encountered: