diff options
| author | 2017-10-04 20:27:34 +0000 | |
|---|---|---|
| committer | 2017-10-04 20:27:34 +0000 | |
| commit | 31eb748944903b7f4f38afda9851951ca9dfc1ae (patch) | |
| tree | 9b95b6ea45d0874d75eb05b90c0840e191416439 /gnu/llvm/unittests/Support/ErrorTest.cpp | |
| parent | Don't try to handle IPv4-compatible IPv6 addresses (diff) | |
| download | wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.tar.xz wireguard-openbsd-31eb748944903b7f4f38afda9851951ca9dfc1ae.zip | |
Import LLVM 5.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/unittests/Support/ErrorTest.cpp')
| -rw-r--r-- | gnu/llvm/unittests/Support/ErrorTest.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/gnu/llvm/unittests/Support/ErrorTest.cpp b/gnu/llvm/unittests/Support/ErrorTest.cpp index 29a173a058b..a762cf023f9 100644 --- a/gnu/llvm/unittests/Support/ErrorTest.cpp +++ b/gnu/llvm/unittests/Support/ErrorTest.cpp @@ -360,7 +360,7 @@ TEST(Error, CheckJoinErrors) { [&](const CustomError &CE) { Sum += CE.getInfo(); }); - EXPECT_EQ(Sum, 28) << "Failed to correctly concatenate erorr lists."; + EXPECT_EQ(Sum, 28) << "Failed to correctly concatenate error lists."; } } @@ -469,6 +469,38 @@ TEST(Error, ExitOnError) { << "exitOnError returned an unexpected error result"; } +// Test that the ExitOnError utility works as expected. +TEST(Error, CantFailSuccess) { + cantFail(Error::success()); + + int X = cantFail(Expected<int>(42)); + EXPECT_EQ(X, 42) << "Expected value modified by cantFail"; + + int Dummy = 42; + int &Y = cantFail(Expected<int&>(Dummy)); + EXPECT_EQ(&Dummy, &Y) << "Reference mangled by cantFail"; +} + +// Test that cantFail results in a crash if you pass it a failure value. +#if LLVM_ENABLE_ABI_BREAKING_CHECKS +TEST(Error, CantFailDeath) { + EXPECT_DEATH( + cantFail(make_error<StringError>("foo", inconvertibleErrorCode())), + "Failure value returned from cantFail wrapped call") + << "cantFail(Error) did not cause an abort for failure value"; + + EXPECT_DEATH( + { + auto IEC = inconvertibleErrorCode(); + int X = cantFail(Expected<int>(make_error<StringError>("foo", IEC))); + (void)X; + }, + "Failure value returned from cantFail wrapped call") + << "cantFail(Expected<int>) did not cause an abort for failure value"; +} +#endif + + // Test Checked Expected<T> in success mode. TEST(Error, CheckedExpectedInSuccessMode) { Expected<int> A = 7; |
