File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 13
13
#include " llvm/Support/Errc.h"
14
14
#include " llvm/Support/ErrorHandling.h"
15
15
#include " llvm/Testing/Support/Error.h"
16
+ #include " gmock/gmock.h"
16
17
#include " gtest/gtest-spi.h"
17
18
#include " gtest/gtest.h"
18
19
#include < memory>
@@ -1158,4 +1159,21 @@ TEST(Error, BadAllocFatalErrorHandlersInteraction) {
1158
1159
remove_bad_alloc_error_handler ();
1159
1160
}
1160
1161
1162
+ TEST (Error, ForwardToExpected) {
1163
+ auto ErrorReturningFct = [](bool Fail) {
1164
+ return Fail ? make_error<StringError>(llvm::errc::invalid_argument,
1165
+ " Some Error" )
1166
+ : Error::success ();
1167
+ };
1168
+ auto ExpectedReturningFct = [&](bool Fail) -> Expected<int > {
1169
+ auto Err = ErrorReturningFct (Fail);
1170
+ if (Err)
1171
+ return Err;
1172
+ return 42 ;
1173
+ };
1174
+ std::optional<int > MaybeV;
1175
+ EXPECT_THAT_ERROR (ExpectedReturningFct (true ).moveInto (MaybeV), Failed ());
1176
+ EXPECT_THAT_ERROR (ExpectedReturningFct (false ).moveInto (MaybeV), Succeeded ());
1177
+ EXPECT_EQ (*MaybeV, 42 );
1178
+ }
1161
1179
} // namespace
You can’t perform that action at this time.
0 commit comments