diff options
Diffstat (limited to 'gnu/llvm/unittests/Support/ErrorTest.cpp')
| -rw-r--r-- | gnu/llvm/unittests/Support/ErrorTest.cpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/gnu/llvm/unittests/Support/ErrorTest.cpp b/gnu/llvm/unittests/Support/ErrorTest.cpp index 20509268374..29a173a058b 100644 --- a/gnu/llvm/unittests/Support/ErrorTest.cpp +++ b/gnu/llvm/unittests/Support/ErrorTest.cpp @@ -82,12 +82,14 @@ protected: char CustomSubError::ID = 0; -static Error handleCustomError(const CustomError &CE) { return Error(); } +static Error handleCustomError(const CustomError &CE) { + return Error::success(); +} static void handleCustomErrorVoid(const CustomError &CE) {} static Error handleCustomErrorUP(std::unique_ptr<CustomError> CE) { - return Error(); + return Error::success(); } static void handleCustomErrorUPVoid(std::unique_ptr<CustomError> CE) {} @@ -95,21 +97,22 @@ static void handleCustomErrorUPVoid(std::unique_ptr<CustomError> CE) {} // Test that success values implicitly convert to false, and don't cause crashes // once they've been implicitly converted. TEST(Error, CheckedSuccess) { - Error E; + Error E = Error::success(); EXPECT_FALSE(E) << "Unexpected error while testing Error 'Success'"; } // Test that unchecked succes values cause an abort. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, UncheckedSuccess) { - EXPECT_DEATH({ Error E; }, "Program aborted due to an unhandled Error:") + EXPECT_DEATH({ Error E = Error::success(); }, + "Program aborted due to an unhandled Error:") << "Unchecked Error Succes value did not cause abort()"; } #endif // ErrorAsOutParameter tester. void errAsOutParamHelper(Error &Err) { - ErrorAsOutParameter ErrAsOutParam(Err); + ErrorAsOutParameter ErrAsOutParam(&Err); // Verify that checked flag is raised - assignment should not crash. Err = Error::success(); // Raise the checked bit manually - caller should still have to test the @@ -119,15 +122,15 @@ void errAsOutParamHelper(Error &Err) { // Test that ErrorAsOutParameter sets the checked flag on construction. TEST(Error, ErrorAsOutParameterChecked) { - Error E; + Error E = Error::success(); errAsOutParamHelper(E); (void)!!E; } // Test that ErrorAsOutParameter clears the checked flag on destruction. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, ErrorAsOutParameterUnchecked) { - EXPECT_DEATH({ Error E; errAsOutParamHelper(E); }, + EXPECT_DEATH({ Error E = Error::success(); errAsOutParamHelper(E); }, "Program aborted due to an unhandled Error:") << "ErrorAsOutParameter did not clear the checked flag on destruction."; } @@ -136,7 +139,7 @@ TEST(Error, ErrorAsOutParameterUnchecked) { // Check that we abort on unhandled failure cases. (Force conversion to bool // to make sure that we don't accidentally treat checked errors as handled). // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, UncheckedError) { auto DropUnhandledError = []() { Error E = make_error<CustomError>(42); @@ -195,31 +198,31 @@ TEST(Error, HandlerTypeDeduction) { handleAllErrors( make_error<CustomError>(42), - [](const CustomError &CE) mutable { return Error::success(); }); + [](const CustomError &CE) mutable -> Error { return Error::success(); }); handleAllErrors(make_error<CustomError>(42), [](const CustomError &CE) mutable {}); handleAllErrors(make_error<CustomError>(42), - [](CustomError &CE) { return Error::success(); }); + [](CustomError &CE) -> Error { return Error::success(); }); handleAllErrors(make_error<CustomError>(42), [](CustomError &CE) {}); handleAllErrors(make_error<CustomError>(42), - [](CustomError &CE) mutable { return Error::success(); }); + [](CustomError &CE) mutable -> Error { return Error::success(); }); handleAllErrors(make_error<CustomError>(42), [](CustomError &CE) mutable {}); handleAllErrors( make_error<CustomError>(42), - [](std::unique_ptr<CustomError> CE) { return Error::success(); }); + [](std::unique_ptr<CustomError> CE) -> Error { return Error::success(); }); handleAllErrors(make_error<CustomError>(42), [](std::unique_ptr<CustomError> CE) {}); handleAllErrors( make_error<CustomError>(42), - [](std::unique_ptr<CustomError> CE) mutable { return Error::success(); }); + [](std::unique_ptr<CustomError> CE) mutable -> Error { return Error::success(); }); handleAllErrors(make_error<CustomError>(42), [](std::unique_ptr<CustomError> CE) mutable {}); @@ -363,7 +366,7 @@ TEST(Error, CheckJoinErrors) { // Test that we can consume success values. TEST(Error, ConsumeSuccess) { - Error E; + Error E = Error::success(); consumeError(std::move(E)); } @@ -374,7 +377,7 @@ TEST(Error, ConsumeError) { // Test that handleAllUnhandledErrors crashes if an error is not caught. // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, FailureToHandle) { auto FailToHandle = []() { handleAllErrors(make_error<CustomError>(7), [&](const CustomSubError &SE) { @@ -392,7 +395,7 @@ TEST(Error, FailureToHandle) { // Test that handleAllUnhandledErrors crashes if an error is returned from a // handler. // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, FailureFromHandler) { auto ReturnErrorFromHandler = []() { handleAllErrors(make_error<CustomError>(7), @@ -487,7 +490,7 @@ TEST(Error, ExpectedWithReferenceType) { // Test Unchecked Expected<T> in success mode. // We expect this to blow up the same way Error would. // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, UncheckedExpectedInSuccessModeDestruction) { EXPECT_DEATH({ Expected<int> A = 7; }, "Expected<T> must be checked before access or destruction.") @@ -498,7 +501,7 @@ TEST(Error, UncheckedExpectedInSuccessModeDestruction) { // Test Unchecked Expected<T> in success mode. // We expect this to blow up the same way Error would. // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, UncheckedExpectedInSuccessModeAccess) { EXPECT_DEATH({ Expected<int> A = 7; *A; }, "Expected<T> must be checked before access or destruction.") @@ -509,7 +512,7 @@ TEST(Error, UncheckedExpectedInSuccessModeAccess) { // Test Unchecked Expected<T> in success mode. // We expect this to blow up the same way Error would. // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, UncheckedExpectedInSuccessModeAssignment) { EXPECT_DEATH({ Expected<int> A = 7; A = 7; }, "Expected<T> must be checked before access or destruction.") @@ -529,7 +532,7 @@ TEST(Error, ExpectedInFailureMode) { // Check that an Expected instance with an error value doesn't allow access to // operator*. // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, AccessExpectedInFailureMode) { Expected<int> A = make_error<CustomError>(42); EXPECT_DEATH(*A, "Expected<T> must be checked before access or destruction.") @@ -541,7 +544,7 @@ TEST(Error, AccessExpectedInFailureMode) { // Check that an Expected instance with an error triggers an abort if // unhandled. // Test runs in debug mode only. -#ifndef NDEBUG +#if LLVM_ENABLE_ABI_BREAKING_CHECKS TEST(Error, UnhandledExpectedInFailureMode) { EXPECT_DEATH({ Expected<int> A = make_error<CustomError>(42); }, "Expected<T> must be checked before access or destruction.") |
