[llvm] Unittest for Error forwarding, follow-up to PR #92208 (PR #92314)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 13:44:32 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Mircea Trofin (mtrofin)
<details>
<summary>Changes</summary>
Added a unittest demonstrating Error -> Expected<T> forwarding.
---
Full diff: https://github.com/llvm/llvm-project/pull/92314.diff
1 Files Affected:
- (modified) llvm/unittests/Support/ErrorTest.cpp (+16)
``````````diff
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 1229282cf0def..5c0179f256d6e 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -1158,4 +1158,20 @@ TEST(Error, BadAllocFatalErrorHandlersInteraction) {
remove_bad_alloc_error_handler();
}
+TEST(Error, ForwardToExpected) {
+ auto ErrorReturningFct = [](bool Fail) {
+ return Fail ? make_error<StringError>(llvm::errc::invalid_argument,
+ "Some Error")
+ : Error::success();
+ };
+ auto ExpectedReturningFct = [&](bool Fail) -> Expected<int> {
+ auto Err = ErrorReturningFct(Fail);
+ if (Err)
+ return Err;
+ return 42;
+ };
+ std::optional<int> MaybeV;
+ EXPECT_THAT_ERROR(ExpectedReturningFct(true).moveInto(MaybeV), Failed());
+ EXPECT_EQ(*ExpectedReturningFct(false), 42);
+}
} // namespace
``````````
</details>
https://github.com/llvm/llvm-project/pull/92314
More information about the llvm-commits
mailing list