[clang-tools-extra] r230947 - [clang-tidy] Organized clang-tidy unit tests. NFC.

Alexander Kornienko alexfh at google.com
Mon Mar 2 03:55:05 PST 2015


Author: alexfh
Date: Mon Mar  2 05:55:04 2015
New Revision: 230947

URL: http://llvm.org/viewvc/llvm-project?rev=230947&view=rev
Log:
[clang-tidy] Organized clang-tidy unit tests. NFC.

  * Moved unit tests for BracesAroundStatementsCheck to
    ReadabilityModuleTest.cpp.
  * Moved EXPECT_NO_CHANGES macro to ClangTidyTest.h to avoid defining it three
    times.


Modified:
    clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
    clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp
    clang-tools-extra/trunk/unittests/clang-tidy/MiscModuleTest.cpp
    clang-tools-extra/trunk/unittests/clang-tidy/ReadabilityModuleTest.cpp

Modified: clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h?rev=230947&r1=230946&r2=230947&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h Mon Mar  2 05:55:04 2015
@@ -78,6 +78,9 @@ std::string runCheckOnCode(StringRef Cod
   return tooling::applyAllReplacements(Code, Fixes);
 }
 
+#define EXPECT_NO_CHANGES(Check, Code)                                         \
+  EXPECT_EQ(Code, runCheckOnCode<Check>(Code))
+
 } // namespace test
 } // namespace tidy
 } // namespace clang

