[PATCH] D53482: Add clang-format stability check with FormatTests

Vladimir Glavnyy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 21 10:55:02 PDT 2018


vglavnyy created this revision.
vglavnyy added reviewers: djasper, krasimir.
Herald added a subscriber: cfe-commits.

Twice running clang-format may give unstable result for some code samples, for example: https://bugs.llvm.org/show_bug.cgi?id=23728
This commit adds stability check to clang-format unit-tests.
After apply this patch 10 tests from the FormatTests will fail.

> [==========] 647 tests from 19 test cases ran. (31449 ms total)
> [  PASSED  ] 637 tests.
> [  FAILED  ] 10 tests, listed below:
> [  FAILED  ] FormatTest.OnlyGeneratesNecessaryReplacements
> [  FAILED  ] FormatTest.BreaksStringLiterals
> [  FAILED  ] FormatTest.BreaksStringLiteralsWithTabs
> [  FAILED  ] FormatTest.BreaksWideAndNSStringLiterals
> [  FAILED  ] FormatTest.BreaksStringLiteralsWithin_TMacro
> [  FAILED  ] FormatTest.DoNotBreakStringLiteralsInEscapeSequence
> [  FAILED  ] FormatTest.OptimizeBreakPenaltyVsExcess
> [  FAILED  ] FormatTest.WorksFor8bitEncodings
> [  FAILED  ] FormatTest.SplitsUTF8Strings
> [  FAILED  ] FormatTest.SupportsCRLF


Repository:
  rC Clang

https://reviews.llvm.org/D53482

Files:
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -38,7 +38,8 @@
 
   std::string format(llvm::StringRef Code,
                      const FormatStyle &Style = getLLVMStyle(),
-                     StatusCheck CheckComplete = SC_ExpectComplete) {
+                     StatusCheck CheckComplete = SC_ExpectComplete,
+                     bool check = true) {
     LLVM_DEBUG(llvm::errs() << "---\n");
     LLVM_DEBUG(llvm::errs() << Code << "\n\n");
     std::vector<tooling::Range> Ranges(1, tooling::Range(0, Code.size()));
@@ -54,6 +55,12 @@
     auto Result = applyAllReplacements(Code, Replaces);
     EXPECT_TRUE(static_cast<bool>(Result));
     LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+    if (check && Status.FormatComplete) {
+      // Do recursive call and check that format of format is valid.
+      LLVM_DEBUG(llvm::errs() << "\ncheck\n\n");
+      auto FormatedResult = format(*Result, Style, SC_ExpectComplete, false);
+      EXPECT_EQ(*Result, FormatedResult);
+    }
     return *Result;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53482.170339.patch
Type: text/x-patch
Size: 1159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181021/cf3420ff/attachment.bin>


More information about the cfe-commits mailing list