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 (970B)


      1 #define DOCTEST_CONFIG_IMPLEMENT
      2 #include <doctest/doctest.h>
      3 
      4 int main(int argc, char **argv) {
      5     doctest::Context context;
      6     context.applyCommandLine(argc, argv);
      7 
      8     int res = context.run(); // run doctest
      9 
     10     // important - query flags (and --exit) rely on the user doing this
     11     if (context.shouldExit()) {
     12         // propagate the result of the tests
     13         return res;
     14     }
     15 
     16     printf("%s\n", "Hello, World!");
     17 }
     18 
     19 int factorial(const int number) {
     20     return number < 1 ? 1 : number <= 1 ? number : factorial(number - 1) * number;
     21 }
     22 
     23 TEST_CASE("testing the factorial function") {
     24     CHECK(factorial(0) == 1);
     25     CHECK(factorial(1) == 1);
     26     CHECK(factorial(2) == 2);
     27     CHECK(factorial(3) == 6);
     28     CHECK(factorial(10) == 3628800);
     29 }
     30 
     31 // running notes
     32 // ./example_exe --no-run (run normal program)
     33 // ./example_exe --exit (run tests then exit)
     34 // ./example_exe (run tests then run program)
     35 // ./example_exe --success (print successful test casts)