char*
) actually comparing pointers?Pros of doctest:
DOCTEST_CONFIG_DISABLE
identifierAside from everything mentioned so far doctest has some small features which Catch doesn't but currently nothing big.
Missing stuff:
std::exception
don't get their .what()
method calledTEST_CASE("[myTag] test name")
)INFO
/CONTEXT
But all these things (and more!) are planned in the roadmap!
doctest can be thought of as a very polished, light, stable and clean subset (or reimplementation) of Catch but this will change in the future as more features are added.
Using the fast asserts in combination with DOCTEST_CONFIG_SUPER_FAST_ASSERTS
yelds the fastest compile times.
There are only 2 drawbacks of this approach:
CHECK(a==b)
) means that there is no try/catch
block in each assert so if an expression throws the whole test case ends.DOCTEST_CONFIG_SUPER_FAST_ASSERTS
config identifier will result in even faster fast asserts (30-80%) at the cost of only one thing: when an assert fails and a debugger is present - the framework will break inside a doctest function so the user will have to go 1 level up in the callstack to see where the actual assert is in the source code.These 2 things can be considered negligible if you are dealing mainly with arithmetic (expressions are unlikely to throw exceptions) and all the tests usually pass (you don't need to often navigate to a failing assert with a debugger attached)
If you want better aliases for the asserts instead of the long ones you could use DOCTEST_CONFIG_NO_SHORT_MACRO_NAMES
and then define your aliases like this: #define CHECK_EQ DOCTEST_FAST_CHECK_EQ
(example in here).
Currently no. Asserts cannot be used in multiple threads and test cases cannot be ran in parallel. These are long-term features that are planned on the roadmap.
For now tests are ran serially and doing asserts in multiple user threads will lead to crashes.
There is an option to run a range of tests from an executable - so tests can be ran in parallel with multiple process invocations - see the example (the run.py script).
This is a common problem and it affects all modern compilers on all platforms.
The problem is that when a static library is being linked to a binary (executable or dll) - only object files from the static library that define a synbol being required from the binary will get pulled in (this is a linker/dependency optimization).
I have created a CMake function that forces every object file from a static library to be linked into a binary target - it is called doctest_force_link_static_lib_in_target()
. It is unintrusive - no source file gets changed - everything is done with compiler flags per source files. An example project using it can be found here.
It doesn't work in 2 scenarios:
For an alternative you can checkout the pthom/doctest_registerlibrary repository.
char*
) actually comparing pointers?doctest by default treats char*
as normal pointers. Using the DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
changes that.
There are 2 options:
#ifdef DOCTEST_LIBRARY_INCLUDED
and #endif
- that way your tests will be compiled and registered if the user includes the doctest header before your headers (and he will also have to implement the test runner somewhere).Also note that it would be a good idea to add a tag in your test case names (like this: TEST_CASE("[the_lib] testing foo")
) so the user can easily filter them out with --test-case-exclude=*the_lib*
if he wishes to.
Yes. The REQUIRE
family of asserts uses exceptions to terminate the current test case when they fail. An exception is used instead of a simple return;
because asserts can be used not only in a test case but also in functions called by a test case.
It hasn't been tested yet what happens when compiling with -fno-exceptions
.
Try using the DOCTEST_CONFIG_USE_IOSFWD
configuration identifier.
Currently no. Single header libraries like stb have this as an option (everything gets declared static - making it with internal linkage) but it isn't very logical for doctest - the main point is to write tests in any source file of the project and have the test runner implemented in only one source file.
Aren't they evil and not modern? - Check out the answer Phil Nash gives to this question here (the creator of Catch).
Look at this example in the repository.