Sitelet https://web.archive.org/web/20210821152609/https://github.com/catchorg/Catch2/issues/2175
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

Namespace tests with filename to reduce test naming conflicts #2175

Open
zfields opened this issue Feb 12, 2021 · 1 comment
Open

Namespace tests with filename to reduce test naming conflicts #2175

zfields opened this issue Feb 12, 2021 · 1 comment

Comments

@zfields
Copy link

@zfields zfields commented Feb 12, 2021

Description

I have a hardware abstraction layer interface, as well as a driver interface. I have multiple drivers utilizing the HAL interface, while implementing the driver interface. This plugin approach causes me to have identically named tests across multiple test files.

For example:

TEST_CASE("init() returns `E_HAL_INIT`, when HardwareAbstractionLayer::init() returns an error", "[init][hal][error]") {

When I attempt to compile multiple test files into a single test runner, then I get the following name collisions...

error: TEST_CASE( "init() returns `SUCCESS`, when no errors occur" ) already defined.
        First seen at signal_generator.test.cpp:36
        Redefined at led_ntsc_driver.test.cpp:179

I noticed you have a flag on the test binary, --filenames-as-tags. I am curious if you could incorporate the "test case + tags" into a test identifier to achieve uniqueness.

This seems like an elegant solution to this problem, unless you already have a workaround. If so, would you please share the preferred pattern with me.

Thanks,
Zak

@horenmar
Copy link
Member

@horenmar horenmar commented Feb 13, 2021

You aren't first to ask this, and there is a relatively simple workaround, as long as you keep your test case named with string literals (strictly speaking you don't have to).

This should work

#define FILE_TEST_CASE(...) (__FILE__ __VA_ARGS__)

Caveats: It is too early in the morning to think about anonymous test cases (TEST_CASE()), but they should work, if you dynamically create the test name, you will have to do proper concatenation.

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

Successfully merging a pull request may close this issue.

None yet
2 participants