From 208faaaa290319b7eecab112e7922f88097c3ebe Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Wed, 20 Aug 2014 16:01:42 +0000 Subject: [clang-tidy] Allow /**/ comments on #endifs when checking header guards. Turning block comments into line comments just creates unecessary churn. llvm-svn: 216072 --- .../unittests/clang-tidy/LLVMModuleTest.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp') diff --git a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp index 5423169caba..ce4ca641afc 100644 --- a/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp +++ b/clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp @@ -93,6 +93,18 @@ static std::string runHeaderGuardCheck(StringRef Code, const Twine &Filename) { Code, /*Errors=*/nullptr, Filename, std::string("-xc++-header")); } +namespace { +struct WithEndifComment : public LLVMHeaderGuardCheck { + bool shouldSuggestEndifComment(StringRef Filename) override { return true; } +}; +} // namespace + +static std::string runHeaderGuardCheckWithEndif(StringRef Code, + const Twine &Filename) { + return test::runCheckOnCode( + Code, /*Errors=*/nullptr, Filename, std::string("-xc++-header")); +} + TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) { EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif\n", runHeaderGuardCheck("#ifndef FOO\n#define FOO\n#endif\n", @@ -126,6 +138,24 @@ TEST(LLVMHeaderGuardCheckTest, FixHeaderGuards) { runHeaderGuardCheck( "int foo;\n#ifndef FOOLOLO\n#define FOOLOLO\n#endif\n", "include/clang/bar.h")); + + EXPECT_EQ("#ifndef LLVM_ADT_FOO_H\n#define LLVM_ADT_FOO_H\n#endif " + " // LLVM_ADT_FOO_H\n", + runHeaderGuardCheckWithEndif("#ifndef FOO\n#define FOO\n#endif\n", + "include/llvm/ADT/foo.h")); + + 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_H\n", + "include/llvm/ADT/foo.h")); + + 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")); } #endif -- cgit v1.2.3