-
Notifications
You must be signed in to change notification settings - Fork 10.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
Print C++17 types (any, optional, string_view and variant) and absl::any #2438
Conversation
c76b1f3
to
b76b791
Compare
I like the idea here, but I think we need to have a bit of internal discussion first about how we want to support this. |
Cool! Let me know what you lot decided, though mind I believe I've made it consistent with the current code (should you want to refactor sth). |
Thanks for this PR. After internal discussion, we are going to have googletest take a hard dependency on Abseil very soon. Which means that compiling with C++17, all the types will be the standard types and have correct printing, and without C++17, the Abseil backports will have correct printing and the standard ones won't be available. So I think this PR won't be necessary. Thanks again though, for this effort as well as all the other PRs you've sent. They're super useful and very much appreciated. |
Thank you for recognition! |
@asoffer ping |
@asoffer, please note that my code uses string_views and I get bad formatting. Even my custom PrintTo() function doesn't work, check out this: #include <string_view>
#include <gtest/gtest.h>
void PrintTo(std::string_view const s, std::ostream* const str)
{
*str << "view";
}
TEST(FailAndPrint, MyTest)
{
using namespace std::string_view_literals;
EXPECT_EQ("this is"sv, "not equal"sv);
} As a user, I'm not supposed to alter ::testing::internal and std namespaces - however in order to make my string_views work I would need to inject my function into either of these places to make ADL work. |
If you're using C++17, absl::{optional, variant, any, string_view} are all the same type as the std equivalents, so unless I'm missing something this should all "just work" fine. You do not need to spell it with the absl:: namespace qualification. If any of this doesn't work, please open up issues. The googletest dependency on Abseil is more about using Abseil internally and should not impose any requirements on how users write tests. |
But I've already pinned a related issue :) It's #2437 and it basically tells you that not only is GTest unable to print those types, but also there are some Valgrind issues. |
Ok, @asoffer. I didn't know what you meant was the latest "Coming soon":
which appeared a few days ago. Yes, it will work too for std::string_view I think. Please mind the other types! What I wrote here:
effecitively means that this particular function will not work for |
@asoffer ping |
Resolves #2437.
Future work:
Matchers could now support wide string_views. This is something new; Abseil doesn't support this one.