]> granicus.if.org Git - clang/commitdiff
unittests: explicit stringify StringRefs for conversion
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 25 Jan 2014 20:04:44 +0000 (20:04 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 25 Jan 2014 20:04:44 +0000 (20:04 +0000)
When clang is built outside of the LLVM tree (against a corresponding version),
there is no definition providing for operator<<(std::ostream &, StringRef) which
is required for the assertion routines in google-test tests.  Avoid the
compilation failure by explicitly stringifying the StringRef prior to use.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200096 91177308-0d34-0410-b5e6-96231b3b80d8

unittests/AST/DeclPrinterTest.cpp
unittests/AST/StmtPrinterTest.cpp
unittests/Tooling/CompilationDatabaseTest.cpp

index ade55aaee363e2a0c62bf574ada8d2f83d94c639..66da3866029306de6438b81590b991bd656ed38e 100644 (file)
@@ -77,7 +77,8 @@ public:
   OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder));
 
   if (!runToolOnCodeWithArgs(Factory->create(), Code, Args, FileName))
-    return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
+    return testing::AssertionFailure()
+      << "Parsing error in \"" << Code.str() << "\"";
 
   if (Printer.getNumFoundDecls() == 0)
     return testing::AssertionFailure()
@@ -90,8 +91,8 @@ public:
 
   if (Printer.getPrinted() != ExpectedPrinted)
     return ::testing::AssertionFailure()
-      << "Expected \"" << ExpectedPrinted << "\", "
-         "got \"" << Printer.getPrinted() << "\"";
+      << "Expected \"" << ExpectedPrinted.str() << "\", "
+         "got \"" << Printer.getPrinted().str() << "\"";
 
   return ::testing::AssertionSuccess();
 }
index 473ee13b2a273ad1854ff7c67bc76036cf3a2077..eac36d65ee47e8aba68e656387331e85f1145eaa 100644 (file)
@@ -76,7 +76,8 @@ public:
   OwningPtr<FrontendActionFactory> Factory(newFrontendActionFactory(&Finder));
 
   if (!runToolOnCodeWithArgs(Factory->create(), Code, Args))
-    return testing::AssertionFailure() << "Parsing error in \"" << Code << "\"";
+    return testing::AssertionFailure()
+      << "Parsing error in \"" << Code.str() << "\"";
 
   if (Printer.getNumFoundStmts() == 0)
     return testing::AssertionFailure()
@@ -89,8 +90,8 @@ public:
 
   if (Printer.getPrinted() != ExpectedPrinted)
     return ::testing::AssertionFailure()
-      << "Expected \"" << ExpectedPrinted << "\", "
-         "got \"" << Printer.getPrinted() << "\"";
+      << "Expected \"" << ExpectedPrinted.str() << "\", "
+         "got \"" << Printer.getPrinted().str() << "\"";
 
   return ::testing::AssertionSuccess();
 }
index c575dff209a7f47432ffaea43d6319fea2e4a71d..4920d6d66bb949e02e4f694af757c5e6c67d39ff 100644 (file)
@@ -24,7 +24,7 @@ static void expectFailure(StringRef JSONDatabase, StringRef Explanation) {
   std::string ErrorMessage;
   EXPECT_EQ(NULL, JSONCompilationDatabase::loadFromBuffer(JSONDatabase,
                                                           ErrorMessage))
-    << "Expected an error because of: " << Explanation;
+    << "Expected an error because of: " << Explanation.str();
 }
 
 TEST(JSONCompilationDatabase, ErrsOnInvalidFormat) {