onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 1 | #define DOCTEST_CONFIG_DISABLE |
| 2 | |
| 3 | #define DOCTEST_CONFIG_IMPLEMENT |
| 4 | #include "doctest.h" |
| 5 | |
onqtam | 05bcc37 | 2017-03-17 02:10:38 +0200 | [diff] [blame] | 6 | // set an exception translator for double - as a reference |
| 7 | REGISTER_EXCEPTION_TRANSLATOR(double& e) { |
| 8 | return doctest::String("double: ") + doctest::toString(e); |
| 9 | } |
| 10 | |
onqtam | 246e817 | 2017-03-17 02:48:12 +0200 | [diff] [blame] | 11 | static doctest::String intTranslator(int ex) { return doctest::String("int: ") + doctest::toString(ex); } |
| 12 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 13 | int main(int argc, char** argv) { |
onqtam | 05bcc37 | 2017-03-17 02:10:38 +0200 | [diff] [blame] | 14 | // set an exception translator for int |
onqtam | 246e817 | 2017-03-17 02:48:12 +0200 | [diff] [blame] | 15 | doctest::registerExceptionTranslator(intTranslator); |
onqtam | 05bcc37 | 2017-03-17 02:10:38 +0200 | [diff] [blame] | 16 | |
onqtam | cfce188 | 2017-04-02 17:31:55 +0300 | [diff] [blame] | 17 | doctest::Context context; |
| 18 | |
| 19 | // !!! THIS IS JUST AN EXAMPLE SHOWING HOW DEFAULTS/OVERRIDES ARE SET !!! |
onqtam | 7d5c0d5 | 2016-06-02 17:50:59 +0300 | [diff] [blame] | 20 | |
| 21 | // defaults |
| 22 | context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in the name |
| 23 | context.setOption("no-breaks", true); // don't break in the debugger when assertions fail |
| 24 | |
| 25 | context.applyCommandLine(argc, argv); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 26 | |
| 27 | // overrides |
onqtam | cfce188 | 2017-04-02 17:31:55 +0300 | [diff] [blame] | 28 | context.setOption("abort-after", 5); // stop test execution after 5 failed assertions |
| 29 | context.setOption("order_by", "name"); // sort the test cases by their name |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 30 | |
| 31 | int res = context.run(); // run |
| 32 | |
onqtam | f720d43 | 2016-05-31 17:51:10 +0300 | [diff] [blame] | 33 | 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] | 34 | return res; // propagate the result of the tests |
| 35 | |
| 36 | int client_stuff_return_code = 0; |
| 37 | // your program - if the testing framework is integrated in your production code |
| 38 | |
onqtam | 96bdf71 | 2016-09-13 16:45:52 +0300 | [diff] [blame] | 39 | 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] | 40 | } |