-
-
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
Missing brackets round expression in macro #607
Comments
Writing the expression in parenthesis defeats CATCH' expression decomposition. |
What am I supposed to be reading on that page that makes this issue different? [edit] My use case is: SECTION("metadata can be compared")
{
const ponder::Class& class1 = ponder::classByType<MyClass>();
const ponder::Class& class2 = ponder::classByType<MyClass2>();
REQUIRE(class1 == class1);
REQUIRE(class1 != class2);
REQUIRE(class2 != class1);
} Catch was trying to convert the rhs of the first CHECK( str == "string value" );
CHECK( thisReturnsTrue() );
REQUIRE( i == 42 ); |
Well, that what's on that page doesn't work anymore as described: Without parenthesis
With parenthesis
|
Usually the 'problem' you decribe is solved via parenthesis locally in the test:
|
Do you think that is a bug or not? Please explain. |
To get an impression of how the expression decomposition works, you may have a look at lest_decompose and follow the use of Kevlin Henney presented the idea in Rethinking Unit Testing in C++ (Video). |
If you'd written this description to start with, or it was included in the docs we probably wouldn't have this confusion. Ok, now I understand why it was trying to coerce my expression into a string, which caused my problem. In which case I still think there is a problem, that the documentation needs updating. It seems that docs make a big selling point of there being less comparison macros. But, using other systems, if I'd written |
- This change breaks the "decomposition" feature mentioned here: catchorg/Catch2#607
(It's not always easy to assess how much information is required to clear-up things for someone.) It's not the first time this confusion surfaces. Perhaps you can suggest such an improvement to the documentation via a PR? cheers, |
* catch: Remove the Boost dependency from Ponder tests. - We are now Boost free. This has been left commented out in case we need to test against Boost in the future. May be removed. Add test for variadic template args. - They all use variadic template args! - This is more args than it used to handle! Finish conversion of unit tests from Boost Test to Catch. Continue moving over to Catch. Revert Catch expression change. - This change breaks the "decomposition" feature mentioned here: catchorg/Catch2#607 Catch macro fix fixes this string conversion issue. Convert more tests over to Catch. Fix operator precedence bug in Catch. Refactor array property for Catch. Revert "Revert "Start moving over to catch."" Revert "Start moving over to catch." Start moving over to catch.
I'm not quite sure what the original issue was. You later give an example of comparing two objects of your own classes, and mention string conversions. Is this where the actual issue arises? You don't say whether the string conversion is working or not, or causing a problem or not. The string conversion is not actually part of the comparison. The comparison is on the actual typed data. The strings are used for reporting on what was actually tested (and should fall back to In general Catch does "just work" without you having to know how it works internally. It's true that it's doing a fair bit internally to achieve that - in ways that are more complex than you might expect - which is unfortunate on those rare occasions that the abstraction does leak. So I'm keen to get to the bottom of what's actually going wrong for you. Maybe it will inform tweaks to the docs. Maybe we can fix something in the implementation. |
I think the problem may be related to opaque objects that do not coerce into strings. I think I was comparing two objects and one didn't have a string representation. Putting brackets around these tests makes them work. I'll try and investigate further when I have some time. Cheers. |
My issue is this: https://github.com/philsquared/Catch/blob/master/docs/tostring.md Initially it wasn't obvious because I have a lot of templates. I have missing template specialisations for string conversion for user objects. In these cases I have to use double brackets. I'll wrap Catch in a header and add some test-only string conversion code. Thanks for following up. |
Hmm. I'll just keep this open for a response. Don't suppose there is any way of catching things that don't coerce into strings at compile time? My tests compile ok but fail because of lack of string conversion. |
There are no parentheses around CHECK( a == b );
// expands to:
( __catchResult <= a == b ).endExpression();
// which, because comparison operators have equal precedence and are left-associative,
// is equivalent to:
( (__catchResult <= a) == b ).endExpression(); And this is how Catch is able to capture (using overloaded operators) and report the values of
If, on the other hand, there were parentheses around CHECK( a == b );
// would expand to
( __catchResult <= (a == b) ).endExpression(); and Catch would never see the individual values of
|
That's weird. Can you give an example, please? |
Ok, it seems this is because I have a competing string coercion system. I was getting modified behaviour because it wasn't being included in all the tests. Adding a Catch wrapper with string conversion extensions changed the behaviour. I think I'll just have to avoid this expr design for the cases where this is a problem. |
In the
REQUIRE
macro internals there are missing brackets around theexpr
(line 27) when it is evaluated. If you compared 2 booleans then the<=
operator precedence is higher than==
and it fails.include/internal/catch_capture.hpp
Solution, add brackets.
The text was updated successfully, but these errors were encountered: