blob: f1c2af758c250ae4b58fa9d6ec6ec03afdae5f9b [file] [log] [blame]
onqtam4a655632016-05-26 14:20:52 +03001#define DOCTEST_CONFIG_IMPLEMENT
2#include "doctest.h"
3
onqtam7cc0e962017-04-17 23:30:36 +03004#include "header.h"
5
Martin Moene2e66b612016-05-30 17:18:44 +02006int program();
onqtam8171c482018-07-03 20:31:18 +03007void some_program_code(int argc, char** argv);
Martin Moene2e66b612016-05-30 17:18:44 +02008
onqtam4a655632016-05-26 14:20:52 +03009int main(int argc, char** argv) {
onqtamcfce1882017-04-02 17:31:55 +030010 doctest::Context context;
11
12 // !!! THIS IS JUST AN EXAMPLE SHOWING HOW DEFAULTS/OVERRIDES ARE SET !!!
onqtam7d5c0d52016-06-02 17:50:59 +030013
14 // defaults
15 context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in the name
onqtam89da6542017-05-02 21:10:42 +030016 context.setOption("rand-seed", 324); // if order-by is set to "rand" ise this seed
17 context.setOption("order-by", "file"); // sort the test cases by file and line
onqtam7d5c0d52016-06-02 17:50:59 +030018
19 context.applyCommandLine(argc, argv);
onqtam4a655632016-05-26 14:20:52 +030020
21 // overrides
onqtam4a655632016-05-26 14:20:52 +030022 context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
onqtam4a655632016-05-26 14:20:52 +030023
Martin Moene2e66b612016-05-30 17:18:44 +020024 int res = context.run(); // run queries, or run tests unless --no-run is specified
onqtam4a655632016-05-26 14:20:52 +030025
onqtam7ffa84e2016-05-30 18:42:20 +030026 if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
onqtam4a655632016-05-26 14:20:52 +030027 return res; // propagate the result of the tests
28
onqtam89da6542017-05-02 21:10:42 +030029 context.clearFilters(); // removes all filters added up to this point
30
Martin Moene2e66b612016-05-30 17:18:44 +020031 int client_stuff_return_code = program();
onqtam8171c482018-07-03 20:31:18 +030032 some_program_code(argc, argv);
onqtam4a655632016-05-26 14:20:52 +030033 // your program - if the testing framework is integrated in your production code
34
onqtam96bdf712016-09-13 16:45:52 +030035 return res + client_stuff_return_code; // the result from doctest is propagated here as well
onqtam4a655632016-05-26 14:20:52 +030036}
37
onqtam4a655632016-05-26 14:20:52 +030038TEST_CASE("[string] testing std::string") {
39 std::string a("omg");
40 CHECK(a == "omg");
41}
42
43TEST_CASE("[math] basic stuff") {
44 CHECK(6 > 5);
45 CHECK(6 > 7);
46}
Martin Moene2e66b612016-05-30 17:18:44 +020047
48int program() {
onqtam4fe9a872016-05-30 18:51:00 +030049 printf("Program code.\n");
Martin Moene2e66b612016-05-30 17:18:44 +020050 return EXIT_SUCCESS;
51}