MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / assert_throws

Function assert_throws

smallthinker/tests/test-chat-parser.cpp:30–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30static 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
48static void test_reasoning() {
49 {

Callers 2

test_regexFunction · 0.85
test_positionsFunction · 0.85

Calls 4

fnFunction · 0.50
stringClass · 0.50
emptyMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected