2014-09-22 18:41:39 +08:00
|
|
|
#include "ClangTidyTest.h"
|
2015-03-02 19:55:04 +08:00
|
|
|
#include "readability/BracesAroundStatementsCheck.h"
|
2014-09-22 18:41:39 +08:00
|
|
|
#include "readability/NamespaceCommentCheck.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace test {
|
|
|
|
|
2015-03-02 19:55:04 +08:00
|
|
|
using readability::BracesAroundStatementsCheck;
|
2014-09-22 18:41:39 +08:00
|
|
|
using readability::NamespaceCommentCheck;
|
|
|
|
|
|
|
|
TEST(NamespaceCommentCheckTest, Basic) {
|
|
|
|
EXPECT_EQ("namespace i {\n} // namespace i",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace i {\n}"));
|
|
|
|
EXPECT_EQ("namespace {\n} // namespace",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n}"));
|
2016-10-14 16:10:08 +08:00
|
|
|
EXPECT_EQ("namespace i { namespace j {\n} // namespace j\n } // namespace i",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>(
|
|
|
|
"namespace i { namespace j {\n} }"));
|
2014-09-22 18:41:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(NamespaceCommentCheckTest, SingleLineNamespaces) {
|
|
|
|
EXPECT_EQ(
|
|
|
|
"namespace i { namespace j { } }",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace i { namespace j { } }"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(NamespaceCommentCheckTest, CheckExistingComments) {
|
|
|
|
EXPECT_EQ("namespace i { namespace j {\n"
|
|
|
|
"} /* namespace j */ } // namespace i\n"
|
|
|
|
" /* random comment */",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>(
|
|
|
|
"namespace i { namespace j {\n"
|
|
|
|
"} /* namespace j */ } /* random comment */"));
|
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"} // namespace",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n"
|
|
|
|
"} // namespace"));
|
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"} //namespace",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n"
|
|
|
|
"} //namespace"));
|
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"} // anonymous namespace",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n"
|
|
|
|
"} // anonymous namespace"));
|
2014-10-16 23:11:54 +08:00
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"} // Anonymous namespace.",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n"
|
|
|
|
"} // Anonymous namespace."));
|
2016-10-14 16:10:08 +08:00
|
|
|
EXPECT_EQ(
|
|
|
|
"namespace q {\n"
|
|
|
|
"} // namespace q",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace q {\n"
|
|
|
|
"} // anonymous namespace q"));
|
2014-09-22 18:41:39 +08:00
|
|
|
EXPECT_EQ(
|
|
|
|
"namespace My_NameSpace123 {\n"
|
|
|
|
"} // namespace My_NameSpace123",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace My_NameSpace123 {\n"
|
|
|
|
"} // namespace My_NameSpace123"));
|
|
|
|
EXPECT_EQ(
|
|
|
|
"namespace My_NameSpace123 {\n"
|
|
|
|
"} //namespace My_NameSpace123",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace My_NameSpace123 {\n"
|
|
|
|
"} //namespace My_NameSpace123"));
|
|
|
|
EXPECT_EQ("namespace My_NameSpace123 {\n"
|
|
|
|
"} // end namespace My_NameSpace123",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>(
|
|
|
|
"namespace My_NameSpace123 {\n"
|
|
|
|
"} // end namespace My_NameSpace123"));
|
|
|
|
// Understand comments only on the same line.
|
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"} // namespace\n"
|
|
|
|
"// namespace",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n"
|
|
|
|
"}\n"
|
|
|
|
"// namespace"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(NamespaceCommentCheckTest, FixWrongComments) {
|
|
|
|
EXPECT_EQ("namespace i { namespace jJ0_ {\n"
|
|
|
|
"} // namespace jJ0_\n"
|
|
|
|
" } // namespace i\n"
|
|
|
|
" /* random comment */",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>(
|
|
|
|
"namespace i { namespace jJ0_ {\n"
|
|
|
|
"} /* namespace qqq */ } /* random comment */"));
|
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"} // namespace",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n"
|
|
|
|
"} // namespace asdf"));
|
2015-03-05 22:58:03 +08:00
|
|
|
// Remove unknown line comments. These are likely to be an unrecognized form
|
|
|
|
// of a namespace ending comment.
|
2015-03-05 22:56:11 +08:00
|
|
|
EXPECT_EQ("namespace {\n"
|
|
|
|
"} // namespace",
|
|
|
|
runCheckOnCode<NamespaceCommentCheck>("namespace {\n"
|
|
|
|
"} // random text"));
|
2014-09-22 18:41:39 +08:00
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, IfWithComments) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, If) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, IfElseWithShortStatements) {
|
2015-03-31 21:53:03 +08:00
|
|
|
ClangTidyOptions Options;
|
2015-10-06 21:52:51 +08:00
|
|
|
Options.CheckOptions["test-check-0.ShortStatementLines"] = "1";
|
2015-03-31 21:53:03 +08:00
|
|
|
|
|
|
|
EXPECT_EQ("int main() {\n"
|
|
|
|
" if (true) return 1;\n"
|
|
|
|
" if (false) { return -1;\n"
|
|
|
|
" } else if (1 == 2) { return -2;\n"
|
|
|
|
" } else { return -3;\n"
|
|
|
|
"}\n"
|
|
|
|
"}",
|
|
|
|
runCheckOnCode<BracesAroundStatementsCheck>(
|
|
|
|
"int main() {\n"
|
|
|
|
" if (true) return 1;\n"
|
|
|
|
" if (false) return -1;\n"
|
|
|
|
" else if (1 == 2) return -2;\n"
|
|
|
|
" else return -3;\n"
|
|
|
|
"}",
|
|
|
|
nullptr, "input.cc", None, Options));
|
2015-06-05 00:36:58 +08:00
|
|
|
|
|
|
|
// If the last else is an else-if, we also force it.
|
|
|
|
EXPECT_EQ("int main() {\n"
|
|
|
|
" if (false) { return -1;\n"
|
|
|
|
" } else if (1 == 2) { return -2;\n"
|
|
|
|
"}\n"
|
|
|
|
"}",
|
|
|
|
runCheckOnCode<BracesAroundStatementsCheck>(
|
|
|
|
"int main() {\n"
|
|
|
|
" if (false) return -1;\n"
|
|
|
|
" else if (1 == 2) return -2;\n"
|
|
|
|
"}",
|
|
|
|
nullptr, "input.cc", None, Options));
|
2015-03-31 21:53:03 +08:00
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, For) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, ForRange) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, DoWhile) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, While) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, Nested) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}"));
|
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
TEST(BracesAroundStatementsCheckTest, Macros) {
|
2015-03-02 19:55:04 +08:00
|
|
|
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"
|
|
|
|
"}");
|
2015-09-10 01:06:09 +08:00
|
|
|
EXPECT_EQ("#define DO_IT ++i\n"
|
|
|
|
"int i = 0;\n"
|
|
|
|
"int main() {\n"
|
|
|
|
" if (false) {\n"
|
|
|
|
" DO_IT;\n"
|
|
|
|
" } else if (1 == 2) {\n"
|
|
|
|
" DO_IT;\n"
|
|
|
|
" } else {\n"
|
|
|
|
" DO_IT;\n"
|
|
|
|
"}\n"
|
|
|
|
"}",
|
|
|
|
runCheckOnCode<BracesAroundStatementsCheck>("#define DO_IT ++i\n"
|
|
|
|
"int i = 0;\n"
|
|
|
|
"int main() {\n"
|
|
|
|
" if (false)\n"
|
|
|
|
" DO_IT;\n"
|
|
|
|
" else if (1 == 2)\n"
|
|
|
|
" DO_IT;\n"
|
|
|
|
" else\n"
|
|
|
|
" DO_IT;\n"
|
|
|
|
"}"));
|
2015-03-02 19:55:04 +08:00
|
|
|
}
|
|
|
|
|
2016-10-14 16:10:08 +08:00
|
|
|
#define EXPECT_NO_CHANGES_WITH_OPTS(Check, Opts, Code) \
|
|
|
|
EXPECT_EQ(Code, runCheckOnCode<Check>(Code, nullptr, "input.cc", None, Opts))
|
|
|
|
TEST(BracesAroundStatementsCheckTest, ImplicitCastInReturn) {
|
|
|
|
ClangTidyOptions Opts;
|
|
|
|
Opts.CheckOptions["test-check-0.ShortStatementLines"] = "1";
|
|
|
|
|
2017-08-10 20:38:46 +08:00
|
|
|
StringRef Input = "const char *f() {\n"
|
2016-10-14 16:10:08 +08:00
|
|
|
" if (true) return \"\";\n"
|
|
|
|
" return \"abc\";\n"
|
2017-08-10 20:38:46 +08:00
|
|
|
"}\n";
|
|
|
|
EXPECT_NO_CHANGES_WITH_OPTS(BracesAroundStatementsCheck, Opts, Input);
|
|
|
|
EXPECT_EQ("const char *f() {\n"
|
|
|
|
" if (true) { return \"\";\n"
|
|
|
|
"}\n"
|
|
|
|
" return \"abc\";\n"
|
|
|
|
"}\n",
|
|
|
|
runCheckOnCode<BracesAroundStatementsCheck>(Input));
|
2016-10-14 16:10:08 +08:00
|
|
|
}
|
|
|
|
|
2014-09-22 18:41:39 +08:00
|
|
|
} // namespace test
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|