AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::ut Namespace Reference

AnCH unit tests library namespace. More...

Classes

class  AssertException
 Unit test assertion error. More...
struct  AssertMessage
 Assertion message with its location. More...
class  DefaultRunner
 Default unit tests runner. More...
class  Runner
 Unit tests runner. More...
class  ThreadErrors
 Exceptions raised in threads started by a unit test. More...
class  UnitTests
 Unit tests collection. More...

Functions

void fail (std::string_view message="", const std::source_location &location=std::source_location::current())
void assertTrue (bool check, std::string_view message="", const std::source_location &location=std::source_location::current())
void assertFalse (bool check, std::string_view message="", const std::source_location &location=std::source_location::current())
template<typename... T>
void assertThat (bool check, std::type_identity_t< anch::ut::AssertMessage< T... > > message, const T &... args)
template<typename T>
bool equals (const char *const field, const std::set< T > &expected, const std::set< T > &value, std::ostream &out=std::cout)
template<typename T>
bool equals (const char *const field, const std::list< T > &expected, const std::list< T > &value, std::ostream &out=std::cout)
template<typename T>
bool equals (const char *const field, const std::vector< T > &expected, const std::vector< T > &value, std::ostream &out=std::cout)
template<typename T>
bool equals (const char *const field, const std::optional< T > &expected, const std::optional< T > &value, std::ostream &out=std::cout)
template<typename T>
bool equals (const char *const field, const std::shared_ptr< T > &expected, const std::shared_ptr< T > &value, std::ostream &out=std::cout)
template<typename T>
bool equalsPtr (const char *const field, const T *const expected, const T *const value, std::ostream &out=std::cout)
template<typename T>
bool equals (const char *const field, const T &expected, const T &value, std::ostream &out=std::cout)
void setup (UnitTests &tests)

Detailed Description

AnCH unit tests library namespace.

A test executable implements anch::ut::setup to register its tests; assertions are anch::ut::assertThat and anch::ut::assertTrue . See AnCH unit tests library documentation.

Function Documentation

◆ assertFalse()

void anch::ut::assertFalse ( bool check,
std::string_view message = "",
const std::source_location & location = std::source_location::current() )

Check if condition is false and raise unit test error otherwise

Parameters
checkthe condition to check
messagethe assertion message (default to empty string)
locationthe assertion location (default to caller location)
Exceptions
anch::ut::AssertExceptioncheck is true
Here is the call graph for this function:

◆ assertThat()

template<typename... T>
void anch::ut::assertThat ( bool check,
std::type_identity_t< anch::ut::AssertMessage< T... > > message,
const T &... args )

Assert clause with error message formatting (std::format syntax with {} placeholders).
The message is checked at compile time (it has to be a string literal whose placeholders match the arguments) and is formatted only when the assertion fails. The assertion location is reported with the message.

Template Parameters
Tthe arguments
Parameters
checktrue if test is OK, false otherwise
messagethe message which have to be formatted
argsthe message's arguments
Exceptions
anch::ut::AssertExceptioncheck is false
Here is the call graph for this function:

◆ assertTrue()

void anch::ut::assertTrue ( bool check,
std::string_view message = "",
const std::source_location & location = std::source_location::current() )

Check if condition is true and raise unit test error otherwise

Parameters
checkthe condition to check
messagethe assertion message (default to empty string)
locationthe assertion location (default to caller location)
Exceptions
anch::ut::AssertExceptioncheck is false
Here is the call graph for this function:

◆ equals() [1/6]

template<typename T>
bool anch::ut::equals ( const char *const field,
const std::list< T > & expected,
const std::list< T > & value,
std::ostream & out = std::cout )

Check if optional value is equals to expected pointer value ; print the field and expected versus current value when false ; return the result

Template Parameters
Tthe value type
Parameters
fieldthe field name
expectedthe expected value
valuethe current value
outthe output stream to print in when false (default to std::cout)
Returns
true when expect equals to value, false otherwise
Here is the call graph for this function:

◆ equals() [2/6]

template<typename T>
bool anch::ut::equals ( const char *const field,
const std::optional< T > & expected,
const std::optional< T > & value,
std::ostream & out = std::cout )

Check if optional value is equals to expected pointer value ; print the field and expected versus current value when false ; return the result

Template Parameters
Tthe value type
Parameters
fieldthe field name
expectedthe expected value
valuethe current value
outthe output stream to print in when false (default to std::cout)
Returns
true when expect equals to value, false otherwise
Here is the call graph for this function:

◆ equals() [3/6]

template<typename T>
bool anch::ut::equals ( const char *const field,
const std::set< T > & expected,
const std::set< T > & value,
std::ostream & out = std::cout )

Check if optional value is equals to expected pointer value ; print the field and expected versus current value when false ; return the result

Template Parameters
Tthe value type
Parameters
fieldthe field name
expectedthe expected value
valuethe current value
outthe output stream to print in when false (default to std::cout)
Returns
true when expect equals to value, false otherwise
Here is the call graph for this function:

◆ equals() [4/6]

template<typename T>
bool anch::ut::equals ( const char *const field,
const std::shared_ptr< T > & expected,
const std::shared_ptr< T > & value,
std::ostream & out = std::cout )

Check if shared pointer value is equals to expected shared pointer value ; print the field and expected versus current value when false ; return the result

Template Parameters
Tthe value type
Parameters
fieldthe field name
expectedthe expected value
valuethe current value
outthe output stream to print in when false (default to std::cout)
Returns
true when expect equals to value, false otherwise
Here is the call graph for this function:

◆ equals() [5/6]

template<typename T>
bool anch::ut::equals ( const char *const field,
const std::vector< T > & expected,
const std::vector< T > & value,
std::ostream & out = std::cout )

Check if optional value is equals to expected pointer value ; print the field and expected versus current value when false ; return the result

Template Parameters
Tthe value type
Parameters
fieldthe field name
expectedthe expected value
valuethe current value
outthe output stream to print in when false (default to std::cout)
Returns
true when expect equals to value, false otherwise
Here is the call graph for this function:

◆ equals() [6/6]

template<typename T>
bool anch::ut::equals ( const char *const field,
const T & expected,
const T & value,
std::ostream & out = std::cout )

Check if value is equals to expected value ; print the field and expected versus current value when false ; return the result

Template Parameters
Tthe value type
Parameters
fieldthe field name
expectedthe expected value
valuethe current value
outthe output stream to print in when false (default to std::cout)
Returns
true when expect equals to value, false otherwise
Here is the call graph for this function:

◆ equalsPtr()

template<typename T>
bool anch::ut::equalsPtr ( const char *const field,
const T *const expected,
const T *const value,
std::ostream & out = std::cout )

Check if pointer value is equals to expected pointer value ; print the field and expected versus current value when false ; return the result.
Pointed values are compared when both pointers are not NULL .

Template Parameters
Tthe value type
Parameters
fieldthe field name
expectedthe expected value
valuethe current value
outthe output stream to print in when false (default to std::cout)
Returns
true when expect equals to value, false otherwise
Here is the call graph for this function:

◆ fail()

void anch::ut::fail ( std::string_view message = "",
const std::source_location & location = std::source_location::current() )

Test has been failed ...

Parameters
messagethe assertion message (default to empty string)
locationthe assertion location (default to caller location)
Exceptions
anch::ut::AssertExceptionalways
Here is the call graph for this function:

◆ setup()

void anch::ut::setup ( UnitTests & tests)

Setup unit tests collection

Parameters
teststhe collection to fill
Here is the call graph for this function: