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

run test fixture from cli #190

Closed
nscooling opened this issue Feb 28, 2019 · 5 comments
Closed

run test fixture from cli #190

nscooling opened this issue Feb 28, 2019 · 5 comments

Comments

@nscooling
Copy link

Description

There does not appear any ability to run a test fixture (similar to the way test cases and test suites can be run) from the command line.

I appreciate that a test-case with subcase seems to be your preferred model but not having this capability negates any major benefit of having Fixtures.

Can it be done without prefixing all fixture test cases with an appropriate string for regex matching?

Maybe the fixture name could be pre-pended to the test case name string to allow regex test invocation?

  • doctest version: v1.2.8
  • Operating System: OS X & Linux
  • Compiler+version: clang & g++ C++17
@onqtam
Copy link
Member

onqtam commented Feb 28, 2019

Hi! when using TEST_CASE_FIXTURE you are basically adding just another test case - the doctest runner doesn't know that this is in fact a special kind which derives from a class - it doesn't care.

Such test fixtures (which are normal test cases actually) can just as easily be put in a TEST_SUITE and then be filtered - just like normal test cases (or as you suggested a prefix in the name could be used).

I could perhaps introduce a new tag decorator and add the fixture class as a tag (or prepend it to the name of the test - which would be a breaking change), but currently using test suites is an easier way and I would prefer keeping the framework simpler.

Is using test suites enough for your needs? Let me know what you think.

@nscooling
Copy link
Author

Hi Viktor, thanks for the quick response. I guess using the TEST_SUITE approach works without changing things.

I'd guess I'd like to see the Fixture treated as a TEST_SUITE so then could filter automatically at the test suite level. From a traditional test strategy perspective, I see a Fixture akin to a test suite anyway.

What would you say were the conceptual differences between a suite and a fixture?

@onqtam
Copy link
Member

onqtam commented Feb 28, 2019

To be honest I mainly mimicked what Catch is doing (and perhaps other C++ testing frameworks).

Here is one solution you could use:

#undef DOCTEST_TEST_CASE_FIXTURE
#define DOCTEST_TEST_CASE_FIXTURE(c, ...)                                 \
    DOCTEST_IMPLEMENT_FIXTURE(DOCTEST_ANONYMOUS(_DOCTEST_ANON_CLASS_), c, \
                              DOCTEST_ANONYMOUS(_DOCTEST_ANON_FUNC_),     \
                              __VA_ARGS__* doctest::test_suite(#c))

and now when you use TEST_CASE_FIXTURE(ClassToInheritFrom, "name") it will be added automatically to the ClassToInheritFrom test suite, so you don't have to deal with test suites explicitly.

You could put that code in a header called doctest_proxy.h and have it include doctest.h and then change the semantics of the macros however you like.

Let me know if this works for you.

@nscooling
Copy link
Author

nscooling commented Feb 28, 2019

That looks great, I'll have a play and let you know.

Update: that works perfectly! any chance getting it as an enhancement request?

Thanks

@onqtam
Copy link
Member

onqtam commented Mar 2, 2019

I missed your edit of your last post (no notification) so sorry for the late reply.

I don't think that most people would see the fixture used as a test suite.

I could add it and guard it with an #ifdef with yet another config option but am reluctant to do so - it is a simple enough change for users to make on their own.

I might advertise the ability to change the behavior of the macros more in the docs but for now I'm closing this issue - let me know if you need anything else :)

@onqtam onqtam closed this as completed Mar 2, 2019
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

No branches or pull requests

2 participants