onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 1 | #define DOCTEST_CONFIG_IMPLEMENT |
| 2 | #include "doctest.h" |
| 3 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame^] | 4 | #include "header.h" |
| 5 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 6 | int program(); |
| 7 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 8 | int main(int argc, char** argv) { |
onqtam | cfce188 | 2017-04-02 17:31:55 +0300 | [diff] [blame] | 9 | doctest::Context context; |
| 10 | |
| 11 | // !!! THIS IS JUST AN EXAMPLE SHOWING HOW DEFAULTS/OVERRIDES ARE SET !!! |
onqtam | 7d5c0d5 | 2016-06-02 17:50:59 +0300 | [diff] [blame] | 12 | |
| 13 | // defaults |
| 14 | context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in the name |
onqtam | 27079bc | 2017-04-16 23:21:13 +0300 | [diff] [blame] | 15 | //context.setOption("abort-after", 5); // stop test execution after 5 failed assertions |
| 16 | context.setOption("order-by", "file"); // sort the test cases by file and line |
onqtam | 7d5c0d5 | 2016-06-02 17:50:59 +0300 | [diff] [blame] | 17 | |
| 18 | context.applyCommandLine(argc, argv); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 19 | |
| 20 | // overrides |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 21 | context.setOption("no-breaks", true); // don't break in the debugger when assertions fail |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 22 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 23 | 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] | 24 | |
onqtam | 7ffa84e | 2016-05-30 18:42:20 +0300 | [diff] [blame] | 25 | 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] | 26 | return res; // propagate the result of the tests |
| 27 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 28 | int client_stuff_return_code = program(); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 29 | // your program - if the testing framework is integrated in your production code |
| 30 | |
onqtam | 96bdf71 | 2016-09-13 16:45:52 +0300 | [diff] [blame] | 31 | return res + client_stuff_return_code; // the result from doctest is propagated here as well |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 32 | } |
| 33 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 34 | TEST_CASE("[string] testing std::string") { |
| 35 | std::string a("omg"); |
| 36 | CHECK(a == "omg"); |
| 37 | } |
| 38 | |
| 39 | TEST_CASE("[math] basic stuff") { |
| 40 | CHECK(6 > 5); |
| 41 | CHECK(6 > 7); |
| 42 | } |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 43 | |
| 44 | int program() { |
onqtam | 4fe9a87 | 2016-05-30 18:51:00 +0300 | [diff] [blame] | 45 | printf("Program code.\n"); |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 46 | return EXIT_SUCCESS; |
| 47 | } |