MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / TEST

Function TEST

oneflow/core/common/maybe_test.cpp:26–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24namespace test {
25
26TEST(Maybe, JUST_MSG) {
27 auto f = [](int x) -> Maybe<int> {
28 if (x > 10) { return Error::InvalidValueError() << "input value " << x; }
29
30 return 233;
31 };
32
33 auto g = [](int x) { return x * x - 5 * x + 3; };
34
35 auto h = [&](int x) -> Maybe<int> {
36 auto y = g(x);
37 return JUST_MSG(f(y), "input value g(", x, ")");
38 };
39
40 auto i = [&](float x) -> Maybe<int> {
41 int y = x;
42 return JUST_MSG(h(y), std::stringstream() << "input value int(" << x << ")");
43 };
44
45 auto data = CHECK_JUST(i(1));
46 ASSERT_EQ(data, 233);
47
48 auto err = i(10.123).stacked_error();
49 ASSERT_EQ(err->error_proto()->msg(), R"(input value 53)");
50 ASSERT_GE(err->stack_frame().size(), 2);
51 ASSERT_EQ(err->stack_frame().at(0)->code_text(), "f(y)");
52 ASSERT_EQ(err->stack_frame().at(1)->code_text(), "h(y)");
53
54 try {
55 CHECK_JUST(i(10.234));
56 } catch (const RuntimeException& e) {
57 EXPECT_TRUE(std::string(e.what()).find(R"(input value 53)") != std::string::npos);
58 }
59}
60
61TEST(Maybe, CHECK_OR_RETURN) {
62 auto f = [](int x) -> Maybe<int> {

Callers 1

channel_test.cppFile · 0.70

Calls 7

gFunction · 0.85
findMethod · 0.80
whatMethod · 0.80
fFunction · 0.50
stacked_errorMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected