[PATCH] D151145: Add disabled unittest reproducing TextProto formatting issue.

Ben J via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 22 13:11:26 PDT 2023


Icantjuddle created this revision.
Icantjuddle added a reviewer: clang-format.
Herald added a project: All.
Icantjuddle requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Github Issue <https://github.com/llvm/llvm-project/issues/62871>

Basically adding an empty `TextProto` section causes the formatting of `TextProto` raw strings to change and spaces to be added after the `: `. 
This diff adds a test that reproduces this issus.
It is currently disabled as it is failing, here is the output:

  ❯ build/tools/clang/unittests/Format/FormatTests --gtest_filter='FormatTestRawStrings.DISABLED*' --gtest_also_run_disabled_tests
  Note: Google Test filter = FormatTestRawStrings.DISABLED*
  [==========] Running 1 test from 1 test suite.
  [----------] Global test environment set-up.
  [----------] 1 test from FormatTestRawStrings
  [ RUN      ] FormatTestRawStrings.DISABLED_FormatsCorrectlyWhenTextProtoIsInOwnSection
  /home/bjudd/code/llvm-project/clang/unittests/Format/FormatTestRawStrings.cpp:134: Failure
  Expected equality of these values:
    Expected
      Which is: "\nt = R\"pb(item: 1)pb\";"
    Actual
      Which is: "\nt = R\"pb(item : 1)pb\";"
  With diff:
  @@ -1,2 +1,2 @@
  
  -t = R\"pb(item: 1)pb\";
  +t = R\"pb(item : 1)pb\";
  
  [  FAILED  ] FormatTestRawStrings.DISABLED_FormatsCorrectlyWhenTextProtoIsInOwnSection (7 ms)
  [----------] 1 test from FormatTestRawStrings (7 ms total)
  
  [----------] Global test environment tear-down
  [==========] 1 test from 1 test suite ran. (7 ms total)
  [  PASSED  ] 0 tests.
  [  FAILED  ] 1 test, listed below:
  [  FAILED  ] FormatTestRawStrings.DISABLED_FormatsCorrectlyWhenTextProtoIsInOwnSection
  
   1 FAILED TEST


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151145

Files:
  clang/unittests/Format/FormatTestRawStrings.cpp


Index: clang/unittests/Format/FormatTestRawStrings.cpp
===================================================================
--- clang/unittests/Format/FormatTestRawStrings.cpp
+++ clang/unittests/Format/FormatTestRawStrings.cpp
@@ -75,6 +75,31 @@
     return Style;
   }

+  FormatStyle getRawStringPbStyleSeparateSection() {
+    constexpr const char *FormatStr = R"format(---
+BasedOnStyle: LLVM
+ColumnLimit: 40
+RawStringFormats:
+  - Language: TextProto
+    Delimiters:
+      - 'pb'
+    BasedOnStyle: google
+---
+Language: TextProto
+# Don't set any options.
+...
+)format";
+    llvm::MemoryBufferRef ConfigBuffer(FormatStr, "ClangFormatConfig");
+    FormatStyle Style = {};
+    Style.Language = FormatStyle::LK_Cpp;
+    if (auto Err = parseConfiguration(ConfigBuffer, &Style)) {
+      llvm::dbgs() << Err.value();
+      llvm::dbgs() << Err.message();
+      assert(Err);
+    }
+    return Style;
+  }
+
   FormatStyle getRawStringLLVMCppStyleBasedOn(std::string BasedOnStyle) {
     FormatStyle Style = getLLVMStyle();
     Style.RawStringFormats = {
@@ -164,6 +189,18 @@
                    getRawStringPbStyleWithColumns(40)));
 }

+// Currently a bug in how configs are processed:
+// See: https://github.com/llvm/llvm-project/issues/62871
+TEST_F(FormatTestRawStrings,
+       DISABLED_FormatsCorrectlyWhenTextProtoIsInOwnSection) {
+  // TextProto formatting works when in a RawString.
+  expect_eq(R"test(
+t = R"pb(item: 1)pb";)test",
+            format(R"test(
+t = R"pb(item:1)pb";)test",
+                   getRawStringPbStyleSeparateSection()));
+}
+
 TEST_F(FormatTestRawStrings, RespectsClangFormatOff) {
   expect_eq(R"test(
 // clang-format off


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151145.524442.patch
Type: text/x-patch
Size: 1678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230522/2d515f97/attachment.bin>


More information about the cfe-commits mailing list