Utopia
2
Framework for studying models of complex & adaptive systems.
|
Gathers useful tools for writing tests in the Boost.Test framework. More...
Functions | |
template<typename Callable = std::function<void(const DataIO::Config&)>> | |
void | Utopia::TestTools::test_config_callable (Callable &&func, const DataIO::Config &test_cases, const std::string_view context_name="", const LocationInfo loc={}) |
Repeatedly invokes a unary function that expects a Config node. More... | |
template<typename ExcT , typename Callable = std::function<void()>> | |
void | Utopia::TestTools::check_exception (Callable &&func, const std::string_view match="", const LocationInfo loc={}) |
Checks if a callable throws with the expected error type and message. More... | |
Gathers useful tools for writing tests in the Boost.Test framework.
Have a look at the Utopia::TestTools namespace for more specific information.
void Utopia::TestTools::check_exception | ( | Callable && | func, |
const std::string_view | match = "" , |
||
const LocationInfo | loc = {} |
||
) |
Checks if a callable throws with the expected error type and message.
An unexpected error type, error message, or lack of throwing an error is reported via BOOST_ERROR.
ExcT | The expected exception type |
func | The callable that is expected to throw the exception. It must take no arguments. |
match | If given, it will be checked whether the error message contains this string. This can not be a regex or glob pattern. Uses contains to perform the check. |
loc | Location information. If provided, the BOOST_ERROR will include line and file information. |
void Utopia::TestTools::test_config_callable | ( | Callable && | func, |
const DataIO::Config & | test_cases, | ||
const std::string_view | context_name = "" , |
||
const LocationInfo | loc = {} |
||
) |
Repeatedly invokes a unary function that expects a Config node.
The parameters with which the function is invoked are specified in a YAML mapping, test_cases
. Each case also allows to specify whether the callable will throw an exception; this makes use of the Utopia::TestTools::check_exception method and supports most of the basic exception types.
Each of the test cases has the following form:
Example YAML configuration for multiple test cases:
For the test_cases
maping exemplified above, this can be invoked via:
func | The callable to repeatedly invoke. This must be a unary function that accepts a Config node. |
test_cases | A YAML::Node mapping that contains as keys the test cases and as value another mapping. The params key within each test case is passed to the callable. The throws and match keys are optional and control the exception handling. |
context_name | A name that is added to the BOOST_TEST_CONTEXT which is created for each test case. The context helps to debug failing test cases, as it provides all parameters that were passed to the callable. |
loc | Optional location information that can help tracing back where this is invoked from. |