[clang-tidy] Organized clang-tidy unit tests. NFC.
authorAlexander Kornienko <alexfh@google.com>
Mon, 2 Mar 2015 11:55:04 +0000 (11:55 +0000)
committerAlexander Kornienko <alexfh@google.com>
Mon, 2 Mar 2015 11:55:04 +0000 (11:55 +0000)
  * Moved unit tests for BracesAroundStatementsCheck to
    ReadabilityModuleTest.cpp.
  * Moved EXPECT_NO_CHANGES macro to ClangTidyTest.h to avoid defining it three
    times.

llvm-svn: 230947

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

index 54a38c4..a90d557 100644 (file)
@@ -78,6 +78,9 @@ std::string runCheckOnCode(StringRef Code,
   return tooling::applyAllReplacements(Code, Fixes);
 }
 
+#define EXPECT_NO_CHANGES(Check, Code)                                         \
+  EXPECT_EQ(Code, runCheckOnCode<Check>(Code))
+
 } // namespace test
 } // namespace tidy
 } // namespace clang
index 0b19af2..4ddf8d9 100644 (file)
@@ -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); };");
index f8419ab..2e1fbba 100644 (file)
@@ -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, OtherEditDistanceBelowThreshold) {
                     "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
index 2d51949..8c7007c 100644 (file)
@@ -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, FixWrongComments) {
                                                   "} // 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