summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r--llvm/unittests/Support/ErrorTest.cpp39
-rw-r--r--llvm/unittests/Support/FormatVariadicTest.cpp9
2 files changed, 38 insertions, 10 deletions
diff --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 529439ffd95..2f9ce2d5646 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -32,7 +32,7 @@ public:
// Log this error to a stream.
void log(raw_ostream &OS) const override {
- OS << "CustomError { " << getInfo() << "}";
+ OS << "CustomError {" << getInfo() << "}";
}
std::error_code convertToErrorCode() const override {
@@ -702,25 +702,44 @@ TEST(Error, ErrorMessage) {
EXPECT_EQ(toString(Error::success()).compare(""), 0);
Error E1 = make_error<CustomError>(0);
- EXPECT_EQ(toString(std::move(E1)).compare("CustomError { 0}"), 0);
+ EXPECT_EQ(toString(std::move(E1)).compare("CustomError {0}"), 0);
Error E2 = make_error<CustomError>(0);
handleAllErrors(std::move(E2), [](const CustomError &CE) {
- EXPECT_EQ(CE.message().compare("CustomError { 0}"), 0);
+ EXPECT_EQ(CE.message().compare("CustomError {0}"), 0);
});
Error E3 = joinErrors(make_error<CustomError>(0), make_error<CustomError>(1));
EXPECT_EQ(toString(std::move(E3))
- .compare("CustomError { 0}\n"
- "CustomError { 1}"),
+ .compare("CustomError {0}\n"
+ "CustomError {1}"),
0);
}
+TEST(Error, Stream) {
+ {
+ Error OK = Error::success();
+ std::string Buf;
+ llvm::raw_string_ostream S(Buf);
+ S << OK;
+ EXPECT_EQ("success", S.str());
+ consumeError(std::move(OK));
+ }
+ {
+ Error E1 = make_error<CustomError>(0);
+ std::string Buf;
+ llvm::raw_string_ostream S(Buf);
+ S << E1;
+ EXPECT_EQ("CustomError {0}", S.str());
+ consumeError(std::move(E1));
+ }
+}
+
TEST(Error, ErrorMatchers) {
EXPECT_THAT_ERROR(Error::success(), Succeeded());
EXPECT_NONFATAL_FAILURE(
EXPECT_THAT_ERROR(make_error<CustomError>(0), Succeeded()),
- "Expected: succeeded\n Actual: failed (CustomError { 0})");
+ "Expected: succeeded\n Actual: failed (CustomError {0})");
EXPECT_THAT_ERROR(make_error<CustomError>(0), Failed());
EXPECT_NONFATAL_FAILURE(EXPECT_THAT_ERROR(Error::success(), Failed()),
@@ -748,14 +767,14 @@ TEST(Error, ErrorMatchers) {
Failed<CustomError>(testing::Property(&CustomError::getInfo, 1))),
"Expected: failed with Error of given type and the error is an object "
"whose given property is equal to 1\n"
- " Actual: failed (CustomError { 0})");
+ " Actual: failed (CustomError {0})");
EXPECT_THAT_ERROR(make_error<CustomError>(0), Failed<ErrorInfoBase>());
EXPECT_THAT_EXPECTED(Expected<int>(0), Succeeded());
EXPECT_NONFATAL_FAILURE(
EXPECT_THAT_EXPECTED(Expected<int>(make_error<CustomError>(0)),
Succeeded()),
- "Expected: succeeded\n Actual: failed (CustomError { 0})");
+ "Expected: succeeded\n Actual: failed (CustomError {0})");
EXPECT_THAT_EXPECTED(Expected<int>(make_error<CustomError>(0)), Failed());
EXPECT_NONFATAL_FAILURE(
@@ -767,7 +786,7 @@ TEST(Error, ErrorMatchers) {
EXPECT_THAT_EXPECTED(Expected<int>(make_error<CustomError>(0)),
HasValue(0)),
"Expected: succeeded with value (is equal to 0)\n"
- " Actual: failed (CustomError { 0})");
+ " Actual: failed (CustomError {0})");
EXPECT_NONFATAL_FAILURE(
EXPECT_THAT_EXPECTED(Expected<int>(1), HasValue(0)),
"Expected: succeeded with value (is equal to 0)\n"
@@ -787,7 +806,7 @@ TEST(Error, ErrorMatchers) {
EXPECT_THAT_EXPECTED(Expected<int>(make_error<CustomError>(0)),
HasValue(testing::Gt(1))),
"Expected: succeeded with value (is > 1)\n"
- " Actual: failed (CustomError { 0})");
+ " Actual: failed (CustomError {0})");
}
} // end anon namespace
diff --git a/llvm/unittests/Support/FormatVariadicTest.cpp b/llvm/unittests/Support/FormatVariadicTest.cpp
index 54373da51c4..6d621464c0e 100644
--- a/llvm/unittests/Support/FormatVariadicTest.cpp
+++ b/llvm/unittests/Support/FormatVariadicTest.cpp
@@ -671,3 +671,12 @@ TEST(FormatVariadicTest, CopiesAndMoves) {
EXPECT_EQ(0, R.Copied);
EXPECT_EQ(0, R.Moved);
}
+
+namespace adl {
+struct X {};
+raw_ostream &operator<<(raw_ostream &OS, const X &) { return OS << "X"; }
+} // namespace adl
+TEST(FormatVariadicTest, FormatStreamable) {
+ adl::X X;
+ EXPECT_EQ("X", formatv("{0}", X).str());
+}
OpenPOWER on IntegriCloud