onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 1 | #define DOCTEST_CONFIG_IMPLEMENT |
ncihnegn | c5458f2 | 2019-01-28 05:08:18 -0800 | [diff] [blame] | 2 | #include <doctest/doctest.h> |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 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(); |
onqtam | 8171c48 | 2018-07-03 20:31:18 +0300 | [diff] [blame] | 7 | void some_program_code(int argc, char** argv); |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 8 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 9 | int main(int argc, char** argv) { |
onqtam | cfce188 | 2017-04-02 17:31:55 +0300 | [diff] [blame] | 10 | doctest::Context context; |
| 11 | |
| 12 | // !!! THIS IS JUST AN EXAMPLE SHOWING HOW DEFAULTS/OVERRIDES ARE SET !!! |
onqtam | 7d5c0d5 | 2016-06-02 17:50:59 +0300 | [diff] [blame] | 13 | |
| 14 | // defaults |
| 15 | context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in the name |
onqtam | 40fc39c | 2019-03-22 22:25:59 +0200 | [diff] [blame] | 16 | context.setOption("rand-seed", 324); // if order-by is set to "rand" use this seed |
onqtam | 89da654 | 2017-05-02 21:10:42 +0300 | [diff] [blame] | 17 | context.setOption("order-by", "file"); // sort the test cases by file and line |
onqtam | 7d5c0d5 | 2016-06-02 17:50:59 +0300 | [diff] [blame] | 18 | |
| 19 | context.applyCommandLine(argc, argv); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 20 | |
| 21 | // overrides |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 22 | 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] | 23 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 24 | 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] | 25 | |
onqtam | 7ffa84e | 2016-05-30 18:42:20 +0300 | [diff] [blame] | 26 | 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] | 27 | return res; // propagate the result of the tests |
| 28 | |
onqtam | 89da654 | 2017-05-02 21:10:42 +0300 | [diff] [blame] | 29 | context.clearFilters(); // removes all filters added up to this point |
| 30 | |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 31 | int client_stuff_return_code = program(); |
onqtam | 8171c48 | 2018-07-03 20:31:18 +0300 | [diff] [blame] | 32 | some_program_code(argc, argv); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 33 | // your program - if the testing framework is integrated in your production code |
| 34 | |
onqtam | 96bdf71 | 2016-09-13 16:45:52 +0300 | [diff] [blame] | 35 | 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] | 36 | } |
| 37 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 38 | TEST_CASE("[string] testing std::string") { |
| 39 | std::string a("omg"); |
| 40 | CHECK(a == "omg"); |
| 41 | } |
| 42 | |
| 43 | TEST_CASE("[math] basic stuff") { |
| 44 | CHECK(6 > 5); |
| 45 | CHECK(6 > 7); |
| 46 | } |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 47 | |
| 48 | int program() { |
onqtam | 4fe9a87 | 2016-05-30 18:51:00 +0300 | [diff] [blame] | 49 | printf("Program code.\n"); |
Martin Moene | 2e66b61 | 2016-05-30 17:18:44 +0200 | [diff] [blame] | 50 | return EXIT_SUCCESS; |
| 51 | } |