MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / ExpectThrowContains

Function ExpectThrowContains

test/cpp/utils/exception_test_utils.h:25–51  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24template <typename ExceptionType = std::exception, typename Fn>
25inline void ExpectThrowContains(Fn&& fn,
26 const std::string& expected_substr,
27 const std::string& context = "") {
28 try {
29 fn();
30 if (context.empty()) {
31 FAIL() << "Expected exception containing: " << expected_substr;
32 } else {
33 FAIL() << "Expected exception containing: " << expected_substr
34 << ", context: " << context;
35 }
36 } catch (const ExceptionType& e) {
37 if (context.empty()) {
38 EXPECT_NE(std::string(e.what()).find(expected_substr), std::string::npos)
39 << "actual error: " << e.what();
40 } else {
41 EXPECT_NE(std::string(e.what()).find(expected_substr), std::string::npos)
42 << "context: " << context << ", actual error: " << e.what();
43 }
44 } catch (...) {
45 if (context.empty()) {
46 FAIL() << "Expected the specified exception type";
47 } else {
48 FAIL() << "Expected the specified exception type, context: " << context;
49 }
50 }
51}
52
53} // namespace utils
54} // namespace test

Callers

nothing calls this directly

Calls 4

fnFunction · 0.50
emptyMethod · 0.45
findMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected