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

FAQ item request: Accessing current testcase name #345

Open
eyalroz opened this issue Mar 2, 2020 · 4 comments
Open

FAQ item request: Accessing current testcase name #345

eyalroz opened this issue Mar 2, 2020 · 4 comments
Labels
category/API-usage Issues regarding the core usage API such as macros or matchers has-workaround There is a workaround for the issue which can be used before (and if) fixing type/feature-proposal

Comments

@eyalroz
Copy link

eyalroz commented Mar 2, 2020

I couldn't find this in the documentation or the FAQ: Is it possible to obtain the current test case's name from within that testcase's code? I mean, it should be, but how do we do it? That should be either in the FAQ or in some other relevant documentation file, IMHO.

@onqtam
Copy link
Member

onqtam commented Mar 2, 2020

That's a good idea. I'll probably look into this for the next version of doctest, and maybe I should also look at #184 - basically the ability to introspect what is registered.

For now what you can do is define a function like the following:

const char* getCurrentTestName() { return doctest::detail::g_cs->currentTest->m_name; }

in the translation unit where the framework is implemented (where DOCTEST_CONFIG_IMPLEMENT is defined) and then you can forward declare it anywhere you choose and use it.

@Lectem
Copy link
Contributor

Lectem commented Sep 8, 2020

I also think this would be a good feature to have.
My use case is when doing benchmarks with nanobench, it would be practical to use the same name for the benchmark and the test. getCurrentTestName would be great because in the case of templated test cases, it already includes the template parameters.

@zeroxia
Copy link

zeroxia commented May 16, 2022

Besides getCurrentTestCaseName(), can we also have getCurrentSubCaseName()?
I hope we can see these API's soon, thanks!

@pablode
Copy link

pablode commented Feb 5, 2024

Would love to see this feature added!

@cdeln cdeln added enhancement has-workaround There is a workaround for the issue which can be used before (and if) fixing type/feature-proposal category/API-usage Issues regarding the core usage API such as macros or matchers and removed enhancement labels Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category/API-usage Issues regarding the core usage API such as macros or matchers has-workaround There is a workaround for the issue which can be used before (and if) fixing type/feature-proposal
Projects
None yet
Development

No branches or pull requests

6 participants