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

Allow same name test cases with different tags #1999

Closed
michaelvlach opened this issue Aug 5, 2020 · 2 comments
Closed

Allow same name test cases with different tags #1999

michaelvlach opened this issue Aug 5, 2020 · 2 comments
Milestone

Comments

@michaelvlach
Copy link
Contributor

Description
Suppose I have a test case TEST_CASE("Examples", "[Class1]") and TEST_CASE("Examples", "[Class2]") in two different tests I get the error from Catch2 due to duplicate test case name. I have encountered several times now this situation where the tests are named the same (and rightfully so) but they need to be somehow disambiguated despite having different tags. So I would like to request kind of "overloading" the test case name on tags. What I usually end up with is: TEST_CASE("Example [Class1]", "[Class1]") and being DRY believer I don't like it. Hence this request. Perhaps only the detection of the duplicates could be enhanced so that rather than failing it would append the tags to the name first (as an alias?) to see if it helps (but still failing if it did not). Or include surrounding namespace? But that is probably unknowable in a macro.

@horenmar
Copy link
Member

horenmar commented Aug 6, 2020

Surrounding namespace detection could be possible with some __FUNCTION__ trickery, but it is not something reasonable to do.

Anyway, I am considering to allow TEST_CASEs with the same name as long as they have different source location (so file+line) for v3. However, I won't be porting this change to v2... What you can do to fix this for yourself now is to add a MY_TEST_CASE like this

#define MY_TEST_CASE(testName, tags) TEST_CASE(testName tags, tags)

Obviously this is a toy definition that has some problems (tags are now required, both test name and tags have to be a string literal), but those should be fixable with some minor complications.

@mv185095
Copy link

mv185095 commented Aug 6, 2020

Thanks a lot! I would happily adopt Catch2 v3 so no need to backport it. Doing it per source sounds perfectly fine. Looking forward to it in v3. :-)

@horenmar horenmar added this to the 3.0 milestone Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants