Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-02-11 19:11:57 +0100
committerMartin Hořeňovský2017-02-11 19:11:57 +0100
commitfd7dde10d359785a4857358d579d9b85cdd0dd46 (patch)
tree2c2092774cb9050b508827063828ae96058698c7 /docs
parent9a3788d98c38b5491a8e90079fd6e69cf321318a (diff)
downloadcatch3-fd7dde10d359785a4857358d579d9b85cdd0dd46.tar.gz
Added example of how to separately compile Catch's main
Closes #632
Diffstat (limited to 'docs')
-rw-r--r--docs/slow-compiles.md26
1 files changed, 26 insertions, 0 deletions
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