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

Display type name in TEMPLATE_LIST_TEST_CASE output #2537

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

cschreib
Copy link

@cschreib cschreib commented Sep 24, 2022

Description

Currentlly, when using TEMPLATE_LIST_TEST_CASE to create a templated test case, the test output refers to each type in the list by index:

Template test case with test types specified inside std::tuple - MyTypes - 0
Template test case with test types specified inside std::tuple - MyTypes - 1
Template test case with test types specified inside std::tuple - MyTypes - 2

This is easy to handle when the type list contains few elements, but does not scale very well to long type lists, and requires looking at the test code to figure out which index corresponds to which type. This PR changes the output to also show the name of the type:

Template test case with test types specified inside std::tuple - MyTypes - 0 - int
Template test case with test types specified inside std::tuple - MyTypes - 1 - char
Template test case with test types specified inside std::tuple - MyTypes - 2 - float

This is currently done using typeid(T).name(). In libstdc++, the name returned by this function is mangled, so we also have to de-mangle it using standard compiler functions. On MSVC no de-mangling is required. I don't know about other compilers.

There are other options available to get a human-readable name for a type, including macro tricks with __PRETTY_FUNCTION__ et al. I figured these were less portable, so shied away from them.

GitHub Issues

None

@tophyr
Copy link

tophyr commented Dec 2, 2023

Does this work without RTTI? I'd be interested in your opinion of 1bc18d6 which aims at the same goal, but doesn't necessitate RTTI. I think we could integrate your typeid ideas into that fairly easily, also.

@cschreib
Copy link
Author

cschreib commented Dec 2, 2023

I think it does require RTTI. In snitch I ended up using the __PRETTY_FUNCTION__ trick, which doesn't require RTTI and works well on all three major compilers. I would actually recommend switching to this other method.

@tophyr
Copy link

tophyr commented Dec 4, 2023

Thanks for the idea @cschreib! I have integrated your ideas, along with the RTTI default exhibited here and the original customization-point idea I had, in #2771.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants