AnCH unit tests library namespace.
More...
|
| 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) |
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.
◆ 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
-
| check | the condition to check |
| message | the assertion message (default to empty string) |
| location | the assertion location (default to caller location) |
- Exceptions
-
◆ 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
-
- Parameters
-
| check | true if test is OK, false otherwise |
| message | the message which have to be formatted |
| args | the message's arguments |
- Exceptions
-
◆ 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
-
| check | the condition to check |
| message | the assertion message (default to empty string) |
| location | the assertion location (default to caller location) |
- Exceptions
-
◆ 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
-
- Parameters
-
| field | the field name |
| expected | the expected value |
| value | the current value |
| out | the output stream to print in when false (default to std::cout) |
- Returns
true when expect equals to value, false otherwise
◆ 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
-
- Parameters
-
| field | the field name |
| expected | the expected value |
| value | the current value |
| out | the output stream to print in when false (default to std::cout) |
- Returns
true when expect equals to value, false otherwise
◆ 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
-
- Parameters
-
| field | the field name |
| expected | the expected value |
| value | the current value |
| out | the output stream to print in when false (default to std::cout) |
- Returns
true when expect equals to value, false otherwise
◆ 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
-
- Parameters
-
| field | the field name |
| expected | the expected value |
| value | the current value |
| out | the output stream to print in when false (default to std::cout) |
- Returns
true when expect equals to value, false otherwise
◆ 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
-
- Parameters
-
| field | the field name |
| expected | the expected value |
| value | the current value |
| out | the output stream to print in when false (default to std::cout) |
- Returns
true when expect equals to value, false otherwise
◆ 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
-
- Parameters
-
| field | the field name |
| expected | the expected value |
| value | the current value |
| out | the output stream to print in when false (default to std::cout) |
- Returns
true when expect equals to value, false otherwise
◆ 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
-
- Parameters
-
| field | the field name |
| expected | the expected value |
| value | the current value |
| out | the output stream to print in when false (default to std::cout) |
- Returns
true when expect equals to value, false otherwise
◆ fail()
| void anch::ut::fail |
( |
std::string_view | message = "", |
|
|
const std::source_location & | location = std::source_location::current() ) |
Test has been failed ...
- Parameters
-
| message | the assertion message (default to empty string) |
| location | the assertion location (default to caller location) |
- Exceptions
-
◆ setup()
Setup unit tests collection
- Parameters
-
| tests | the collection to fill |