Skip to content
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

Allow users to provide a templated overload of PrintTo #3682

Closed
wants to merge 1 commit into from

Conversation

MakersF
Copy link

@MakersF MakersF commented Nov 25, 2021

It's currently not possible to provide an overload of PrintTo for all the types supporting a specific concept

template<typename T, typename = std::enable_if_t<MatchesConcept<T>>>
void PrintTo(const T& t, std::ostream* os) {
  // print using the concept
}

because this is as constrained as the fallback implementation defined in gtest, so the compiler considers them ambiguous.
With this change, gtest doesn't define a fallback implementation of PrintTo(), but instead checks if one is callable, and if it doesn't uses the fallback behaviour.


This change addresses #3674 and it's largely backward compatible.
These are the situations in which this is not backward compatible

  1. When printing type T, there is a PrintTo for type Q, T is convertible to Q.
    Before: fallback behaviours, After: PrintTo(Q)

There is a way to be fully backward compatible, but the implementation is more complicated (it involves simulating the old behaviour to detect whether the fallback or PrintTo would have been called), so I'm proposing this change first

It's currently not possible to provide an overload of PrintTo for all the types supporting a specific concept

template<typename T, typename = std::enable_if_t<MatchesConcept<T>>>
void PrintTo(const T& t, std::ostream* os) {
  // print using the concept
}

because this is as constrained as the fallback implementation defined in gtest, so the compiler considers them ambiguous.
With this change, gtest doesn't define a fallback implementation of PrintTo(), but instead checks if one is callable, and if it doesn't uses the fallback behaviour.
@MakersF
Copy link
Author

MakersF commented Dec 5, 2021

Closing as this is a simplification and results in currently working code not to compile. I opened another PR which has the fully backward compatible solution

@MakersF MakersF closed this Dec 5, 2021
puetzk added a commit to puetzk/googletest that referenced this pull request Sep 26, 2022
UnitTest::GetInstance()->original_working_dir() is documented public API:
https://github.com/google/googletest/blob/main/docs/reference/testing.md#original_working_dir-unittestoriginal_working_dir

and is used for things like UnitTestOptions::GetAbsolutePathToOutputFile.
So stubbing it to just return an empty string breaks many other unit tests
unnecessarily if you have a filesystem but not death tests

If there's a need to do something special for diskless systems,
seems like they should have a distinct check.

reverts e5686bb
google#3090
See google#3869 for discussion

This has now been reverted (and refactored) on `main` by google#3682,
but the refactoring is more complex than I want to cherry-pick.
So we will keep the simple revert for 0.12.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants