overload PrintTo for std::type_info and std::type_index#3184
Conversation
deaa69f to
d782fbb
Compare
6cf8920 to
62b6685
Compare
|
Hi! I have two findings here:
|
|
@kuzkry Thanks for your comment, Krystian.
Thanks for the suggestion. I think I'll amend this pull request tomorrow, to add an
Are you sure it should? I mean, would it harm to query the name of a type when |
c5b6fbf to
9369ca2
Compare
9369ca2 to
370c039
Compare
|
@kuzkry Can you please check if I have addressed both of your findings correctly by my force-pushes? |
Heh, I see you took your time to find my actual name, nice :D
Thanks too :) That looks good to me.
Good point, indeed. Therefore, it's not like it should, but it could :) I think it does no harm really and you're right, we don't need it. If we keep it without
Sure. I'm gonna reply in the thread of your inline comment. Last but not least, I've just come up with this one. Did you know this?
So our equality matchers may fail on this: const std::type_info& ti1 = typeid(A);
const std::type_info& ti2 = typeid(A);
EXPECT_EQ(&ti1, &ti2); // not guaranteedBut maybe it's too much for the testing framework and it shouldn't take care of it. |
kuzkry
left a comment
There was a problem hiding this comment.
This is the point where I can only say I like it and wish you good luck with getting it approved by maintainers :)
|
For the record, it appears that the following compiles well, even with Tested on GCC 10.2 and Clang 11.0.0 at https://godbolt.org/z/jsvr1s Whereas a simple
Visual C++ does seem to support msvc v19.28 says at https://godbolt.org/z/Ps85nf
|
370c039 to
ae50871
Compare
@kuzkry Thank you very much for your approval, Krystian! |
@kuzkry Indeed! Fortunately, |
Yeah, no problem with it then. It becomes problematic when addresses are compared. |
kuzkry
left a comment
There was a problem hiding this comment.
Sorry to bother you, but I've found something about GTEST_HAS_RTTI here:
gtest-port.h includes <typeinfo> there conditionally (no other file in GoogleTest includes this btw.) so I think that's the place where you should move your <typeindex> inclusion and actually hide your printers under #ifdef GTEST_HAS_RTTI. Upon closer inspection, I think this fits better because everything related to RTTI relies on this switch and it's strictly followed rule.
kuzkry
left a comment
There was a problem hiding this comment.
I would like just to unapprove it but GitHub forces me to request changes.
@kuzkry Thanks for having another look at this pull request. Can you please elaborate a little bit more? Specifically, could those two googletest/googletest/include/gtest/gtest-printers.h Lines 109 to 110 in ae50871 After having tried |
|
Hey @N-Dekker, I'm sorry for not answering that earlier :( It slipped through my list. I think you're right and what you did is fine 👍 I just meant we should probably try to conform to existing style and unify it with how RTTI is generally handled in GoogleTest. I didn't want to go into details but gtest-port.h is quite special.
gtest-port.h exists so that GoogleTest can keep platform specific dilemmas away from the rest of GoogleTest code and make it more platform agnostic. And it makes sense that support for RTTI is determined there and the rest of the code simply conforms to that, hence the comment:
Last but not least, you can always empirically verify that all RTTI-specific classes (from standard |
|
@kuzkry Thanks you for your explanation, Krystian. Personally I would rather not add an extra |
|
I agree with Krystian's suggestion to guard the overloads with an
Otherwise, this PR looks good to me. |
ae50871 to
59236b5
Compare
|
@dinord @kuzkry FYI The force-push that I just did is only the result of a |
Included the string returned by their `name()` member function with the output of `PrintTo`.
Typical use case:
std::unique_ptr<AbstractProduct> product = FactoryMethod();
// Assert that the product is of type X:
ASSERT_EQ(std::type_index{typeid(*product)},
std::type_index{typeid(ProductX)});
Possible output in case of a test assert failure, now including the names of the compared type indices:
> error: Expected equality of these values:
> std::type_index(typeid(*product))
> Which is: 8-byte object <D0-65 54-8C F6-7F 00-00> ("class ProductY")
> std::type_index(typeid(ProductX))
> Which is: 8-byte object <40-64 54-8C F6-7F 00-00> ("class ProductX")
With help from Krystian Kuzniarek.
59236b5 to
ac3c2a8
Compare
|
@dinord @kuzkry Update: Addressed the RTTI issue with my latest force-push, I hope it's OK to you! |
|
@dinord Hi Dino! Thanks you for looking at this pull request of mine! I see you added a label, last week, "imported-into-CL", I'm interested to hear from you what that means! Anyway, I really hope this PR will make it onto the master branch 😃 What do you think? |
|
My guess is that it's a maintainers' marker saying your PR is actually being reviewed in the context of true GoogleTest. Because actually this repository is a mirror and the original one is stored on Google servers. It probably runs some superior continuous integration that checks if that breaks code at Google. I guess typo fixes and easy stuff do not require expensive validations to be done so you won't see it in every PR. Please hire me 😂 |
|
@N-Dekker your PR is going through our internal import process. |
|
Thank you for contributing to GoogleTest, Niels! |
Included the string returned by their
name()member function with the output ofPrintTo.Typical use case:
Possible output in case of a test assert failure, now including the names of the compared type indices:
With help from Krystian Kuzniarek (@kuzkry).