This is a bug fix of https://bugs.llvm.org/show_bug.cgi?id=50116
-----current behavior-----
darwin@darwin-ubuntu-04:~/temp$ cat b.cpp
namespace A{ int i; }
namespace B{
int j;
}
darwin@darwin-ubuntu-04:~/temp$ /home/darwin/projects/llvm-project/build/bin/clang-format b.cpp -style="{BasedOnStyle: google, BreakBeforeBraces: Custom, BraceWrapping: {AfterNamespace: true}}"
namespace A
{
int i;
}
namespace B
{
int j;
}-----expected result-----
namespace A
{
int i;
}
namespace B
{
int j;
}First revision only contains the change of the test code. I would like to have someone review the expected result. If it is OK. Then I can fix it.
Here is the output of the test case without fixing yet:
darwin@Darwins-iMac build % /Volumes/silo/Projects/open-source/llvm-project/build/tools/clang/unittests/Format/./FormatTests --gtest_filter=FormatTest.RemovesEmptyLines
Note: Google Test filter = FormatTest.RemovesEmptyLines
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from FormatTest
[ RUN ] FormatTest.RemovesEmptyLines
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:279: Failure
Expected equality of these values:
"namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "namespace N\n{\n\nint i;\n}"
format("namespace N\n" "{\n" "\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:290: Failure
Expected equality of these values:
"/* something */ namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "/* something */ namespace N\n{\n\nint i;\n}"
format("/* something */ namespace N {\n" "\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "/* something */ namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
/* something */ namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:302: Failure
Expected equality of these values:
"inline namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "inline namespace N\n{\n\nint i;\n}"
format("inline namespace N\n" "{\n" "\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "inline namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
inline namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:313: Failure
Expected equality of these values:
"/* something */ inline namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "/* something */ inline namespace N\n{\n\nint i;\n}"
format("/* something */ inline namespace N\n" "{\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "/* something */ inline namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
/* something */ inline namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:324: Failure
Expected equality of these values:
"export namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "export namespace N\n{\n\nint i;\n}"
format("export namespace N\n" "{\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "export namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
export namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:345: Failure
Expected equality of these values:
"namespace a\n" "{\n" "namespace b\n" "{\n" "\n" "class AA {};\n" "\n" "} // namespace b\n" "} // namespace a\n"
Which is: "namespace a\n{\nnamespace b\n{\n\nclass AA {};\n\n} // namespace b\n} // namespace a\n"
format("namespace a\n" "{\n" "namespace b\n" "{\n" "\n" "\n" "class AA {};\n" "\n" "\n" "}\n" "}\n", GoogleWrapBraceAfterNamespace)
Which is: "namespace a\n{\nnamespace b\n{\nclass AA {};\n\n} // namespace b\n} // namespace a\n"
With diff:
@@ -3,5 @@
namespace b
{
-
class AA {};
[ FAILED ] FormatTest.RemovesEmptyLines (41 ms)
[----------] 1 test from FormatTest (41 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (41 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] FormatTest.RemovesEmptyLines
1 FAILED TEST
darwin@Darwins-iMac build %After the fix, all test cases have passed:
darwin@Darwins-iMac build % cmake --build . -j24 -t check-clang-unit ; echo '\007' [ 0%] Built target hmaptool ... [100%] Built target ClangUnitTests [100%] Running lit suite /Volumes/silo/Projects/open-source/llvm-project/clang/test/Unit Testing Time: 245.60s Skipped: 3 Passed : 14105 [100%] Built target check-clang-unit
Nit:I do think at some point we need to have some sort of option for controlling these empty lines,
` EmptyLine: AfterNamespace: 1 BeforeAccessModifier: 1 AfterAccessModifier: 1 BetweenFunctions: 1 ... `