Modified: clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp?rev=230947&r1=230946&r2=230947&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp Mon Mar  2 05:55:04 2015
@@ -7,9 +7,6 @@ namespace clang {
 namespace tidy {
 namespace test {
 
-#define EXPECT_NO_CHANGES(Check, Code)                                         \
-  EXPECT_EQ(Code, runCheckOnCode<Check>(Code))
-
 TEST(ExplicitConstructorCheckTest, SingleArgumentConstructorsOnly) {
   EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(); };");
   EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(int i, int j); };");

Modified: clang-tools-extra/trunk/unittests/clang-tidy/MiscModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/MiscModuleTest.cpp?rev=230947&r1=230946&r2=230947&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/MiscModuleTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/MiscModuleTest.cpp Mon Mar  2 05:55:04 2015
@@ -1,18 +1,11 @@
 #include "ClangTidyTest.h"
 #include "misc/ArgumentCommentCheck.h"
-#include "readability/BracesAroundStatementsCheck.h"
 #include "gtest/gtest.h"
 
 namespace clang {
 namespace tidy {
-
-using readability::BracesAroundStatementsCheck;
-
 namespace test {
 
-#define EXPECT_NO_CHANGES(Check, Code)                                         \
-  EXPECT_EQ(Code, runCheckOnCode<Check>(Code))
-
 TEST(ArgumentCommentCheckTest, CorrectComments) {
   EXPECT_NO_CHANGES(ArgumentCommentCheck,
                     "void f(int x, int y); void g() { f(/*x=*/0, /*y=*/0); }");
@@ -39,334 +32,6 @@ TEST(ArgumentCommentCheckTest, OtherEdit
                     "void f(int xxx, int yyy); void g() { f(/*xxy=*/0, 0); }");
 }
 
-TEST(BracesAroundStatementsCheck, IfWithComments) {
-  EXPECT_EQ("int main() {\n"
-            "  if (false /*dummy token*/) {\n"
-            "    // comment\n"
-            "    return -1; /**/\n"
-            "}\n"
-            "  if (false) {\n"
-            "    return -1; // comment\n"
-            "}\n"
-            "  if (false) {\n"
-            "    return -1; \n"
-            "}/* multi-line \n comment */\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  if (false /*dummy token*/)\n"
-                "    // comment\n"
-                "    return -1; /**/\n"
-                "  if (false)\n"
-                "    return -1; // comment\n"
-                "  if (false)\n"
-                "    return -1; /* multi-line \n comment */\n"
-                "}"));
-  EXPECT_EQ("int main() {\n"
-            "  if (false /*dummy token*/) {\n"
-            "    // comment\n"
-            "    return -1 /**/ ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  if (false /*dummy token*/)\n"
-                "    // comment\n"
-                "    return -1 /**/ ;\n"
-                "}"));
-}
-
-TEST(BracesAroundStatementsCheck, If) {
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
-                                                 "  if (false) {\n"
-                                                 "    return -1;\n"
-                                                 "  }\n"
-                                                 "}");
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
-                                                 "  if (auto Cond = false) {\n"
-                                                 "    return -1;\n"
-                                                 "  }\n"
-                                                 "}");
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
-                                                 "  if (false) {\n"
-                                                 "    return -1;\n"
-                                                 "  } else {\n"
-                                                 "    return -2;\n"
-                                                 "  }\n"
-                                                 "}");
-  EXPECT_EQ("int main() {\n"
-            "  if (false) {\n"
-            "    return -1;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  if (false)\n"
-                                                        "    return -1;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  if (auto Cond = false /**/ ) {\n"
-            "    return -1;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  if (auto Cond = false /**/ )\n"
-                "    return -1;\n"
-                "}"));
-  // FIXME: Consider adding braces before EMPTY_MACRO and after the statement.
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck,
-                    "#define EMPTY_MACRO\n"
-                    "int main() {\n"
-                    "  if (auto Cond = false EMPTY_MACRO /**/ ) EMPTY_MACRO\n"
-                    "    return -1;\n"
-                    "}");
-  EXPECT_EQ("int main() {\n"
-            "  if (true) { return -1/**/ ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  if (true) return -1/**/ ;\n"
-                "}"));
-  EXPECT_EQ("int main() {\n"
-            "  if (false) {\n"
-            "    return -1;\n"
-            "  } else {\n"
-            "    return -2;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  if (false)\n"
-                                                        "    return -1;\n"
-                                                        "  else\n"
-                                                        "    return -2;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  if (false) {\n"
-            "    return -1;\n"
-            "  } else if (1 == 2) {\n"
-            "    return -2;\n"
-            "  } else {\n"
-            "    return -3;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  if (false)\n"
-                                                        "    return -1;\n"
-                                                        "  else if (1 == 2)\n"
-                                                        "    return -2;\n"
-                                                        "  else\n"
-                                                        "    return -3;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  if (false) {\n"
-            "    return -1;\n"
-            "  } else if (1 == 2) {\n"
-            "    return -2;\n"
-            "  } else {\n"
-            "    return -3;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  if (false)\n"
-                                                        "    return -1;\n"
-                                                        "  else if (1 == 2) {\n"
-                                                        "    return -2;\n"
-                                                        "  } else\n"
-                                                        "    return -3;\n"
-                                                        "}"));
-}
-
-TEST(BracesAroundStatementsCheck, For) {
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
-                                                 "  for (;;) {\n"
-                                                 "    ;\n"
-                                                 "  }\n"
-                                                 "}");
-  EXPECT_EQ("int main() {\n"
-            "  for (;;) {\n"
-            "    ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  for (;;)\n"
-                                                        "    ;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  for (;;) {\n"
-            "    /**/ ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  for (;;)\n"
-                                                        "    /**/ ;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  for (;;) {\n"
-            "    return -1 /**/ ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  for (;;)\n"
-                                                        "    return -1 /**/ ;\n"
-                                                        "}"));
-}
-
-TEST(BracesAroundStatementsCheck, ForRange) {
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
-                                                 "  int arr[4];\n"
-                                                 "  for (int i : arr) {\n"
-                                                 "    ;\n"
-                                                 "  }\n"
-                                                 "}");
-  EXPECT_EQ("int main() {\n"
-            "  int arr[4];\n"
-            "  for (int i : arr) {\n"
-            "    ;\n"
-            "}\n"
-            "  for (int i : arr) {\n"
-            "    return -1 ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  int arr[4];\n"
-                                                        "  for (int i : arr)\n"
-                                                        "    ;\n"
-                                                        "  for (int i : arr)\n"
-                                                        "    return -1 ;\n"
-                                                        "}"));
-}
-
-TEST(BracesAroundStatementsCheck, DoWhile) {
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
-                                                 "  do {\n"
-                                                 "    ;\n"
-                                                 "  } while (false);\n"
-                                                 "}");
-  EXPECT_EQ("int main() {\n"
-            "  do {\n"
-            "    ;\n"
-            "  } while (false);\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  do\n"
-                                                        "    ;\n"
-                                                        "  while (false);\n"
-                                                        "}"));
-}
-
-TEST(BracesAroundStatementsCheck, While) {
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
-                                                 "  while (false) {\n"
-                                                 "    ;\n"
-                                                 "  }\n"
-                                                 "}");
-  EXPECT_EQ("int main() {\n"
-            "  while (false) {\n"
-            "    ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  while (false)\n"
-                                                        "    ;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  while (auto Cond = false) {\n"
-            "    ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  while (auto Cond = false)\n"
-                "    ;\n"
-                "}"));
-  EXPECT_EQ("int main() {\n"
-            "  while (false /*dummy token*/) {\n"
-            "    ;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  while (false /*dummy token*/)\n"
-                "    ;\n"
-                "}"));
-  EXPECT_EQ("int main() {\n"
-            "  while (false) {\n"
-            "    break;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  while (false)\n"
-                                                        "    break;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  while (false) {\n"
-            "    break /**/;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  while (false)\n"
-                                                        "    break /**/;\n"
-                                                        "}"));
-  EXPECT_EQ("int main() {\n"
-            "  while (false) {\n"
-            "    /**/;\n"
-            "}\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                        "  while (false)\n"
-                                                        "    /**/;\n"
-                                                        "}"));
-}
-
-TEST(BracesAroundStatementsCheck, Nested) {
-  EXPECT_EQ("int main() {\n"
-            "  do { if (true) {}} while (false);\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  do if (true) {}while (false);\n"
-                "}"));
-  EXPECT_EQ("int main() {\n"
-            "  do { if (true) {}} while (false);\n"
-            "}",
-            runCheckOnCode<BracesAroundStatementsCheck>(
-                "int main() {\n"
-                "  do if (true) {}while (false);\n"
-                "}"));
-  EXPECT_EQ(
-      "int main() {\n"
-      "  if (true) {\n"
-      "    // comment\n"
-      "    if (false) {\n"
-      "      // comment\n"
-      "      /**/ ; // comment\n"
-      "    }\n"
-      "}\n"
-      "}",
-      runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
-                                                  "  if (true)\n"
-                                                  "    // comment\n"
-                                                  "    if (false) {\n"
-                                                  "      // comment\n"
-                                                  "      /**/ ; // comment\n"
-                                                  "    }\n"
-                                                  "}"));
-}
-
-TEST(BracesAroundStatementsCheck, Macros) {
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck,
-                    "#define IF(COND) if (COND) return -1;\n"
-                    "int main() {\n"
-                    "  IF(false)\n"
-                    "}");
-  EXPECT_NO_CHANGES(BracesAroundStatementsCheck,
-                    "#define FOR(COND) for (COND) return -1;\n"
-                    "int main() {\n"
-                    "  FOR(;;)\n"
-                    "}");
-}
-
 } // namespace test
 } // namespace tidy
 } // namespace clang

