summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2016-05-27 01:37:32 +0000
committerLang Hames <lhames@gmail.com>2016-05-27 01:37:32 +0000
commitc5e0bbd781d45bf8ebd22ed90b6b64130affeb51 (patch)
treed928363532216da7bddec10bb81af4ccb4f87adc /llvm/unittests/Support
parent76dacb4ba9e50c8583e5aaf37badc0de7a3da60c (diff)
downloadbcm5719-llvm-c5e0bbd781d45bf8ebd22ed90b6b64130affeb51.tar.gz
bcm5719-llvm-c5e0bbd781d45bf8ebd22ed90b6b64130affeb51.zip
[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. llvm-svn: 270948
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index c2a1673f42d..919bce53860 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/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;
OpenPOWER on IntegriCloud