Feature request: Custom typeinfo
Sometimes it would be useful to do typed tests on incomplete types.
While that can be achieved by turning RTTI off (typeid does not work with incomplete types), type information is then obviously missing in the report (you only get "<type>" for any test case).
There are other ways of obtaining type information (even at compile time - e.g. boost typeindex) but I completely understand you probably don't want to add unnecessary dependencies.
However, a mechanism could be added for the user to provide his own typeinfo function.
template <typename T>
std::string GetTypeName() {
# if GTEST_HAS_CUSTOM_TI
const char* const name = GTEST_CUSTOM_GETTYPENAME(T);
# elif GTEST_HAS_RTTI
const char* const name = typeid(T).name();
...
# else
return "<type>";
# endif
}
Something like this perhaps? I think this could be useful to anyone who cannot use RTTI for some reason but still wants some type information.
I have been cleaning up older and inactive GitHub googletest issues. You may see an issue "closed" if it appears to be inactive/abandoned Thank you
Actually, this feature would be nice to have. I happen to have RTTI disabled on some projects with type-parameterized tests, and where TypeParam = <type> in gtest output really isn't helpful.
I resort to adding a specialization to internal namespace, which feels brittle:
namespace testing::internal { // dirty hack to have type names despite -fno-rtti
template <> std::string GetTypeName<feature::plain>() { return "plain"; }
template <> std::string GetTypeName<feature::sse2>() { return "sse2"; }
template <> std::string GetTypeName<feature::avx2>() { return "avx2"; }
template <> std::string GetTypeName<feature::avx512>() { return "avx512"; }
}
Having some similar mechanism not buried in an internal namespace would be great.
Should I open a new issue or is re-opening this one ok?
There are two distinct issues here:
- Tolerating incomplete types in typed tests. This was forcing OP to turn RTTI off.
- When RTTI is off, use anything better than "<type>" in diagnostics.
Fully customizable typeinfo is a solution to both. There are other solution of differing quality and difficulty as well. We don't need full typeinfo. We only need a name for diagnostics.
For example, we may be able to parse meaningful type names from the __PRETTY_FUNCTION__ variable.
For example, we may be able to parse meaningful type names from the
__PRETTY_FUNCTION__variable.
This is exactly what boost typeindex does when RTTI is turned off. I use it with patched gtest.
Anyway, nice to hear that someone else beside myself finds this useful. :D
Any updates on this? Would be really nice to be able either to inject something or have it figured out from PRETTY_FUNCTION
Looks like this was previously requested as well: #415
This is a pretty old issue, but it seems like some way of custom-naming types has been a desirable feature for at least some users for quite a while... it's been a while, but maybe this issue is still worth re-opening?