MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / assert_throws

Function assert_throws

subprojects/llama.cpp/tests/test-chat-parser.cpp:36–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36static void assert_throws(const std::function<void()> & fn, const std::string & expected_exception_pattern = "") {
37 try {
38 fn();
39 } catch (const std::exception & e) {
40 if (expected_exception_pattern.empty()) {
41 return;
42 }
43 std::regex expected_exception_regex(expected_exception_pattern);
44 std::string actual_message = e.what();
45 if (std::regex_search(actual_message, expected_exception_regex)) {
46 return;
47 }
48 throw std::runtime_error("Exception doesn't match expected pattern: " + actual_message + " (pattern: " + expected_exception_pattern + ")");
49 throw std::runtime_error("Exception of unexpected type: " + std::string(e.what()));
50 }
51 throw std::runtime_error("Exception was expected but not thrown");
52}
53
54static void test_reasoning() {
55 //common_log_set_verbosity_thold(LOG_DEFAULT_DEBUG);

Callers 2

test_regexFunction · 0.85
test_positionsFunction · 0.85

Calls 3

stringClass · 0.85
emptyMethod · 0.65
whatMethod · 0.45

Tested by

no test coverage detected