diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-09-16 17:41:19 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-09-16 17:41:19 +0000 |
commit | eb213cb1cd499a5f53833097c1c795ae4c8f9900 (patch) | |
tree | 491d837abcb368aa458921e05757f3f500436fc4 /clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp | |
parent | 75877443599e32f3959204eadfaf0d9318ec68d5 (diff) | |
download | bcm5719-llvm-eb213cb1cd499a5f53833097c1c795ae4c8f9900.tar.gz bcm5719-llvm-eb213cb1cd499a5f53833097c1c795ae4c8f9900.zip |
[clang-tidy] When emitting header guard fixes bundle all fix-its into one
warning.
Before we would emit two warnings if the header guard was wrong and the comment
on a trailing #endif also needed fixing.
llvm-svn: 217890
Diffstat (limited to 'clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp')
-rw-r--r-- | clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp index 67b3d67de98..dc7db4c95b7 100644 --- a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp @@ -88,9 +88,12 @@ TEST(NamespaceCommentCheckTest, FixWrongComments) { // FIXME: It seems this might be incompatible to dos path. Investigating. #if !defined(_WIN32) -static std::string runHeaderGuardCheck(StringRef Code, const Twine &Filename) { - return test::runCheckOnCode<LLVMHeaderGuardCheck>( - Code, /*Errors=*/nullptr, Filename, std::string("-xc++-header")); +static std::string runHeaderGuardCheck(StringRef Code, const Twine &Filename, + unsigned NumWarnings = 1) { + std::vector<ClangTidyError> Errors; + std::string Result = test::runCheckOnCode<LLVMHeaderGuardCheck>( + Code, &Errors, Filename, std::string("-xc++-header")); + return Errors.size() == NumWarnings ? Result : "invalid error count"; } namespace { @@ -102,9 +105,12 @@ struct WithEndifComment : public LLVMHeaderGuardCheck { } // namespace static std::string runHeaderGuardCheckWithEndif(StringRef Code, - const Twine &Filename) { - return test::runCheckOnCode<WithEndifComment>( - Code, /*Errors=*/nullptr, Filename, std::string("-xc++-header")); + const Twine &Filename, + unsigned NumWarnings = 1) { + std::vector<ClangTidyError> Errors; + std::string Result = test::runCheckOnCode<WithEndifComment>( + Code, &Errors, Filename, std::string("-xc++-header")); + return Errors.size() == NumWarnings ? Result : "invalid error count"; } TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) { @@ -116,7 +122,7 @@ TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) { EXPECT_EQ("#ifndef LLVM_ADT_FOO_H_\n#define LLVM_ADT_FOO_H_\n#endif\n", runHeaderGuardCheck( "#ifndef LLVM_ADT_FOO_H_\n#define LLVM_ADT_FOO_H_\n#endif\n", - "include/llvm/ADT/foo.h")); + "include/llvm/ADT/foo.h", 0)); EXPECT_EQ("#ifndef LLVM_CLANG_C_BAR_H\n#define LLVM_CLANG_C_BAR_H\n\n\n#endif\n", runHeaderGuardCheck("", "./include/clang-c/bar.h")); @@ -157,14 +163,14 @@ TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) { runHeaderGuardCheckWithEndif("#ifndef LLVM_ADT_FOO_H\n#define " "LLVM_ADT_FOO_H\n" "#endif /* LLVM_ADT_FOO_H */\n", - "include/llvm/ADT/foo.h")); + "include/llvm/ADT/foo.h", 0)); EXPECT_EQ("#ifndef LLVM_ADT_FOO_H_\n#define LLVM_ADT_FOO_H_\n#endif " "// LLVM_ADT_FOO_H_\n", runHeaderGuardCheckWithEndif( "#ifndef LLVM_ADT_FOO_H_\n#define " "LLVM_ADT_FOO_H_\n#endif // LLVM_ADT_FOO_H_\n", - "include/llvm/ADT/foo.h")); + "include/llvm/ADT/foo.h", 0)); EXPECT_EQ( "#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif // " @@ -178,14 +184,14 @@ TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) { runHeaderGuardCheckWithEndif("#ifndef LLVM_ADT_FOO_H\n#define " "LLVM_ADT_FOO_H\n#endif \\ \n// " "LLVM_ADT_FOO_H\n", - "include/llvm/ADT/foo.h")); + "include/llvm/ADT/foo.h", 0)); EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif /* " "LLVM_ADT_FOO_H\\ \n FOO */", runHeaderGuardCheckWithEndif( "#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif /* " "LLVM_ADT_FOO_H\\ \n FOO */", - "include/llvm/ADT/foo.h")); + "include/llvm/ADT/foo.h", 0)); } #endif |