RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
RSTest.hpp File Reference

Minimal unit-test framework: TEST_CASE(), CHECK() and RUN_ALL_TESTS(). More...

#include <iostream>
#include <string_view>
#include <source_location>
#include <vector>
#include <cassert>
#include <exception>
#include <chrono>

Go to the source code of this file.

Namespaces

namespace  RST
 Root namespace of RSTools.
 

Macros

#define CHECK(e, ...)   RST::RSTester::checkInternal(DECOMPOSE_CMP_OP(e, #e) __VA_OPT__(,) __VA_ARGS__)
 Checks a condition; on failure, prints the expression and its operands and stops the test.
 
#define TEST_CASE(name)
 Defines and registers a test: TEST_CASE(my_test) { CHECK(1 + 1 == 2); }.
 
#define RUN_ALL_TESTS()   RST::RSTester::TestRunner::getInstance().runAllTests()
 Runs every registered test and returns the number of failures.
 

Detailed Description

Minimal unit-test framework: TEST_CASE(), CHECK() and RUN_ALL_TESTS().

Macro Definition Documentation

◆ CHECK

#define CHECK (   e,
  ... 
)    RST::RSTester::checkInternal(DECOMPOSE_CMP_OP(e, #e) __VA_OPT__(,) __VA_ARGS__)

Checks a condition; on failure, prints the expression and its operands and stops the test.

◆ TEST_CASE

#define TEST_CASE (   name)
Value:
static void name(); \
static int CONCAT(impl, __LINE__) = RST::RSTester::TestRunner::getInstance().addTest({name, #name}); \
static void name()

Defines and registers a test: TEST_CASE(my_test) { CHECK(1 + 1 == 2); }.

◆ RUN_ALL_TESTS

#define RUN_ALL_TESTS ( )    RST::RSTester::TestRunner::getInstance().runAllTests()

Runs every registered test and returns the number of failures.