[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

Konrad Wilhelm Kleine via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 21 03:13:44 PDT 2022


kwk added a comment.

In the current state, some tests in `SortIncludesTest.SupportAtImportLines` are failing.

This is strange, because I've tested it with this `.clang-format` file:

  BasedOnStyle: LLVM
  IncludeBlocks: Regroup



NOTE: for each test I've change the `Regroup` to `Preserve` respectively`.

This was the input file: **`foo.c`**:

  #import "b.h"
  @import Foundation;
  @import foundation;
  #import "c.h"
  #import <d/e.h>
  @import Base;
  #import "foo.hpp"
  
  @import aaaa;
  #import <f/g.h>
  @import AAAA;
  #include "foobar"
  #import "foo.h"

And this was the command to test it by hand:

  $ ninja clang-format && ./bin/clang-format --style=file foo.c

The output of this manual invocation looks correct to me so I've pasted
it into the test file and escaped the quotes. But there it fails with:

  $ ninja clang-format && ninja FormatTests &&
  ./tools/clang/unittests/Format/FormatTests
  --gtest_filter=SortIncludesTest.SupportAtImportLines
  
  [2/2] Linking CXX executable tools/clang/unittests/Format/FormatTests
  Note: Google Test filter = SortIncludesTest.SupportAtImportLines
  [==========] Running 1 test from 1 test suite.
  [----------] Global test environment set-up.
  [----------] 1 test from SortIncludesTest
  [ RUN      ] SortIncludesTest.SupportAtImportLines
  /home/fedora/llvm-project/clang/unittests/Format/SortIncludesTest.cpp:33:
  Failure
  Expected equality of these values:
    ExpectedNumRanges
      Which is: 1
    Replaces.size()
      Which is: 2
  /home/fedora/llvm-project/clang/unittests/Format/SortIncludesTest.cpp:555:
  Failure
  Expected equality of these values:
    "#import \"foo.hpp\"\n" "\n" "#import \"b.h\"\n" "#import \"c.h\"\n"
  "#import \"foo.h\"\n" "#include \"foobar\"\n" "\n" "#import <d/e.h>\n"
  "#import <f/g.h>\n" "\n" "@import AAAA;\n" "@import aaaa;\n" "@import
  Base;\n" "@import Foundation;\n" "@import foundation;\n"
      Which is: "#import \"foo.hpp\"\n\n#import \"b.h\"\n#import
  \"c.h\"\n#import \"foo.h\"\n#include \"foobar\"\n\n#import
  <d/e.h>\n#import <f/g.h>\n\n at import AAAA;\n at import aaaa;\n at import
  Base;\n at import Foundation;\n at import foundation;\n"
    sort("#import \"b.h\"\n" "@import Foundation;\n" "@import
  foundation;\n" "#import \"c.h\"\n" "#import <d/e.h>\n" "@import Base;\n"
  "#import \"foo.hpp\"\n" "\n" "@import aaaa;\n" "#import <f/g.h>\n"
  "@import AAAA;\n" "#include \"foobar\"\n" "#import \"foo.h\"\n",
  "foo.c")
      Which is: "#import \"foo.hpp\"\n\n#import \"b.h\"\n#import
  \"c.h\"\n#import \"foo.h\"\n#include \"foobar\"\n\n#import
  <d/e.h>\n#import <f/g.h>\n\n at import AAAA;\n at import Base;\n at import
  Foundation;\n at import aaaa;\n at import foundation;\n"
  With diff:
  @@ -10,6 +10,6 @@
  
   @import AAAA;
  - at import aaaa;
   @import Base;
   @import Foundation;
  + at import aaaa;
   @import foundation;\n
  
  [  FAILED  ] SortIncludesTest.SupportAtImportLines (16 ms)
  [----------] 1 test from SortIncludesTest (16 ms total)
  
  [----------] Global test environment tear-down
  [==========] 1 test from 1 test suite ran. (16 ms total)
  [  PASSED  ] 0 tests.
  [  FAILED  ] 1 test, listed below:
  [  FAILED  ] SortIncludesTest.SupportAtImportLines

What's bothering me is that inside the tests there seems to be a
different sorting for upper- and lower-case includes. But maybe I'm
mistaken.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370



More information about the cfe-commits mailing list