libept
Classes | Namespaces | Macros | Functions | Variables
tests.h File Reference
#include <string>
#include <sstream>
#include <exception>
#include <functional>
#include <vector>

Go to the source code of this file.

Classes

struct  ept::tests::LocationInfo
 Add information to the test backtrace for the tests run in the current scope. More...
 
struct  ept::tests::TestStackFrame
 Information about one stack frame in the test execution stack. More...
 
struct  ept::tests::TestStack
 
struct  ept::tests::TestFailed
 Exception raised when a test assertion fails, normally by Location::fail_test. More...
 
struct  ept::tests::Actual< A >
 
struct  ept::tests::ActualCString
 
struct  ept::tests::ActualStdString
 
struct  ept::tests::ActualDouble
 
struct  ept::tests::ActualFunction
 
struct  ept::tests::TestMethodResult
 Result of running a test method. More...
 
struct  ept::tests::TestCaseResult
 Result of running a whole test case. More...
 
struct  ept::tests::TestController
 Abstract interface for the objects that supervise test execution. More...
 
struct  ept::tests::SimpleTestController
 Simple default implementation of TestController. More...
 
struct  ept::tests::TestRegistry
 Test registry. More...
 
struct  ept::tests::TestMethod
 Test method information. More...
 
struct  ept::tests::TestCase
 Test case collecting several test methods, and self-registering with the singleton instance of TestRegistry. More...
 
struct  ept::tests::Fixture
 Base class for test fixtures. More...
 
struct  ept::tests::FixtureTestCase< FIXTURE >
 Test case that includes a fixture. More...
 

Namespaces

 ept
 String functions.
 
 ept::tests
 

Macros

#define EPT_TEST_INFO(name)
 Use this to declare a local variable with the given name that will be picked up by tests as extra local info. More...
 
#define wassert(...)
 Run the given command, raising TestFailed with the appropriate backtrace information if it threw an exception. More...
 
#define wassert_true(...)   wassert(actual(__VA_ARGS__).istrue())
 Shortcut to check that a given expression returns true. More...
 
#define wassert_false(...)   wassert(actual(__VA_ARGS__).isfalse())
 Shortcut to check that a given expression returns false. More...
 
#define wcallchecked(func)
 Call a function returning its result, and raising TestFailed with the appropriate backtrace information if it threw an exception. More...
 

Functions

template<typename A >
void ept::tests::assert_true (const A &actual)
 Test function that ensures that the actual value is true. More...
 
void ept::tests::assert_true (std::nullptr_t actual)
 
template<typename A >
void ept::tests::assert_false (const A &actual)
 Test function that ensures that the actual value is false. More...
 
void ept::tests::assert_false (std::nullptr_t actual)
 
template<typename A , typename E >
void ept::tests::assert_equal (const A &actual, const E &expected)
 Test function that ensures that the actual value is the same as a reference one. More...
 
template<typename A , typename E >
void ept::tests::assert_not_equal (const A &actual, const E &expected)
 Test function that ensures that the actual value is different than a reference one. More...
 
template<typename A , typename E >
void ept::tests::assert_less (const A &actual, const E &expected)
 Ensure that the actual value is less than the reference value. More...
 
template<typename A , typename E >
void ept::tests::assert_less_equal (const A &actual, const E &expected)
 Ensure that the actual value is less or equal than the reference value. More...
 
template<typename A , typename E >
void ept::tests::assert_greater (const A &actual, const E &expected)
 Ensure that the actual value is greater than the reference value. More...
 
template<typename A , typename E >
void ept::tests::assert_greater_equal (const A &actual, const E &expected)
 Ensure that the actual value is greather or equal than the reference value. More...
 
void ept::tests::assert_startswith (const std::string &actual, const std::string &expected)
 Ensure that the string actual starts with expected. More...
 
void ept::tests::assert_endswith (const std::string &actual, const std::string &expected)
 Ensure that the string actual ends with expected. More...
 
void ept::tests::assert_contains (const std::string &actual, const std::string &expected)
 Ensure that the string actual contains expected. More...
 
void ept::tests::assert_not_contains (const std::string &actual, const std::string &expected)
 Ensure that the string actual does not contain expected. More...
 
void ept::tests::assert_re_matches (const std::string &actual, const std::string &expected)
 Ensure that the string actual matches the extended regular expression expected. More...
 
void ept::tests::assert_not_re_matches (const std::string &actual, const std::string &expected)
 Ensure that the string actual does not match the extended regular expression expected. More...
 
template<typename A >
Actual< A > ept::tests::actual (const A &actual)
 
ActualCString ept::tests::actual (const char *actual)
 
ActualCString ept::tests::actual (char *actual)
 
ActualStdString ept::tests::actual (const std::string &actual)
 
ActualDouble ept::tests::actual (double actual)
 
ActualFunction ept::tests::actual_function (std::function< void()> actual)
 

Variables

const ept::tests::LocationInfo ept_test_location_info
 

Macro Definition Documentation

◆ EPT_TEST_INFO

#define EPT_TEST_INFO (   name)
Value:
ept::tests::LocationInfo& name = ept_test_location_info
Add information to the test backtrace for the tests run in the current scope.
Definition: tests.h:53
const ept::tests::LocationInfo ept_test_location_info
Definition: tests.cc:20

Use this to declare a local variable with the given name that will be picked up by tests as extra local info.

◆ wassert

#define wassert (   ...)
Value:
do { try { \
__VA_ARGS__ ; \
} catch (TestFailed& e) { \
e.add_stack_info(__FILE__, __LINE__, #__VA_ARGS__, ept_test_location_info); \
throw; \
} catch (std::exception& e) { \
throw TestFailed(e, __FILE__, __LINE__, #__VA_ARGS__, ept_test_location_info); \
} } while(0)
const ept::tests::LocationInfo ept_test_location_info
Definition: tests.cc:20

Run the given command, raising TestFailed with the appropriate backtrace information if it threw an exception.

If the command raises TestFailed, it adds the current stack to its stack information.

Referenced by register_tests(), and ept::tests::ActualFunction::throws().

◆ wassert_false

#define wassert_false (   ...)    wassert(actual(__VA_ARGS__).isfalse())

Shortcut to check that a given expression returns false.

◆ wassert_true

#define wassert_true (   ...)    wassert(actual(__VA_ARGS__).istrue())

Shortcut to check that a given expression returns true.

Referenced by register_tests().

◆ wcallchecked

#define wcallchecked (   func)
Value:
[&]() { try { \
return func; \
} catch (TestFailed& e) { \
e.add_stack_info(__FILE__, __LINE__, #func, ept_test_location_info); \
throw; \
} catch (std::exception& e) { \
throw TestFailed(e, __FILE__, __LINE__, #func, ept_test_location_info); \
} }()
const ept::tests::LocationInfo ept_test_location_info
Definition: tests.cc:20

Call a function returning its result, and raising TestFailed with the appropriate backtrace information if it threw an exception.

If the function raises TestFailed, it adds the current stack to its stack information.

Variable Documentation

◆ ept_test_location_info

const ept::tests::LocationInfo ept_test_location_info