| 28 | } |
| 29 | |
| 30 | static void assert_throws(const std::function<void()> & fn, const std::string & expected_exception_pattern = "") { |
| 31 | try { |
| 32 | fn(); |
| 33 | } catch (const std::exception & e) { |
| 34 | if (expected_exception_pattern.empty()) { |
| 35 | return; |
| 36 | } |
| 37 | std::regex expected_exception_regex(expected_exception_pattern); |
| 38 | std::string actual_message = e.what(); |
| 39 | if (std::regex_search(actual_message, expected_exception_regex)) { |
| 40 | return; |
| 41 | } |
| 42 | throw std::runtime_error("Exception doesn't match expected pattern: " + actual_message + " (pattern: " + expected_exception_pattern + ")"); |
| 43 | throw std::runtime_error("Exception of unexpected type: " + std::string(e.what())); |
| 44 | } |
| 45 | throw std::runtime_error("Exception was expected but not thrown"); |
| 46 | } |
| 47 | |
| 48 | static void test_reasoning() { |
| 49 | { |
no test coverage detected