catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Added example of how to separately compile Catch's main
- Commit
fd7dde10d359785a4857358d579d9b85cdd0dd46- Author
- Martin Hořeňovský ·
- Parents
9a3788d98c38
Changes
docs/slow-compiles.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/slow-compiles.md b/docs/slow-compiles.md index 5291aecc..efb3d6b5 100644 --- a/docs/slow-compiles.md +++ b/docs/slow-compiles.md @@ -17,6 +17,32 @@ Because Catch is implemented *entirely* in headers you might think that the whol As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch +## Practical example +Assume you have the `Factorial` function from the [tutorial](tutorial.md) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`: + +```cpp +// tests-main.cpp +#define CATCH_CONFIG_MAIN +#include "catch.hpp" +``` + +```cpp +// tests-factorial.cpp +#include "catch.hpp" + +#include "factorial.h" + +TEST_CASE( "Factorials are computed", "[factorial]" ) { + REQUIRE( Factorial(1) == 1 ); + REQUIRE( Factorial(2) == 2 ); + REQUIRE( Factorial(3) == 6 ); + REQUIRE( Factorial(10) == 3628800 ); +} +``` + +After compiling `tests-main.cpp` once, it is enough to link it with separately compiled `tests-factorial.cpp`. This means that adding more tests to `tests-factorial.cpp`, will not result in recompiling Catch's main and the resulting compilation times will decrease substantially. + + --- [Home](Readme.md) \ No newline at end of file