diff options
author | Lang Hames <lhames@gmail.com> | 2016-03-25 23:54:32 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-03-25 23:54:32 +0000 |
commit | d1af8fce0fa1d05d635eeb892b82f2cca1cee1cd (patch) | |
tree | 083faace094981e0a867770913a0cf38702fb70f /llvm/unittests/Support/ErrorTest.cpp | |
parent | ed963704f5371835efde99bea9333de05e73deac (diff) | |
download | bcm5719-llvm-d1af8fce0fa1d05d635eeb892b82f2cca1cee1cd.tar.gz bcm5719-llvm-d1af8fce0fa1d05d635eeb892b82f2cca1cee1cd.zip |
[Support] Switch to RAII helper for error-as-out-parameter idiom.
As discussed on the llvm-commits thread for r264467.
llvm-svn: 264479
Diffstat (limited to 'llvm/unittests/Support/ErrorTest.cpp')
-rw-r--r-- | llvm/unittests/Support/ErrorTest.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp index 1a0dd441c1a..7d714777c65 100644 --- a/llvm/unittests/Support/ErrorTest.cpp +++ b/llvm/unittests/Support/ErrorTest.cpp @@ -105,12 +105,32 @@ TEST(Error, UncheckedSuccess) { } #endif -// Test that errors to be used as out parameters are implicitly checked ( -// and thus destruct quietly). -TEST(Error, ErrorAsOutParameter) { - Error E = Error::errorForOutParameter(); +// ErrorAsOutParameter tester. +void errAsOutParamHelper(Error &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 + // error. + (void)!!Err; } +// Test that ErrorAsOutParameter sets the checked flag on construction. +TEST(Error, ErrorAsOutParameterChecked) { + Error E; + errAsOutParamHelper(E); + (void)!!E; +} + +// Test that ErrorAsOutParameter clears the checked flag on destruction. +#ifndef NDEBUG +TEST(Error, ErrorAsOutParameterUnchecked) { + EXPECT_DEATH({ Error E; errAsOutParamHelper(E); }, + "Program aborted due to an unhandled Error:") + << "ErrorAsOutParameter did not clear the checked flag on destruction."; +} +#endif + // 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. |