onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 1 | #define DOCTEST_CONFIG_IMPLEMENT |
| 2 | #include "doctest.h" |
| 3 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 4 | int program(); |
| 5 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 6 | int main(int argc, char** argv) { |
| 7 | doctest::Context context(argc, argv); // initialize |
| 8 | |
| 9 | // overrides |
| 10 | context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in the name |
| 11 | context.setOption("no-breaks", true); // don't break in the debugger when assertions fail |
| 12 | context.setOption("abort-after", 5); // stop test execution after 5 failed assertions |
| 13 | context.setOption("sort", "name"); // sort the test cases by their name |
| 14 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 15 | int res = context.run(); // run queries, or run tests unless --no-run is specified |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 16 | |
onqtam | 7ffa84e | 2016-05-30 18:42:20 +0300 | [diff] [blame] | 17 | if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 18 | return res; // propagate the result of the tests |
| 19 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 20 | int client_stuff_return_code = program(); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 21 | // your program - if the testing framework is integrated in your production code |
| 22 | |
| 23 | return res + client_stuff_return_code; |
| 24 | } |
| 25 | |
| 26 | #include <string> |
| 27 | |
| 28 | TEST_CASE("[string] testing std::string") { |
| 29 | std::string a("omg"); |
| 30 | CHECK(a == "omg"); |
| 31 | } |
| 32 | |
| 33 | TEST_CASE("[math] basic stuff") { |
| 34 | CHECK(6 > 5); |
| 35 | CHECK(6 > 7); |
| 36 | } |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 37 | |
| 38 | int program() { |
onqtam | 4fe9a87 | 2016-05-30 18:51:00 +0300 | [diff] [blame^] | 39 | printf("Program code.\n"); |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 40 | return EXIT_SUCCESS; |
| 41 | } |