Modified: clang-tools-extra/trunk/unittests/clang-tidy/ReadabilityModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ReadabilityModuleTest.cpp?rev=230947&r1=230946&r2=230947&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/ReadabilityModuleTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/ReadabilityModuleTest.cpp Mon Mar  2 05:55:04 2015
@@ -1,4 +1,5 @@
 #include "ClangTidyTest.h"
+#include "readability/BracesAroundStatementsCheck.h"
 #include "readability/NamespaceCommentCheck.h"
 #include "gtest/gtest.h"
 
@@ -6,6 +7,7 @@ namespace clang {
 namespace tidy {
 namespace test {
 
+using readability::BracesAroundStatementsCheck;
 using readability::NamespaceCommentCheck;
 
 TEST(NamespaceCommentCheckTest, Basic) {
@@ -94,6 +96,334 @@ TEST(NamespaceCommentCheckTest, FixWrong
                                                   "} // namespace asdf"));
 }
 
+TEST(BracesAroundStatementsCheck, IfWithComments) {
+  EXPECT_EQ("int main() {\n"
+            "  if (false /*dummy token*/) {\n"
+            "    // comment\n"
+            "    return -1; /**/\n"
+            "}\n"
+            "  if (false) {\n"
+            "    return -1; // comment\n"
+            "}\n"
+            "  if (false) {\n"
+            "    return -1; \n"
+            "}/* multi-line \n comment */\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  if (false /*dummy token*/)\n"
+                "    // comment\n"
+                "    return -1; /**/\n"
+                "  if (false)\n"
+                "    return -1; // comment\n"
+                "  if (false)\n"
+                "    return -1; /* multi-line \n comment */\n"
+                "}"));
+  EXPECT_EQ("int main() {\n"
+            "  if (false /*dummy token*/) {\n"
+            "    // comment\n"
+            "    return -1 /**/ ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  if (false /*dummy token*/)\n"
+                "    // comment\n"
+                "    return -1 /**/ ;\n"
+                "}"));
+}
+
+TEST(BracesAroundStatementsCheck, If) {
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
+                                                 "  if (false) {\n"
+                                                 "    return -1;\n"
+                                                 "  }\n"
+                                                 "}");
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
+                                                 "  if (auto Cond = false) {\n"
+                                                 "    return -1;\n"
+                                                 "  }\n"
+                                                 "}");
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
+                                                 "  if (false) {\n"
+                                                 "    return -1;\n"
+                                                 "  } else {\n"
+                                                 "    return -2;\n"
+                                                 "  }\n"
+                                                 "}");
+  EXPECT_EQ("int main() {\n"
+            "  if (false) {\n"
+            "    return -1;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  if (false)\n"
+                                                        "    return -1;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  if (auto Cond = false /**/ ) {\n"
+            "    return -1;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  if (auto Cond = false /**/ )\n"
+                "    return -1;\n"
+                "}"));
+  // FIXME: Consider adding braces before EMPTY_MACRO and after the statement.
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck,
+                    "#define EMPTY_MACRO\n"
+                    "int main() {\n"
+                    "  if (auto Cond = false EMPTY_MACRO /**/ ) EMPTY_MACRO\n"
+                    "    return -1;\n"
+                    "}");
+  EXPECT_EQ("int main() {\n"
+            "  if (true) { return -1/**/ ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  if (true) return -1/**/ ;\n"
+                "}"));
+  EXPECT_EQ("int main() {\n"
+            "  if (false) {\n"
+            "    return -1;\n"
+            "  } else {\n"
+            "    return -2;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  if (false)\n"
+                                                        "    return -1;\n"
+                                                        "  else\n"
+                                                        "    return -2;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  if (false) {\n"
+            "    return -1;\n"
+            "  } else if (1 == 2) {\n"
+            "    return -2;\n"
+            "  } else {\n"
+            "    return -3;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  if (false)\n"
+                                                        "    return -1;\n"
+                                                        "  else if (1 == 2)\n"
+                                                        "    return -2;\n"
+                                                        "  else\n"
+                                                        "    return -3;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  if (false) {\n"
+            "    return -1;\n"
+            "  } else if (1 == 2) {\n"
+            "    return -2;\n"
+            "  } else {\n"
+            "    return -3;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  if (false)\n"
+                                                        "    return -1;\n"
+                                                        "  else if (1 == 2) {\n"
+                                                        "    return -2;\n"
+                                                        "  } else\n"
+                                                        "    return -3;\n"
+                                                        "}"));
+}
+
+TEST(BracesAroundStatementsCheck, For) {
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
+                                                 "  for (;;) {\n"
+                                                 "    ;\n"
+                                                 "  }\n"
+                                                 "}");
+  EXPECT_EQ("int main() {\n"
+            "  for (;;) {\n"
+            "    ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  for (;;)\n"
+                                                        "    ;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  for (;;) {\n"
+            "    /**/ ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  for (;;)\n"
+                                                        "    /**/ ;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  for (;;) {\n"
+            "    return -1 /**/ ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  for (;;)\n"
+                                                        "    return -1 /**/ ;\n"
+                                                        "}"));
+}
+
+TEST(BracesAroundStatementsCheck, ForRange) {
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
+                                                 "  int arr[4];\n"
+                                                 "  for (int i : arr) {\n"
+                                                 "    ;\n"
+                                                 "  }\n"
+                                                 "}");
+  EXPECT_EQ("int main() {\n"
+            "  int arr[4];\n"
+            "  for (int i : arr) {\n"
+            "    ;\n"
+            "}\n"
+            "  for (int i : arr) {\n"
+            "    return -1 ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  int arr[4];\n"
+                                                        "  for (int i : arr)\n"
+                                                        "    ;\n"
+                                                        "  for (int i : arr)\n"
+                                                        "    return -1 ;\n"
+                                                        "}"));
+}
+
+TEST(BracesAroundStatementsCheck, DoWhile) {
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
+                                                 "  do {\n"
+                                                 "    ;\n"
+                                                 "  } while (false);\n"
+                                                 "}");
+  EXPECT_EQ("int main() {\n"
+            "  do {\n"
+            "    ;\n"
+            "  } while (false);\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  do\n"
+                                                        "    ;\n"
+                                                        "  while (false);\n"
+                                                        "}"));
+}
+
+TEST(BracesAroundStatementsCheck, While) {
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck, "int main() {\n"
+                                                 "  while (false) {\n"
+                                                 "    ;\n"
+                                                 "  }\n"
+                                                 "}");
+  EXPECT_EQ("int main() {\n"
+            "  while (false) {\n"
+            "    ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  while (false)\n"
+                                                        "    ;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  while (auto Cond = false) {\n"
+            "    ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  while (auto Cond = false)\n"
+                "    ;\n"
+                "}"));
+  EXPECT_EQ("int main() {\n"
+            "  while (false /*dummy token*/) {\n"
+            "    ;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  while (false /*dummy token*/)\n"
+                "    ;\n"
+                "}"));
+  EXPECT_EQ("int main() {\n"
+            "  while (false) {\n"
+            "    break;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  while (false)\n"
+                                                        "    break;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  while (false) {\n"
+            "    break /**/;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  while (false)\n"
+                                                        "    break /**/;\n"
+                                                        "}"));
+  EXPECT_EQ("int main() {\n"
+            "  while (false) {\n"
+            "    /**/;\n"
+            "}\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                        "  while (false)\n"
+                                                        "    /**/;\n"
+                                                        "}"));
+}
+
+TEST(BracesAroundStatementsCheck, Nested) {
+  EXPECT_EQ("int main() {\n"
+            "  do { if (true) {}} while (false);\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  do if (true) {}while (false);\n"
+                "}"));
+  EXPECT_EQ("int main() {\n"
+            "  do { if (true) {}} while (false);\n"
+            "}",
+            runCheckOnCode<BracesAroundStatementsCheck>(
+                "int main() {\n"
+                "  do if (true) {}while (false);\n"
+                "}"));
+  EXPECT_EQ(
+      "int main() {\n"
+      "  if (true) {\n"
+      "    // comment\n"
+      "    if (false) {\n"
+      "      // comment\n"
+      "      /**/ ; // comment\n"
+      "    }\n"
+      "}\n"
+      "}",
+      runCheckOnCode<BracesAroundStatementsCheck>("int main() {\n"
+                                                  "  if (true)\n"
+                                                  "    // comment\n"
+                                                  "    if (false) {\n"
+                                                  "      // comment\n"
+                                                  "      /**/ ; // comment\n"
+                                                  "    }\n"
+                                                  "}"));
+}
+
+TEST(BracesAroundStatementsCheck, Macros) {
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck,
+                    "#define IF(COND) if (COND) return -1;\n"
+                    "int main() {\n"
+                    "  IF(false)\n"
+                    "}");
+  EXPECT_NO_CHANGES(BracesAroundStatementsCheck,
+                    "#define FOR(COND) for (COND) return -1;\n"
+                    "int main() {\n"
+                    "  FOR(;;)\n"
+                    "}");
+}
+
 } // namespace test
 } // namespace tidy
 } // namespace clang





More information about the cfe-commits mailing list