diff options
author | Lang Hames <lhames@gmail.com> | 2016-05-27 01:37:32 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-05-27 01:37:32 +0000 |
commit | 5083fc557389a0cdeb5922c5c6dde01e536bdd61 (patch) | |
tree | 1cd9b2798d42781cd1ebbd901409458c35c86a05 /unittests | |
parent | 3e20a7ae1745c8c5c963b966d927a0acbc5849d3 (diff) |
[Support] Add a StringError convenience class to Error.h
StringError can be used to represent Errors that aren't recoverable based on
the error type, but that have a useful error message that can be reported to
the user or logged.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/ErrorTest.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/unittests/Support/ErrorTest.cpp b/unittests/Support/ErrorTest.cpp index c2a1673f42d..919bce53860 100644 --- a/unittests/Support/ErrorTest.cpp +++ b/unittests/Support/ErrorTest.cpp @@ -8,6 +8,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Support/Error.h" + +#include "llvm/ADT/Twine.h" #include "llvm/Support/Errc.h" #include "llvm/Support/ErrorHandling.h" #include "gtest/gtest.h" @@ -376,6 +378,20 @@ TEST(Error, CatchErrorFromHandler) { << "Failed to handle Error returned from handleErrors."; } +TEST(Error, StringError) { + std::string Msg; + raw_string_ostream S(Msg); + logAllUnhandledErrors(make_error<StringError>("foo" + Twine(42), + unconvertibleErrorCode()), + S, ""); + EXPECT_EQ(S.str(), "foo42\n") << "Unexpected StringError log result"; + + auto EC = + errorToErrorCode(make_error<StringError>("", errc::invalid_argument)); + EXPECT_EQ(EC, errc::invalid_argument) + << "Failed to convert StringError to error_code."; +} + // Test that the ExitOnError utility works as expected. TEST(Error, ExitOnError) { ExitOnError ExitOnErr; |