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

Closed
zfields opened this issue Feb 12, 2021 · 2 comments
Closed

Namespace tests with filename to reduce test naming conflicts #2175

zfields opened this issue Feb 12, 2021 · 2 comments
Labels
Good First Issue Issues that can be undertaken by someone new to the project

Comments

@zfields
Copy link

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

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.

@horenmar horenmar added the Good First Issue Issues that can be undertaken by someone new to the project label Feb 22, 2021
@horenmar
Copy link
Member

This has been resolved in fb4153e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Issues that can be undertaken by someone new to the project
Projects
None yet
Development

No branches or pull requests

2 participants