forked from OSchip/llvm-project
[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. llvm-svn: 230947
This commit is contained in:
parent
8384d491d8
commit
37f80456ce
|
@ -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
|
||||
|
|
|
@ -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); };");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue