mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Switch executable semantics to use ErrorBuilder directly and relocate macros (#1184)
This commit is contained in:
@@ -49,5 +49,53 @@ TEST(ErrorTest, IndirectErrorOrSuccess) {
|
||||
EXPECT_TRUE(IndirectErrorOrSuccessTest().ok());
|
||||
}
|
||||
|
||||
TEST(ErrorTest, ReturnIfErrorNoError) {
|
||||
auto result = []() -> ErrorOr<Success> {
|
||||
RETURN_IF_ERROR(ErrorOr<Success>(Success()));
|
||||
RETURN_IF_ERROR(ErrorOr<Success>(Success()));
|
||||
return Success();
|
||||
}();
|
||||
EXPECT_TRUE(result.ok());
|
||||
}
|
||||
|
||||
TEST(ErrorTest, ReturnIfErrorHasError) {
|
||||
auto result = []() -> ErrorOr<Success> {
|
||||
RETURN_IF_ERROR(ErrorOr<Success>(Success()));
|
||||
RETURN_IF_ERROR(ErrorOr<Success>(Error("error")));
|
||||
return Success();
|
||||
}();
|
||||
ASSERT_FALSE(result.ok());
|
||||
EXPECT_EQ(result.error().message(), "error");
|
||||
}
|
||||
|
||||
TEST(ErrorTest, AssignOrReturnNoError) {
|
||||
auto result = []() -> ErrorOr<int> {
|
||||
ASSIGN_OR_RETURN(int a, ErrorOr<int>(1));
|
||||
ASSIGN_OR_RETURN(const int b, ErrorOr<int>(2));
|
||||
int c = 0;
|
||||
ASSIGN_OR_RETURN(c, ErrorOr<int>(3));
|
||||
return a + b + c;
|
||||
}();
|
||||
ASSERT_TRUE(result.ok());
|
||||
EXPECT_EQ(6, *result);
|
||||
}
|
||||
|
||||
TEST(ErrorTest, AssignOrReturnHasDirectError) {
|
||||
auto result = []() -> ErrorOr<int> {
|
||||
RETURN_IF_ERROR(ErrorOr<int>(Error("error")));
|
||||
return 0;
|
||||
}();
|
||||
ASSERT_FALSE(result.ok());
|
||||
}
|
||||
|
||||
TEST(ErrorTest, AssignOrReturnHasErrorInExpected) {
|
||||
auto result = []() -> ErrorOr<int> {
|
||||
ASSIGN_OR_RETURN(int a, ErrorOr<int>(Error("error")));
|
||||
return a;
|
||||
}();
|
||||
ASSERT_FALSE(result.ok());
|
||||
EXPECT_EQ(result.error().message(), "error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace Carbon::Testing
|
||||
|
||||
Reference in New Issue
Block a user