1 #ifndef UTOPIA_CORE_TESTTOOLS_CONFIG_HH
2 #define UTOPIA_CORE_TESTTOOLS_CONFIG_HH
10 #include <boost/test/unit_test.hpp>
11 #include <boost/core/demangle.hpp>
13 #include <yaml-cpp/yaml.h>
108 template<
typename Callable=std::function<
void(const DataIO::Config&)>>
111 const std::string_view context_name =
"",
115 static_assert(std::is_invocable_v<Callable, DataIO::Config&>,
116 "Callable requires DataIO::Config as its only argument!");
119 for (
const auto& kv_pair : test_cases) {
121 const auto case_name = kv_pair.first.template as<std::string>();
122 const auto case_cfg = kv_pair.second;
124 BOOST_TEST_CONTEXT(loc << context_name
125 <<
" -- Testing case '" << case_name
126 <<
"' ... with the following parameters:\n\n"
131 if (case_cfg[
"throws"]) {
133 const auto to_test = [func, case_cfg](){
134 func(case_cfg[
"params"]);
137 const auto exc_type = get_as<std::string>(
"throws", case_cfg);
138 const auto match = get_as<std::string>(
"match", case_cfg,
"");
142 if (exc_type ==
"std::exception") {
143 check_exception<std::exception>(to_test, match, loc);
145 else if (exc_type ==
"std::logic_error") {
146 check_exception<std::logic_error>(to_test, match, loc);
148 else if (exc_type ==
"std::invalid_argument") {
149 check_exception<std::invalid_argument>(to_test, match, loc);
151 else if (exc_type ==
"std::domain_error") {
152 check_exception<std::domain_error>(to_test, match, loc);
154 else if (exc_type ==
"std::length_error") {
155 check_exception<std::length_error>(to_test, match, loc);
157 else if (exc_type ==
"std::out_of_range") {
158 check_exception<std::out_of_range>(to_test, match, loc);
160 else if (exc_type ==
"std::runtime_error") {
161 check_exception<std::runtime_error>(to_test, match, loc);
163 else if (exc_type ==
"std::range_error") {
164 check_exception<std::range_error>(to_test, match, loc);
166 else if (exc_type ==
"std::overflow_error") {
167 check_exception<std::overflow_error>(to_test, match, loc);
169 else if (exc_type ==
"std::underflow_error") {
170 check_exception<std::underflow_error>(to_test, match, loc);
172 else if (exc_type ==
"Utopia::KeyError") {
173 check_exception<Utopia::KeyError>(to_test, match, loc);
175 else if (exc_type ==
"Utopia::Exception") {
176 check_exception<Utopia::Exception>(to_test, match, loc);
178 else if (exc_type ==
"YAML::Exception") {
179 check_exception<YAML::Exception>(to_test, match, loc);
183 "Invalid exception type '" << exc_type <<
"' given in "
184 "`throws` argument! Supported exception types are: "
185 "std::exception, std::logic_error, std::invalid_argument, "
186 "std::domain_error, std::length_error, std::out_of_range, "
187 "std::runtime_error, std::range_error, "
188 "std::overflow_error, std::underflow_error, "
189 "Utopia::KeyError, Utopia::Exception, "
190 "and YAML::Exception."
200 func(case_cfg[
"params"]);
202 catch (std::exception& e) {
203 BOOST_ERROR(loc <<
"Unexpectedly threw an error ("
204 << boost::core::demangle(
typeid(e).name())
205 <<
") with message: " << e.what());
208 BOOST_ERROR(loc <<
"Unexpectedly threw a non-std error!");
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71