Pārlūkot izejas kodu

[clang-format] In tests, expected code should be format-stable

Summary: Extend various verifyFormat helper functions to check that the
expected text is "stable". This provides some protection against bugs
where formatting results are ocilating between two forms, or continually
change in some other way.

Testing Done:

* Ran unit tests.

* Reproduced a known instability in preprocessor indentation which was
  caught by this new check.

Reviewers: krasimir

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D42034

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@329231 91177308-0d34-0410-b5e6-96231b3b80d8
Mark Zeren 7 gadi atpakaļ
vecāks
revīzija
893efa76e2

+ 2 - 0
unittests/Format/FormatTest.cpp

@@ -72,6 +72,8 @@ protected:
 
 
   void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
   void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
                     const FormatStyle &Style = getLLVMStyle()) {
                     const FormatStyle &Style = getLLVMStyle()) {
+    EXPECT_EQ(Expected.str(), format(Expected, Style))
+        << "Expected code is not stable";
     EXPECT_EQ(Expected.str(), format(Code, Style));
     EXPECT_EQ(Expected.str(), format(Code, Style));
     if (Style.Language == FormatStyle::LK_Cpp) {
     if (Style.Language == FormatStyle::LK_Cpp) {
       // Objective-C++ is a superset of C++, so everything checked for C++
       // Objective-C++ is a superset of C++, so everything checked for C++

+ 1 - 0
unittests/Format/FormatTestComments.cpp

@@ -70,6 +70,7 @@ protected:
 
 
   void verifyFormat(llvm::StringRef Code,
   void verifyFormat(llvm::StringRef Code,
                     const FormatStyle &Style = getLLVMStyle()) {
                     const FormatStyle &Style = getLLVMStyle()) {
+    EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
   }
 
 

+ 4 - 0
unittests/Format/FormatTestJS.cpp

@@ -49,6 +49,8 @@ protected:
   static void verifyFormat(
   static void verifyFormat(
       llvm::StringRef Code,
       llvm::StringRef Code,
       const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
       const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
+    EXPECT_EQ(Code.str(), format(Code, Style))
+        << "Expected code is not stable";
     std::string Result = format(test::messUp(Code), Style);
     std::string Result = format(test::messUp(Code), Style);
     EXPECT_EQ(Code.str(), Result) << "Formatted:\n" << Result;
     EXPECT_EQ(Code.str(), Result) << "Formatted:\n" << Result;
   }
   }
@@ -57,6 +59,8 @@ protected:
       llvm::StringRef Expected,
       llvm::StringRef Expected,
       llvm::StringRef Code,
       llvm::StringRef Code,
       const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
       const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
+    EXPECT_EQ(Expected.str(), format(Expected, Style))
+        << "Expected code is not stable";
     std::string Result = format(Code, Style);
     std::string Result = format(Code, Style);
     EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
     EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
   }
   }

+ 1 - 0
unittests/Format/FormatTestJava.cpp

@@ -46,6 +46,7 @@ protected:
   static void verifyFormat(
   static void verifyFormat(
       llvm::StringRef Code,
       llvm::StringRef Code,
       const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
       const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_Java)) {
+    EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
   }
 };
 };

+ 1 - 0
unittests/Format/FormatTestObjC.cpp

@@ -58,6 +58,7 @@ protected:
   }
   }
 
 
   void verifyFormat(StringRef Code) {
   void verifyFormat(StringRef Code) {
+    EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
     EXPECT_EQ(Code.str(), format(test::messUp(Code)));
     EXPECT_EQ(Code.str(), format(test::messUp(Code)));
   }
   }
 
 

+ 1 - 0
unittests/Format/FormatTestProto.cpp

@@ -38,6 +38,7 @@ protected:
   }
   }
 
 
   static void verifyFormat(llvm::StringRef Code) {
   static void verifyFormat(llvm::StringRef Code) {
+    EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
     EXPECT_EQ(Code.str(), format(test::messUp(Code)));
     EXPECT_EQ(Code.str(), format(test::messUp(Code)));
   }
   }
 };
 };

+ 1 - 0
unittests/Format/FormatTestTextProto.cpp

@@ -36,6 +36,7 @@ protected:
   }
   }
 
 
   static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
   static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+    EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
     EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
   }
   }