aboutsummaryrefslogtreecommitdiff
path: root/unittests/Utility/StatusTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Utility/StatusTest.cpp')
-rw-r--r--unittests/Utility/StatusTest.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/unittests/Utility/StatusTest.cpp b/unittests/Utility/StatusTest.cpp
index 9655610e4aa3..03e2368c7b1b 100644
--- a/unittests/Utility/StatusTest.cpp
+++ b/unittests/Utility/StatusTest.cpp
@@ -11,9 +11,40 @@
#include "gtest/gtest.h"
using namespace lldb_private;
+using namespace lldb;
TEST(StatusTest, Formatv) {
EXPECT_EQ("", llvm::formatv("{0}", Status()).str());
EXPECT_EQ("Hello Status", llvm::formatv("{0}", Status("Hello Status")).str());
EXPECT_EQ("Hello", llvm::formatv("{0:5}", Status("Hello Error")).str());
}
+
+TEST(StatusTest, ErrorConstructor) {
+ EXPECT_TRUE(Status(llvm::Error::success()).Success());
+
+ Status eagain(
+ llvm::errorCodeToError(std::error_code(EAGAIN, std::generic_category())));
+ EXPECT_TRUE(eagain.Fail());
+ EXPECT_EQ(eErrorTypePOSIX, eagain.GetType());
+ EXPECT_EQ(Status::ValueType(EAGAIN), eagain.GetError());
+
+ Status foo(llvm::make_error<llvm::StringError>(
+ "foo", llvm::inconvertibleErrorCode()));
+ EXPECT_TRUE(foo.Fail());
+ EXPECT_EQ(eErrorTypeGeneric, foo.GetType());
+ EXPECT_STREQ("foo", foo.AsCString());
+}
+
+TEST(StatusTest, ErrorConversion) {
+ EXPECT_FALSE(bool(Status().ToError()));
+
+ llvm::Error eagain = Status(EAGAIN, ErrorType::eErrorTypePOSIX).ToError();
+ EXPECT_TRUE(bool(eagain));
+ std::error_code ec = llvm::errorToErrorCode(std::move(eagain));
+ EXPECT_EQ(EAGAIN, ec.value());
+ EXPECT_EQ(std::generic_category(), ec.category());
+
+ llvm::Error foo = Status("foo").ToError();
+ EXPECT_TRUE(bool(foo));
+ EXPECT_EQ("foo", llvm::toString(std::move(foo)));
+}