MT Core (C++)
Core library for replacing C++ standard in project usage
Loading...
Searching...
No Matches
mttest::TestContext Struct Reference

Context for unit tests. More...

#include <mttest.hpp>

Classes

struct  test_err
 
struct  test_fail
 

Public Member Functions

void add_error (const std::string &cond, const std::runtime_error &err, const std::string &file, size_t line)
 
void add_error (const std::string &cond, int err, const std::string &file, size_t line)
 
void add_error (const std::string &cond, const std::string &file, size_t line)
 
void add_failure (const std::string &cond, const std::string &file, size_t line)
 
void add_failure (const std::string &cond, const std::string &msg, const std::string &file, size_t line)
 
template<typename L, typename R>
void add_failure (const std::string &comp, const std::string &raw, const L &left, const R &right, const std::string &file, size_t line)
 

Public Attributes

std::vector< test_errerrors = {}
 
std::vector< test_failfailures = {}
 

Detailed Description

Context for unit tests.

Definition at line 108 of file mttest.hpp.

Member Function Documentation

◆ add_error() [1/3]

void mttest::TestContext::add_error ( const std::string & cond,
const std::runtime_error & err,
const std::string & file,
size_t line )
inline

Definition at line 126 of file mttest.hpp.

126 {
127 errors.push_back({cond, err.what(), file, line});
128 }
std::vector< test_err > errors
Definition mttest.hpp:123

◆ add_error() [2/3]

void mttest::TestContext::add_error ( const std::string & cond,
const std::string & file,
size_t line )
inline

Definition at line 134 of file mttest.hpp.

134 {
135 errors.push_back({cond, "UNKNOWN", file, line});
136 }

◆ add_error() [3/3]

void mttest::TestContext::add_error ( const std::string & cond,
int err,
const std::string & file,
size_t line )
inline

Definition at line 130 of file mttest.hpp.

130 {
131 errors.push_back({cond, std::to_string(err), file, line});
132 }

◆ add_failure() [1/3]

template<typename L, typename R>
void mttest::TestContext::add_failure ( const std::string & comp,
const std::string & raw,
const L & left,
const R & right,
const std::string & file,
size_t line )
inline

Definition at line 147 of file mttest.hpp.

149 {
150 failures.push_back({"CHECK_EQ(" + raw + ")", file, line,
151 "RECEIVED '" + as_string(left) + "' " + op_name(comp) +
152 " '" + as_string(right) + "'"});
153 }
std::string as_string(const T &val)
Gets a value as a string (for debug printing)
Definition mttest.hpp:74
std::string op_name(const std::string &op)
Gets an operation name's output symbol.
Definition mttest.hpp:96
std::vector< test_fail > failures
Definition mttest.hpp:124
Here is the call graph for this function:

◆ add_failure() [2/3]

void mttest::TestContext::add_failure ( const std::string & cond,
const std::string & file,
size_t line )
inline

Definition at line 138 of file mttest.hpp.

138 {
139 failures.push_back({cond, file, line});
140 }

◆ add_failure() [3/3]

void mttest::TestContext::add_failure ( const std::string & cond,
const std::string & msg,
const std::string & file,
size_t line )
inline

Definition at line 142 of file mttest.hpp.

142 {
143 failures.push_back({cond, file, line, msg});
144 }

Member Data Documentation

◆ errors

std::vector<test_err> mttest::TestContext::errors = {}

Definition at line 123 of file mttest.hpp.

123{};

◆ failures

std::vector<test_fail> mttest::TestContext::failures = {}

Definition at line 124 of file mttest.hpp.

124{};

The documentation for this struct was generated from the following file: