[llvm] 77bab2a - [llvm][unittests] Strip unneeded use of raw_string_ostream::str() (NFC)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 15:35:18 PDT 2024


Author: JOE1994
Date: 2024-09-13T18:33:41-04:00
New Revision: 77bab2a6f37af918a9133d1bb15551bd351b291e

URL: https://github.com/llvm/llvm-project/commit/77bab2a6f37af918a9133d1bb15551bd351b291e
DIFF: https://github.com/llvm/llvm-project/commit/77bab2a6f37af918a9133d1bb15551bd351b291e.diff

LOG: [llvm][unittests] Strip unneeded use of raw_string_ostream::str() (NFC)

Avoid unneeded layer of indirection.

Added: 
    

Modified: 
    llvm/unittests/IR/AsmWriterTest.cpp
    llvm/unittests/IR/MetadataTest.cpp
    llvm/unittests/IR/ValueTest.cpp
    llvm/unittests/IR/VerifierTest.cpp
    llvm/unittests/Support/ARMAttributeParser.cpp
    llvm/unittests/Support/CSKYAttributeParserTest.cpp
    llvm/unittests/Support/Chrono.cpp
    llvm/unittests/Support/ErrorTest.cpp
    llvm/unittests/Support/JSONTest.cpp
    llvm/unittests/Support/ScopedPrinterTest.cpp
    llvm/unittests/Support/WithColorTest.cpp
    llvm/unittests/Support/YAMLIOTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/IR/AsmWriterTest.cpp b/llvm/unittests/IR/AsmWriterTest.cpp
index e9da0a4b39704f..75305f4e2dea40 100644
--- a/llvm/unittests/IR/AsmWriterTest.cpp
+++ b/llvm/unittests/IR/AsmWriterTest.cpp
@@ -33,8 +33,7 @@ TEST(AsmWriterTest, DebugPrintDetachedInstruction) {
   std::string S;
   raw_string_ostream OS(S);
   Add->print(OS);
-  EXPECT_THAT(OS.str(),
-              HasSubstr("<badref> = add i32 poison, poison, !<empty"));
+  EXPECT_THAT(S, HasSubstr("<badref> = add i32 poison, poison, !<empty"));
 }
 
 TEST(AsmWriterTest, DebugPrintDetachedArgument) {
@@ -60,8 +59,7 @@ TEST(AsmWriterTest, DumpDIExpression) {
   std::string S;
   raw_string_ostream OS(S);
   Expr->print(OS);
-  EXPECT_EQ("!DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref)",
-            OS.str());
+  EXPECT_EQ("!DIExpression(DW_OP_constu, 4, DW_OP_minus, DW_OP_deref)", S);
 }
 
 TEST(AsmWriterTest, PrintAddrspaceWithNullOperand) {
@@ -80,7 +78,7 @@ TEST(AsmWriterTest, PrintAddrspaceWithNullOperand) {
   std::string S;
   raw_string_ostream OS(S);
   Call->print(OS);
-  EXPECT_THAT(OS.str(), HasSubstr("<cannot get addrspace!>"));
+  EXPECT_THAT(S, HasSubstr("<cannot get addrspace!>"));
 }
 
 TEST(AsmWriterTest, PrintNullOperandBundle) {
@@ -103,6 +101,6 @@ TEST(AsmWriterTest, PrintNullOperandBundle) {
   std::string S;
   raw_string_ostream OS(S);
   Invoke->print(OS);
-  EXPECT_THAT(OS.str(), HasSubstr("<null operand bundle!>"));
+  EXPECT_THAT(S, HasSubstr("<null operand bundle!>"));
 }
 }

diff  --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp
index 17573ca57e0874..e9bf367ac945b3 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -157,7 +157,7 @@ TEST_F(MDStringTest, PrintingSimple) {
   std::string Str;
   raw_string_ostream oss(Str);
   s->print(oss);
-  EXPECT_STREQ("!\"testing 1 2 3\"", oss.str().c_str());
+  EXPECT_STREQ("!\"testing 1 2 3\"", Str.c_str());
 }
 
 // Test printing of MDString with non-printable characters.
@@ -167,7 +167,7 @@ TEST_F(MDStringTest, PrintingComplex) {
   std::string Str;
   raw_string_ostream oss(Str);
   s->print(oss);
-  EXPECT_STREQ("!\"\\00\\0A\\22\\\\\\FF\"", oss.str().c_str());
+  EXPECT_STREQ("!\"\\00\\0A\\22\\\\\\FF\"", Str.c_str());
 }
 
 typedef MetadataTest MDNodeTest;
@@ -4604,8 +4604,7 @@ TEST(NamedMDNodeTest, Search) {
   std::string Str;
   raw_string_ostream oss(Str);
   NMD->print(oss);
-  EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n",
-               oss.str().c_str());
+  EXPECT_STREQ("!llvm.NMD1 = !{!0, !1}\n", Str.c_str());
 }
 
 typedef MetadataTest FunctionAttachmentTest;

diff  --git a/llvm/unittests/IR/ValueTest.cpp b/llvm/unittests/IR/ValueTest.cpp
index a90438a078c62e..ca45e9abcf2259 100644
--- a/llvm/unittests/IR/ValueTest.cpp
+++ b/llvm/unittests/IR/ValueTest.cpp
@@ -157,13 +157,13 @@ TEST(ValueTest, printSlots) {
       std::string S;                                                           \
       raw_string_ostream OS(S);                                                \
       INST->print(OS);                                                         \
-      EXPECT_EQ(STR, OS.str());                                                \
+      EXPECT_EQ(STR, S);                                                       \
     }                                                                          \
     {                                                                          \
       std::string S;                                                           \
       raw_string_ostream OS(S);                                                \
       INST->print(OS, MST);                                                    \
-      EXPECT_EQ(STR, OS.str());                                                \
+      EXPECT_EQ(STR, S);                                                       \
     }                                                                          \
   } while (false)
   CHECK_PRINT(I0, "  %0 = add i32 %y, 1");
@@ -176,13 +176,13 @@ TEST(ValueTest, printSlots) {
       std::string S;                                                           \
       raw_string_ostream OS(S);                                                \
       INST->printAsOperand(OS, TYPE);                                          \
-      EXPECT_EQ(StringRef(STR), StringRef(OS.str()));                          \
+      EXPECT_EQ(StringRef(STR), StringRef(S));                                 \
     }                                                                          \
     {                                                                          \
       std::string S;                                                           \
       raw_string_ostream OS(S);                                                \
       INST->printAsOperand(OS, TYPE, MST);                                     \
-      EXPECT_EQ(StringRef(STR), StringRef(OS.str()));                          \
+      EXPECT_EQ(StringRef(STR), StringRef(S));                                 \
     }                                                                          \
   } while (false)
   CHECK_PRINT_AS_OPERAND(I0, false, "%0");

diff  --git a/llvm/unittests/IR/VerifierTest.cpp b/llvm/unittests/IR/VerifierTest.cpp
index d79b4f3d8a4444..8199dabc7084c2 100644
--- a/llvm/unittests/IR/VerifierTest.cpp
+++ b/llvm/unittests/IR/VerifierTest.cpp
@@ -105,10 +105,8 @@ TEST(VerifierTest, InvalidRetAttribute) {
   std::string Error;
   raw_string_ostream ErrorOS(Error);
   EXPECT_TRUE(verifyModule(M, &ErrorOS));
-  EXPECT_TRUE(
-      StringRef(ErrorOS.str())
-          .starts_with(
-              "Attribute 'uwtable' does not apply to function return values"));
+  EXPECT_TRUE(StringRef(Error).starts_with(
+      "Attribute 'uwtable' does not apply to function return values"));
 }
 
 /// Test the verifier rejects invalid nofpclass values that the assembler may
@@ -133,7 +131,7 @@ TEST(VerifierTest, InvalidNoFPClassAttribute) {
     raw_string_ostream ErrorOS(Error);
     EXPECT_TRUE(verifyModule(M, &ErrorOS));
 
-    StringRef ErrMsg(ErrorOS.str());
+    StringRef ErrMsg(Error);
 
     if (InvalidMask == 0) {
       EXPECT_TRUE(ErrMsg.starts_with(
@@ -173,33 +171,30 @@ TEST(VerifierTest, CrossModuleRef) {
   std::string Error;
   raw_string_ostream ErrorOS(Error);
   EXPECT_TRUE(verifyModule(M2, &ErrorOS));
-  EXPECT_TRUE(StringRef(ErrorOS.str()) ==
-              "Global is referenced in a 
diff erent module!\n"
-              "ptr @foo2\n"
-              "; ModuleID = 'M2'\n"
-              "  %call = call i32 @foo2()\n"
-              "ptr @foo1\n"
-              "; ModuleID = 'M1'\n"
-              "Global is used by function in a 
diff erent module\n"
-              "ptr @foo2\n"
-              "; ModuleID = 'M2'\n"
-              "ptr @foo3\n"
-              "; ModuleID = 'M3'\n");
+  EXPECT_TRUE(Error == "Global is referenced in a 
diff erent module!\n"
+                       "ptr @foo2\n"
+                       "; ModuleID = 'M2'\n"
+                       "  %call = call i32 @foo2()\n"
+                       "ptr @foo1\n"
+                       "; ModuleID = 'M1'\n"
+                       "Global is used by function in a 
diff erent module\n"
+                       "ptr @foo2\n"
+                       "; ModuleID = 'M2'\n"
+                       "ptr @foo3\n"
+                       "; ModuleID = 'M3'\n");
 
   Error.clear();
   EXPECT_TRUE(verifyModule(M1, &ErrorOS));
-  EXPECT_TRUE(StringRef(ErrorOS.str()) ==
-              "Referencing function in another module!\n"
-              "  %call = call i32 @foo2()\n"
-              "; ModuleID = 'M1'\n"
-              "ptr @foo2\n"
-              "; ModuleID = 'M2'\n");
+  EXPECT_TRUE(StringRef(Error) == "Referencing function in another module!\n"
+                                  "  %call = call i32 @foo2()\n"
+                                  "; ModuleID = 'M1'\n"
+                                  "ptr @foo2\n"
+                                  "; ModuleID = 'M2'\n");
 
   Error.clear();
   EXPECT_TRUE(verifyModule(M3, &ErrorOS));
-  EXPECT_TRUE(
-      StringRef(ErrorOS.str())
-          .starts_with("Referencing personality function in another module!"));
+  EXPECT_TRUE(StringRef(Error).starts_with(
+      "Referencing personality function in another module!"));
 
   // Erase bad methods to avoid triggering an assertion failure on destruction
   F1->eraseFromParent();
@@ -214,9 +209,8 @@ TEST(VerifierTest, InvalidVariableLinkage) {
   std::string Error;
   raw_string_ostream ErrorOS(Error);
   EXPECT_TRUE(verifyModule(M, &ErrorOS));
-  EXPECT_TRUE(StringRef(ErrorOS.str())
-                  .starts_with("Global is external, but doesn't "
-                               "have external or weak linkage!"));
+  EXPECT_TRUE(StringRef(Error).starts_with("Global is external, but doesn't "
+                                           "have external or weak linkage!"));
 }
 
 TEST(VerifierTest, InvalidFunctionLinkage) {
@@ -228,9 +222,8 @@ TEST(VerifierTest, InvalidFunctionLinkage) {
   std::string Error;
   raw_string_ostream ErrorOS(Error);
   EXPECT_TRUE(verifyModule(M, &ErrorOS));
-  EXPECT_TRUE(StringRef(ErrorOS.str())
-                  .starts_with("Global is external, but doesn't "
-                               "have external or weak linkage!"));
+  EXPECT_TRUE(StringRef(Error).starts_with("Global is external, but doesn't "
+                                           "have external or weak linkage!"));
 }
 
 TEST(VerifierTest, DetectInvalidDebugInfo) {
@@ -287,9 +280,8 @@ TEST(VerifierTest, MDNodeWrongContext) {
   std::string Error;
   raw_string_ostream ErrorOS(Error);
   EXPECT_TRUE(verifyModule(M, &ErrorOS));
-  EXPECT_TRUE(
-      StringRef(ErrorOS.str())
-          .starts_with("MDNode context does not match Module context!"));
+  EXPECT_TRUE(StringRef(Error).starts_with(
+      "MDNode context does not match Module context!"));
 }
 
 TEST(VerifierTest, AttributesWrongContext) {
@@ -358,9 +350,8 @@ TEST(VerifierTest, CrossFunctionRef) {
   std::string Error;
   raw_string_ostream ErrorOS(Error);
   EXPECT_TRUE(verifyModule(M, &ErrorOS));
-  EXPECT_TRUE(
-      StringRef(ErrorOS.str())
-          .starts_with("Referring to an instruction in another function!"));
+  EXPECT_TRUE(StringRef(Error).starts_with(
+      "Referring to an instruction in another function!"));
 
   // Explicitly erase the store to avoid a use-after-free when the module is
   // destroyed.
@@ -388,11 +379,10 @@ TEST(VerifierTest, AtomicRMW) {
   std::string Error;
   raw_string_ostream ErrorOS(Error);
   EXPECT_TRUE(verifyFunction(*F, &ErrorOS));
-  EXPECT_TRUE(
-      StringRef(ErrorOS.str())
-          .starts_with("atomicrmw fadd operand must have floating-point or "
-                       "fixed vector of floating-point type!"))
-      << ErrorOS.str();
+  EXPECT_TRUE(StringRef(Error).starts_with(
+      "atomicrmw fadd operand must have floating-point or "
+      "fixed vector of floating-point type!"))
+      << Error;
 }
 
 } // end anonymous namespace

diff  --git a/llvm/unittests/Support/ARMAttributeParser.cpp b/llvm/unittests/Support/ARMAttributeParser.cpp
index 4bde0eeb950308..a0568262b4da95 100644
--- a/llvm/unittests/Support/ARMAttributeParser.cpp
+++ b/llvm/unittests/Support/ARMAttributeParser.cpp
@@ -31,8 +31,8 @@ bool testBuildAttr(unsigned Tag, unsigned Value,
   raw_string_ostream OS(buffer);
   AttributeSection Section(Tag, Value);
   Section.write(OS);
-  ArrayRef<uint8_t> Bytes(
-    reinterpret_cast<const uint8_t*>(OS.str().c_str()), OS.str().size());
+  ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(buffer.c_str()),
+                          buffer.size());
 
   ARMAttributeParser Parser;
   cantFail(Parser.parse(Bytes, llvm::endianness::little));

diff  --git a/llvm/unittests/Support/CSKYAttributeParserTest.cpp b/llvm/unittests/Support/CSKYAttributeParserTest.cpp
index 1d39d14899f852..2c5d93b0b75651 100644
--- a/llvm/unittests/Support/CSKYAttributeParserTest.cpp
+++ b/llvm/unittests/Support/CSKYAttributeParserTest.cpp
@@ -77,8 +77,8 @@ static bool testAttributeInt(unsigned Tag, unsigned Value, unsigned ExpectedTag,
   raw_string_ostream OS(buffer);
   CSKYAttributeSection Section(Tag, Value);
   Section.writeInt(OS);
-  ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(OS.str().c_str()),
-                          OS.str().size());
+  ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(buffer.c_str()),
+                          buffer.size());
 
   CSKYAttributeParser Parser;
   cantFail(Parser.parse(Bytes, llvm::endianness::little));
@@ -94,8 +94,8 @@ static bool testAttributeString(unsigned Tag, const char *Value,
   raw_string_ostream OS(buffer);
   CSKYAttributeSection Section(Tag, Value);
   Section.writeString(OS);
-  ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(OS.str().c_str()),
-                          OS.str().size());
+  ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(buffer.c_str()),
+                          buffer.size());
 
   CSKYAttributeParser Parser;
   cantFail(Parser.parse(Bytes, llvm::endianness::little));
@@ -109,8 +109,8 @@ static void testParseError(unsigned Tag, unsigned Value, const char *msg) {
   raw_string_ostream OS(buffer);
   CSKYAttributeSection Section(Tag, Value);
   Section.writeInt(OS);
-  ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(OS.str().c_str()),
-                          OS.str().size());
+  ArrayRef<uint8_t> Bytes(reinterpret_cast<const uint8_t *>(buffer.c_str()),
+                          buffer.size());
 
   CSKYAttributeParser Parser;
   Error e = Parser.parse(Bytes, llvm::endianness::little);

diff  --git a/llvm/unittests/Support/Chrono.cpp b/llvm/unittests/Support/Chrono.cpp
index 7dfc5dd2c29348..3e3e5517a0aedb 100644
--- a/llvm/unittests/Support/Chrono.cpp
+++ b/llvm/unittests/Support/Chrono.cpp
@@ -48,10 +48,10 @@ TEST(Chrono, TimePointFormat) {
   std::string S;
   raw_string_ostream OS(S);
   OS << T;
-  EXPECT_EQ("2006-01-02 15:04:05.123456789", OS.str());
+  EXPECT_EQ("2006-01-02 15:04:05.123456789", S);
   S.clear();
   OS << T2;
-  EXPECT_EQ("2006-01-02 15:04:05.023456789", OS.str());
+  EXPECT_EQ("2006-01-02 15:04:05.023456789", S);
 
   // formatv default style matches operator<<.
   EXPECT_EQ("2006-01-02 15:04:05.123456789", formatv("{0}", T).str());

diff  --git a/llvm/unittests/Support/ErrorTest.cpp b/llvm/unittests/Support/ErrorTest.cpp
index 4cd9896c3b08e8..16e4865e1bfe97 100644
--- a/llvm/unittests/Support/ErrorTest.cpp
+++ b/llvm/unittests/Support/ErrorTest.cpp
@@ -442,7 +442,7 @@ TEST(Error, StringError) {
   raw_string_ostream S(Msg);
   logAllUnhandledErrors(
       make_error<StringError>("foo" + Twine(42), inconvertibleErrorCode()), S);
-  EXPECT_EQ(S.str(), "foo42\n") << "Unexpected StringError log result";
+  EXPECT_EQ(Msg, "foo42\n") << "Unexpected StringError log result";
 
   auto EC =
     errorToErrorCode(make_error<StringError>("", errc::invalid_argument));
@@ -457,14 +457,14 @@ TEST(Error, createStringError) {
   raw_string_ostream S(Msg);
   logAllUnhandledErrors(createStringError(EC, "foo%s%d0x%" PRIx8, Bar, 1, 0xff),
                         S);
-  EXPECT_EQ(S.str(), "foobar10xff\n")
-    << "Unexpected createStringError() log result";
+  EXPECT_EQ(Msg, "foobar10xff\n")
+      << "Unexpected createStringError() log result";
 
   S.flush();
   Msg.clear();
   logAllUnhandledErrors(createStringError(EC, Bar), S);
-  EXPECT_EQ(S.str(), "bar\n")
-    << "Unexpected createStringError() (overloaded) log result";
+  EXPECT_EQ(Msg, "bar\n")
+      << "Unexpected createStringError() (overloaded) log result";
 
   S.flush();
   Msg.clear();
@@ -769,7 +769,7 @@ TEST(Error, Stream) {
     std::string Buf;
     llvm::raw_string_ostream S(Buf);
     S << OK;
-    EXPECT_EQ("success", S.str());
+    EXPECT_EQ("success", Buf);
     consumeError(std::move(OK));
   }
   {
@@ -777,7 +777,7 @@ TEST(Error, Stream) {
     std::string Buf;
     llvm::raw_string_ostream S(Buf);
     S << E1;
-    EXPECT_EQ("CustomError {0}", S.str());
+    EXPECT_EQ("CustomError {0}", Buf);
     consumeError(std::move(E1));
   }
 }

diff  --git a/llvm/unittests/Support/JSONTest.cpp b/llvm/unittests/Support/JSONTest.cpp
index 8aa42a28ee92a7..4e56557132976c 100644
--- a/llvm/unittests/Support/JSONTest.cpp
+++ b/llvm/unittests/Support/JSONTest.cpp
@@ -502,7 +502,7 @@ static std::string errorContext(const Value &V, const Path::Root &R) {
   std::string Context;
   llvm::raw_string_ostream OS(Context);
   R.printErrorContext(V, OS);
-  return OS.str();
+  return Context;
 }
 
 TEST(JSONTest, Deserialize) {
@@ -603,7 +603,7 @@ TEST(JSONTest, Stream) {
       J.attributeEnd();
       J.attribute("baz", "xyz");
     });
-    return OS.str();
+    return S;
   };
 
   const char *Plain =

diff  --git a/llvm/unittests/Support/ScopedPrinterTest.cpp b/llvm/unittests/Support/ScopedPrinterTest.cpp
index 895e04c2c024af..72af331a2b009c 100644
--- a/llvm/unittests/Support/ScopedPrinterTest.cpp
+++ b/llvm/unittests/Support/ScopedPrinterTest.cpp
@@ -30,10 +30,10 @@ TEST(JSONScopedPrinterTest, PrettyPrintCtor) {
 })";
   const char *NoPrettyPrintOut = R"({"Key":"Value"})";
   PrintFunc(PrettyPrintWriter);
-  EXPECT_EQ(PrettyPrintOut, OS.str());
+  EXPECT_EQ(PrettyPrintOut, StreamBuffer);
   StreamBuffer.clear();
   PrintFunc(NoPrettyPrintWriter);
-  EXPECT_EQ(NoPrettyPrintOut, OS.str());
+  EXPECT_EQ(NoPrettyPrintOut, StreamBuffer);
 }
 
 TEST(JSONScopedPrinterTest, DelimitedScopeCtor) {
@@ -44,20 +44,20 @@ TEST(JSONScopedPrinterTest, DelimitedScopeCtor) {
                                       std::make_unique<DictScope>());
     DictScopeWriter.printString("Label", "DictScope");
   }
-  EXPECT_EQ(R"({"Label":"DictScope"})", OS.str());
+  EXPECT_EQ(R"({"Label":"DictScope"})", StreamBuffer);
   StreamBuffer.clear();
   {
     JSONScopedPrinter ListScopeWriter(OS, /*PrettyPrint=*/false,
                                       std::make_unique<ListScope>());
     ListScopeWriter.printString("ListScope");
   }
-  EXPECT_EQ(R"(["ListScope"])", OS.str());
+  EXPECT_EQ(R"(["ListScope"])", StreamBuffer);
   StreamBuffer.clear();
   {
     JSONScopedPrinter NoScopeWriter(OS, /*PrettyPrint=*/false);
     NoScopeWriter.printString("NoScope");
   }
-  EXPECT_EQ(R"("NoScope")", OS.str());
+  EXPECT_EQ(R"("NoScope")", StreamBuffer);
 }
 
 class ScopedPrinterTest : public ::testing::Test {
@@ -78,7 +78,7 @@ class ScopedPrinterTest : public ::testing::Test {
   void verifyScopedPrinter(StringRef Expected, PrintFunc Func) {
     Func(Writer);
     Writer.flush();
-    EXPECT_EQ(Expected.str(), OS.str());
+    EXPECT_EQ(Expected.str(), StreamBuffer);
     StreamBuffer.clear();
   }
 
@@ -88,7 +88,7 @@ class ScopedPrinterTest : public ::testing::Test {
       Func(JSONWriter);
     }
     JSONWriter.flush();
-    EXPECT_EQ(Expected.str(), OS.str());
+    EXPECT_EQ(Expected.str(), StreamBuffer);
     StreamBuffer.clear();
     HasPrintedToJSON = true;
   }

diff  --git a/llvm/unittests/Support/WithColorTest.cpp b/llvm/unittests/Support/WithColorTest.cpp
index ce90320f65b4a5..b3bd827aef2593 100644
--- a/llvm/unittests/Support/WithColorTest.cpp
+++ b/llvm/unittests/Support/WithColorTest.cpp
@@ -19,7 +19,7 @@ TEST(WithColorTest, ColorMode) {
     OS.enable_colors(true);
 
     WithColor(OS, HighlightColor::Error, ColorMode::Disable) << "test";
-    EXPECT_EQ("test", OS.str());
+    EXPECT_EQ("test", S);
   }
 
   {
@@ -28,7 +28,7 @@ TEST(WithColorTest, ColorMode) {
     OS.enable_colors(true);
 
     WithColor(OS, HighlightColor::Error, ColorMode::Auto) << "test";
-    EXPECT_EQ("test", OS.str());
+    EXPECT_EQ("test", S);
   }
 
 #ifdef LLVM_ON_UNIX
@@ -38,7 +38,7 @@ TEST(WithColorTest, ColorMode) {
     OS.enable_colors(true);
 
     WithColor(OS, HighlightColor::Error, ColorMode::Enable) << "test";
-    EXPECT_EQ("\x1B[0;1;31mtest\x1B[0m", OS.str());
+    EXPECT_EQ("\x1B[0;1;31mtest\x1B[0m", S);
   }
 #endif
 }

diff  --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index 9d40b62115a675..69537fc36a8531 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -1239,7 +1239,8 @@ TEST(YAMLIO, TestReadWriteBlockScalarDocuments) {
 
     // Verify that the block scalar header was written out on the same line
     // as the document marker.
-    EXPECT_NE(llvm::StringRef::npos, llvm::StringRef(ostr.str()).find("--- |"));
+    EXPECT_NE(llvm::StringRef::npos,
+              llvm::StringRef(intermediate).find("--- |"));
   }
   {
     Input yin(intermediate);
@@ -2763,7 +2764,7 @@ TEST(YAMLIO, TestEmptyMapWrite) {
   llvm::raw_string_ostream OS(str);
   Output yout(OS);
   yout << cont;
-  EXPECT_EQ(OS.str(), "---\nfbm:             {}\n...\n");
+  EXPECT_EQ(str, "---\nfbm:             {}\n...\n");
 }
 
 TEST(YAMLIO, TestEmptySequenceWrite) {
@@ -2773,7 +2774,7 @@ TEST(YAMLIO, TestEmptySequenceWrite) {
     llvm::raw_string_ostream OS(str);
     Output yout(OS);
     yout << cont;
-    EXPECT_EQ(OS.str(), "---\nfbs:             []\n...\n");
+    EXPECT_EQ(str, "---\nfbs:             []\n...\n");
   }
 
   {
@@ -2782,7 +2783,7 @@ TEST(YAMLIO, TestEmptySequenceWrite) {
     llvm::raw_string_ostream OS(str);
     Output yout(OS);
     yout << seq;
-    EXPECT_EQ(OS.str(), "---\n[]\n...\n");
+    EXPECT_EQ(str, "---\n[]\n...\n");
   }
 }
 


        


More information about the llvm-commits mailing list