doctest

FORK: The fastest feature-rich C++11/14/17/20 single-header testing framework
git clone https://git.neptards.moe/neptards/doctest.git
Log | Files | Refs | README

main.cpp (1610B)


      1 #define DOCTEST_CONFIG_IMPLEMENT
      2 #include <doctest/doctest.h>
      3 
      4 #include "header.h"
      5 
      6 int program();
      7 void some_program_code(int argc, char** argv);
      8 
      9 int main(int argc, char** argv) {
     10     doctest::Context context;
     11 
     12     // !!! THIS IS JUST AN EXAMPLE SHOWING HOW DEFAULTS/OVERRIDES ARE SET !!!
     13 
     14     // defaults
     15     context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in the name
     16     context.setOption("rand-seed", 324);              // if order-by is set to "rand" use this seed
     17     context.setOption("order-by", "file");            // sort the test cases by file and line
     18 
     19     context.applyCommandLine(argc, argv);
     20 
     21     // overrides
     22     context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
     23 
     24     int res = context.run(); // run queries, or run tests unless --no-run is specified
     25 
     26     if(context.shouldExit()) // important - query flags (and --exit) rely on the user doing this
     27         return res;          // propagate the result of the tests
     28 
     29     context.clearFilters(); // removes all filters added up to this point
     30 
     31     int client_stuff_return_code = program();
     32     some_program_code(argc, argv);
     33     // your program - if the testing framework is integrated in your production code
     34 
     35     return res + client_stuff_return_code; // the result from doctest is propagated here as well
     36 }
     37 
     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 }
     47 
     48 int program() {
     49     std::cout << "Program code." << std::endl;
     50     return EXIT_SUCCESS;
     51 }