You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CMake is used to create two executables, a Tests executable and a Main executable.
If I don't include doctest.cpp in my target sources for Main, I get undefined reference errors because it can't find a definition for all the testing stuff in doctest.
However, if I do include it I get errors because there are multiple main() functions in one target.
Ideally, I would like to be able to wrap my tests in an #ifdef that checks for whether or not an implementation is available, but I'm not sure if that's possible.
What am I supposed to do here?
The text was updated successfully, but these errors were encountered:
DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN implements the test runner and also defines a main() function.
DOCTEST_CONFIG_IMPLEMENT implements ONLY the test runner.
If you define your own main() then you should use DOCTEST_CONFIG_IMPLEMENT - have a look at the relevant docs.
You will need the test runner implemented in your main executable (that means doctest.cpp) since you are writing your tests alongside your production code.
You can also define DOCTEST_CONFIG_DISABLE when building the main executable so tests are written in the production code but aren't compiled (you will still need doctest.cpp so it all links). This way you won't need to #ifdef the tests.
You could also entirely remove the test executable and use the main executable for running the tests - docs.
Description
I would like to write my tests alongside my code, but I'm having trouble trying to figure out where to put the doctest implementation.
I have a
doctest.cpp
file that looks like this:A
main.cpp
that looks like this:thing.h
is self-explanatory, but thing.cpp looks like this:CMake is used to create two executables, a
Tests
executable and aMain
executable.If I don't include
doctest.cpp
in my target sources forMain
, I get undefined reference errors because it can't find a definition for all the testing stuff in doctest.However, if I do include it I get errors because there are multiple
main()
functions in one target.Ideally, I would like to be able to wrap my tests in an
#ifdef
that checks for whether or not an implementation is available, but I'm not sure if that's possible.What am I supposed to do here?
The text was updated successfully, but these errors were encountered: