]> granicus.if.org Git - clang/commitdiff
[clang-format] In tests, expected code should be format-stable
authorMark Zeren <mzeren@vmware.com>
Wed, 4 Apr 2018 21:09:00 +0000 (21:09 +0000)
committerMark Zeren <mzeren@vmware.com>
Wed, 4 Apr 2018 21:09:00 +0000 (21:09 +0000)
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

unittests/Format/FormatTest.cpp
unittests/Format/FormatTestComments.cpp
unittests/Format/FormatTestJS.cpp
unittests/Format/FormatTestJava.cpp
unittests/Format/FormatTestObjC.cpp
unittests/Format/FormatTestProto.cpp
unittests/Format/FormatTestTextProto.cpp

index 2d20bc03651c7d07018ead793b52d1ad25a532d3..43225304670f64ab6bcb70180fb02374b66737f0 100644 (file)
@@ -72,6 +72,8 @@ protected:
 
   void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
                     const FormatStyle &Style = getLLVMStyle()) {
+    EXPECT_EQ(Expected.str(), format(Expected, Style))
+        << "Expected code is not stable";
     EXPECT_EQ(Expected.str(), format(Code, Style));
     if (Style.Language == FormatStyle::LK_Cpp) {
       // Objective-C++ is a superset of C++, so everything checked for C++
index ed11fbdb1fc0da92c686f7f2bbab7de0be78be48..005039698bba48479e82aaf8db3eb74d0fdb8a01 100644 (file)
@@ -70,6 +70,7 @@ protected:
 
   void verifyFormat(llvm::StringRef Code,
                     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));
   }
 
index 5fb47a7d32f0b0f09df8519ee4f2f3b7c347a985..347118353e368d7051a42bf4c3fce3d48bc9c33b 100644 (file)
@@ -49,6 +49,8 @@ protected:
   static void verifyFormat(
       llvm::StringRef Code,
       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);
     EXPECT_EQ(Code.str(), Result) << "Formatted:\n" << Result;
   }
@@ -57,6 +59,8 @@ protected:
       llvm::StringRef Expected,
       llvm::StringRef Code,
       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);
     EXPECT_EQ(Expected.str(), Result) << "Formatted:\n" << Result;
   }
index 1d471b73ee64e4dd9bc466079be103995fd87582..36b72fda475f1fbee7321da3b812a9494de80e19 100644 (file)
@@ -46,6 +46,7 @@ protected:
   static void verifyFormat(
       llvm::StringRef Code,
       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));
   }
 };
index ed5d1aa25609b50e3d39eb61e15e373cbacd630f..b54b1c0b63db7eb612e8e1877c6d7ad310932526 100644 (file)
@@ -58,6 +58,7 @@ protected:
   }
 
   void verifyFormat(StringRef Code) {
+    EXPECT_EQ(Code.str(), format(Code)) << "Expected code is not stable";
     EXPECT_EQ(Code.str(), format(test::messUp(Code)));
   }
 
index 66c5d3778d4a3c3f3b39bf0e9c5631ae085c3ee3..672fd5914d077adb553ebf7f978672ccfa9afde0 100644 (file)
@@ -38,6 +38,7 @@ protected:
   }
 
   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)));
   }
 };
index f4e09cf9e27bd082457ec7242ed1bf890e5edb8a..2cd7fb7bdf3051fe7bc96a94063e84d32d2fad94 100644 (file)
@@ -36,6 +36,7 @@ protected:
   }
 
   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));
   }