Index: clang-tidy/google/CMakeLists.txt =================================================================== --- clang-tidy/google/CMakeLists.txt +++ clang-tidy/google/CMakeLists.txt @@ -20,5 +20,5 @@ clangBasic clangLex clangTidy - clangTidyReadability + clangTidyReadabilityModule ) Index: clang-tidy/google/GoogleTidyModule.cpp =================================================================== --- clang-tidy/google/GoogleTidyModule.cpp +++ clang-tidy/google/GoogleTidyModule.cpp @@ -22,7 +22,9 @@ #include "UnnamedNamespaceInHeaderCheck.h" #include "UsingNamespaceDirectiveCheck.h" #include "../readability/BracesAroundStatementsCheck.h" +#include "../readability/FunctionSize.h" #include "../readability/NamespaceCommentCheck.h" +#include "../readability/RedundantSmartptrGet.h" using namespace clang::ast_matchers; @@ -54,10 +56,14 @@ "google-readability-function"); CheckFactories.registerCheck( "google-readability-todo"); - CheckFactories.registerCheck( - "google-readability-namespace-comments"); CheckFactories.registerCheck( "google-readability-braces-around-statements"); + CheckFactories.registerCheck( + "google-readability-function-size"); + CheckFactories.registerCheck( + "google-readability-namespace-comments"); + CheckFactories.registerCheck( + "google-readability-redundant-smartptr-get"); } ClangTidyOptions getModuleOptions() override { @@ -65,6 +71,7 @@ auto &Opts = Options.CheckOptions; Opts["google-readability-braces-around-statements.ShortStatementLines"] = "1"; + Opts["google-readability-function-size.StatementThreshold"] = "800"; Opts["google-readability-namespace-comments.ShortNamespaceLines"] = "1"; Opts["google-readability-namespace-comments.SpacesBeforeComments"] = "2"; return Options; Index: clang-tidy/llvm/CMakeLists.txt =================================================================== --- clang-tidy/llvm/CMakeLists.txt +++ clang-tidy/llvm/CMakeLists.txt @@ -12,7 +12,7 @@ clangBasic clangLex clangTidy - clangTidyReadability + clangTidyReadabilityModule clangTidyUtils clangTooling ) Index: clang-tidy/misc/CMakeLists.txt =================================================================== --- clang-tidy/misc/CMakeLists.txt +++ clang-tidy/misc/CMakeLists.txt @@ -15,6 +15,4 @@ clangBasic clangLex clangTidy - # Some readability checks are currently registered in the misc module. - clangTidyReadability ) Index: clang-tidy/misc/MiscTidyModule.cpp =================================================================== --- clang-tidy/misc/MiscTidyModule.cpp +++ clang-tidy/misc/MiscTidyModule.cpp @@ -10,11 +10,6 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -// FIXME: Figure out if we want to create a separate module for readability -// checks instead of registering them here. -#include "../readability/BracesAroundStatementsCheck.h" -#include "../readability/FunctionSize.h" -#include "../readability/RedundantSmartptrGet.h" #include "ArgumentCommentCheck.h" #include "BoolPointerImplicitConversion.h" #include "SwappedArgumentsCheck.h" @@ -31,12 +26,6 @@ CheckFactories.registerCheck("misc-argument-comment"); CheckFactories.registerCheck( "misc-bool-pointer-implicit-conversion"); - CheckFactories.registerCheck( - "misc-braces-around-statements"); - CheckFactories.registerCheck( - "misc-function-size"); - CheckFactories.registerCheck( - "misc-redundant-smartptr-get"); CheckFactories.registerCheck( "misc-swapped-arguments"); CheckFactories.registerCheck( Index: clang-tidy/readability/CMakeLists.txt =================================================================== --- clang-tidy/readability/CMakeLists.txt +++ clang-tidy/readability/CMakeLists.txt @@ -1,9 +1,10 @@ set(LLVM_LINK_COMPONENTS support) -add_clang_library(clangTidyReadability +add_clang_library(clangTidyReadabilityModule BracesAroundStatementsCheck.cpp FunctionSize.cpp NamespaceCommentCheck.cpp + ReadabilityTidyModule.cpp RedundantSmartptrGet.cpp LINK_LIBS Index: clang-tidy/readability/ReadabilityTidyModule.cpp =================================================================== --- /dev/null +++ clang-tidy/readability/ReadabilityTidyModule.cpp @@ -0,0 +1,44 @@ +//===--- ReadabilityTidyModule.cpp - clang-tidy ---------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "../ClangTidy.h" +#include "../ClangTidyModule.h" +#include "../ClangTidyModuleRegistry.h" +#include "BracesAroundStatementsCheck.h" +#include "FunctionSize.h" +#include "RedundantSmartptrGet.h" + +namespace clang { +namespace tidy { +namespace readability { + +class ReadabilityModule : public ClangTidyModule { +public: + void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck( + "readability-braces-around-statements"); + CheckFactories.registerCheck( + "readability-function-size"); + CheckFactories.registerCheck( + "readability-redundant-smartptr-get"); + } +}; + +} // namespace readability + +// Register the MiscTidyModule using this statically initialized variable. +static ClangTidyModuleRegistry::Add +X("readability-module", "Adds readability-related checks."); + +// This anchor is used to force the linker to link in the generated object file +// and thus register the MiscModule. +volatile int ReadabilityModuleAnchorSource = 0; + +} // namespace tidy +} // namespace clang Index: clang-tidy/tool/CMakeLists.txt =================================================================== --- clang-tidy/tool/CMakeLists.txt +++ clang-tidy/tool/CMakeLists.txt @@ -12,6 +12,7 @@ clangTidyGoogleModule clangTidyLLVMModule clangTidyMiscModule + clangTidyReadabilityModule clangTooling ) Index: clang-tidy/tool/ClangTidyMain.cpp =================================================================== --- clang-tidy/tool/ClangTidyMain.cpp +++ clang-tidy/tool/ClangTidyMain.cpp @@ -252,6 +252,10 @@ extern volatile int MiscModuleAnchorSource; static int MiscModuleAnchorDestination = MiscModuleAnchorSource; +// This anchor is used to force the linker to link the ReadabilityModule. +extern volatile int ReadabilityModuleAnchorSource; +static int ReadabilityModuleAnchorDestination = ReadabilityModuleAnchorSource; + } // namespace tidy } // namespace clang Index: test/clang-tidy/avoid-c-style-casts.c =================================================================== --- test/clang-tidy/avoid-c-style-casts.c +++ test/clang-tidy/avoid-c-style-casts.c @@ -1,9 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s google-readability-casting %t -- -x c -// REQUIRES: shell - -void f(const char *cpc) { - const char *cpc2 = (const char*)cpc; - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Redundant cast to the same type. [google-readability-casting] - // CHECK-FIXES: const char *cpc2 = cpc; - char *pc = (char*)cpc; -} Index: test/clang-tidy/avoid-c-style-casts.cpp =================================================================== --- test/clang-tidy/avoid-c-style-casts.cpp +++ test/clang-tidy/avoid-c-style-casts.cpp @@ -1,126 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s google-readability-casting %t -// REQUIRES: shell - -bool g() { return false; } - -enum Enum { Enum1 }; -struct X {}; -struct Y : public X {}; - -void f(int a, double b, const char *cpc, const void *cpv, X *pX) { - const char *cpc2 = (const char*)cpc; - // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Redundant cast to the same type. [google-readability-casting] - // CHECK-FIXES: const char *cpc2 = cpc; - - char *pc = (char*)cpc; - // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char *pc = const_cast(cpc); - - char *pc2 = (char*)(cpc + 33); - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char *pc2 = const_cast(cpc + 33); - - const char &crc = *cpc; - char &rc = (char&)crc; - // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char &rc = const_cast(crc); - - char &rc2 = (char&)*cpc; - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char &rc2 = const_cast(*cpc); - - char ** const* const* ppcpcpc; - char ****ppppc = (char****)ppcpcpc; - // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char ****ppppc = const_cast(ppcpcpc); - - char ***pppc = (char***)*(ppcpcpc); - // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char ***pppc = const_cast(*(ppcpcpc)); - - char ***pppc2 = (char***)(*ppcpcpc); - // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char ***pppc2 = const_cast(*ppcpcpc); - - char *pc5 = (char*)(const char*)(cpv); - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-MESSAGES: :[[@LINE-2]]:22: warning: C-style casts are discouraged. Use reinterpret_cast. {{.*}} - // CHECK-FIXES: char *pc5 = const_cast(reinterpret_cast(cpv)); - - int b1 = (int)b; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged. Use static_cast. [google-readability-casting] - // CHECK-FIXES: int b1 = static_cast(b); - - Y *pB = (Y*)pX; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. [google-readability-casting] - Y &rB = (Y&)*pX; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. [google-readability-casting] - - const char *pc3 = (const char*)cpv; - // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: C-style casts are discouraged. Use reinterpret_cast. [google-readability-casting] - // CHECK-FIXES: const char *pc3 = reinterpret_cast(cpv); - - char *pc4 = (char*)cpv; - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. [google-readability-casting] - // CHECK-FIXES: char *pc4 = (char*)cpv; - - b1 = (int)Enum1; - // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: C-style casts are discouraged. Use static_cast. [google-readability-casting] - // CHECK-FIXES: b1 = static_cast(Enum1); - - Enum e = (Enum)b1; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged. Use static_cast. [google-readability-casting] - // CHECK-FIXES: Enum e = static_cast(b1); - - // CHECK-MESSAGES-NOT: warning: - int b2 = int(b); - int b3 = static_cast(b); - int b4 = b; - double aa = a; - (void)b2; - return (void)g(); -} - -template -void template_function(T t, int n) { - int i = (int)t; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. - // CHECK-FIXES: int i = (int)t; - int j = (int)n; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Redundant cast to the same type. - // CHECK-FIXES: int j = n; -} - -template -struct TemplateStruct { - void f(T t, int n) { - int k = (int)t; - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. - // CHECK-FIXES: int k = (int)t; - int l = (int)n; - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Redundant cast to the same type. - // CHECK-FIXES: int l = n; - } -}; - -void test_templates() { - template_function(1, 42); - template_function(1.0, 42); - TemplateStruct().f(1, 42); - TemplateStruct().f(1.0, 42); -} - -#define CAST(type, value) (type)(value) -void macros(double d) { - int i = CAST(int, d); -} - -enum E { E1 = 1 }; -template -struct A { - // Usage of template argument e = E1 is represented as (E)1 in the AST for - // some reason. We have a special treatment of this case to avoid warnings - // here. - static const E ee = e; -}; -struct B : public A {}; Index: test/clang-tidy/google-module.cpp =================================================================== --- test/clang-tidy/google-module.cpp +++ test/clang-tidy/google-module.cpp @@ -2,6 +2,8 @@ // CHECK: CheckOptions: // CHECK: {{- key: *google-readability-braces-around-statements.ShortStatementLines}} // CHECK-NEXT: {{value: *'1'}} +// CHECK: {{- key: *google-readability-function-size.StatementThreshold}} +// CHECK-NEXT: {{value: *'800'}} // CHECK: {{- key: *google-readability-namespace-comments.ShortNamespaceLines}} // CHECK-NEXT: {{value: *'1'}} // CHECK: {{- key: *google-readability-namespace-comments.SpacesBeforeComments}} Index: test/clang-tidy/misc-braces-around-statements-few-lines.cpp =================================================================== --- test/clang-tidy/misc-braces-around-statements-few-lines.cpp +++ test/clang-tidy/misc-braces-around-statements-few-lines.cpp @@ -1,31 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 4}]}" -- -// REQUIRES: shell - -void do_something(const char *) {} - -bool cond(const char *) { - return false; -} - -void test() { - if (cond("if1") /*comment*/) do_something("same-line"); - - if (cond("if2")) - do_something("single-line"); - - if (cond("if3") /*comment*/) - // some comment - do_something("three" - "lines"); - - if (cond("if4") /*comment*/) - // some comment - do_something("many" - "many" - "many" - "many" - "lines"); - // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if4") /*comment*/) { - // CHECK-FIXES: } -} Index: test/clang-tidy/misc-braces-around-statements-same-line.cpp =================================================================== --- test/clang-tidy/misc-braces-around-statements-same-line.cpp +++ test/clang-tidy/misc-braces-around-statements-same-line.cpp @@ -1,37 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 1}]}" -- -// REQUIRES: shell - -void do_something(const char *) {} - -bool cond(const char *) { - return false; -} - -void test() { - if (cond("if1") /*comment*/) do_something("same-line"); - - if (cond("if2")) - do_something("single-line"); - // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if2")) { - // CHECK-FIXES: } - - if (cond("if3") /*comment*/) - // some comment - do_something("three" - "lines"); - // CHECK-MESSAGES: :[[@LINE-4]]:31: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if3") /*comment*/) { - // CHECK-FIXES: } - - if (cond("if4") /*comment*/) - // some comment - do_something("many" - "many" - "many" - "many" - "lines"); - // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if4") /*comment*/) { - // CHECK-FIXES: } -} Index: test/clang-tidy/misc-braces-around-statements-single-line.cpp =================================================================== --- test/clang-tidy/misc-braces-around-statements-single-line.cpp +++ test/clang-tidy/misc-braces-around-statements-single-line.cpp @@ -1,34 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 2}]}" -- -// REQUIRES: shell - -void do_something(const char *) {} - -bool cond(const char *) { - return false; -} - -void test() { - if (cond("if1") /*comment*/) do_something("same-line"); - - if (cond("if2")) - do_something("single-line"); - - if (cond("if3") /*comment*/) - // some comment - do_something("three" - "lines"); - // CHECK-MESSAGES: :[[@LINE-4]]:31: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if3") /*comment*/) { - // CHECK-FIXES: } - - if (cond("if4") /*comment*/) - // some comment - do_something("many" - "many" - "many" - "many" - "lines"); - // CHECK-MESSAGES: :[[@LINE-7]]:31: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if4") /*comment*/) { - // CHECK-FIXES: } -} Index: test/clang-tidy/misc-braces-around-statements.cpp =================================================================== --- test/clang-tidy/misc-braces-around-statements.cpp +++ test/clang-tidy/misc-braces-around-statements.cpp @@ -1,174 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -// REQUIRES: shell - -void do_something(const char *) {} - -bool cond(const char *) { - return false; -} - -#define EMPTY_MACRO -#define EMPTY_MACRO_FUN() - -void test() { - if (cond("if0") /*comment*/) do_something("same-line"); - // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if0") /*comment*/) { do_something("same-line"); - // CHECK-FIXES: } - - if (cond("if0.1")) - do_something("single-line"); - // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if0.1")) { - // CHECK-FIXES: } - - if (cond("if1") /*comment*/) - // some comment - do_something("if1"); - // CHECK-MESSAGES: :[[@LINE-3]]:31: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if1") /*comment*/) { - // CHECK-FIXES: } - if (cond("if2")) { - do_something("if2"); - } - if (cond("if3")) - ; - // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if3")) { - // CHECK-FIXES: } - - if (cond("if-else1")) - do_something("if-else1"); - // CHECK-MESSAGES: :[[@LINE-2]]:24: warning: statement should be inside braces - // CHECK-FIXES: if (cond("if-else1")) { - // CHECK-FIXES: } else { - else - do_something("if-else1 else"); - // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: statement should be inside braces - // CHECK-FIXES: } - if (cond("if-else2")) { - do_something("if-else2"); - } else { - do_something("if-else2 else"); - } - - if (cond("if-else if-else1")) - do_something("if"); - // CHECK-MESSAGES: :[[@LINE-2]]:32: warning: statement should be inside braces - // CHECK-FIXES: } else if (cond("else if1")) { - else if (cond("else if1")) - do_something("else if"); - // CHECK-MESSAGES: :[[@LINE-2]]:29: warning: statement should be inside braces - else - do_something("else"); - // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: statement should be inside braces - // CHECK-FIXES: } - if (cond("if-else if-else2")) { - do_something("if"); - } else if (cond("else if2")) { - do_something("else if"); - } else { - do_something("else"); - } - - for (;;) - do_something("for"); - // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: statement should be inside braces - // CHECK-FIXES: for (;;) { - // CHECK-FIXES: } - for (;;) { - do_something("for"); - } - for (;;) - ; - // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: statement should be inside braces - // CHECK-FIXES: for (;;) { - // CHECK-FIXES: } - - int arr[4] = {1, 2, 3, 4}; - for (int a : arr) - do_something("for-range"); - // CHECK-MESSAGES: :[[@LINE-2]]:20: warning: statement should be inside braces - // CHECK-FIXES: for (int a : arr) { - // CHECK-FIXES: } - for (int a : arr) { - do_something("for-range"); - } - for (int a : arr) - ; - // CHECK-MESSAGES: :[[@LINE-2]]:20: warning: statement should be inside braces - // CHECK-FIXES: for (int a : arr) { - // CHECK-FIXES: } - - while (cond("while1")) - do_something("while"); - // CHECK-MESSAGES: :[[@LINE-2]]:25: warning: statement should be inside braces - // CHECK-FIXES: while (cond("while1")) { - // CHECK-FIXES: } - while (cond("while2")) { - do_something("while"); - } - while (false) - ; - // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: statement should be inside braces - // CHECK-FIXES: while (false) { - // CHECK-FIXES: } - - do - do_something("do1"); - while (cond("do1")); - // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: statement should be inside braces - // CHECK-FIXES: do { - // CHECK-FIXES: } while (cond("do1")); - do { - do_something("do2"); - } while (cond("do2")); - - do - ; - while (false); - // CHECK-MESSAGES: :[[@LINE-3]]:5: warning: statement should be inside braces - // CHECK-FIXES: do { - // CHECK-FIXES: } while (false); - - if (cond("ifif1")) - // comment - if (cond("ifif2")) - // comment - /*comment*/ ; // comment - // CHECK-MESSAGES: :[[@LINE-5]]:21: warning: statement should be inside braces - // CHECK-MESSAGES: :[[@LINE-4]]:23: warning: statement should be inside braces - // CHECK-FIXES: if (cond("ifif1")) { - // CHECK-FIXES: if (cond("ifif2")) { - // CHECK-FIXES: } - // CHECK-FIXES-NEXT: } - - if (cond("ifif3")) - // comment - if (cond("ifif4")) { - // comment - /*comment*/; // comment - } - // CHECK-MESSAGES: :[[@LINE-6]]:21: warning: statement should be inside braces - // CHECK-FIXES: if (cond("ifif3")) { - // CHECK-FIXES: } - - if (cond("ifif5")) - ; /* multi-line - comment */ - // CHECK-MESSAGES: :[[@LINE-3]]:21: warning: statement should be inside braces - // CHECK-FIXES: if (cond("ifif5")) { - // CHECK-FIXES: }/* multi-line - - if (1) while (2) if (3) for (;;) do ; while(false) /**/;/**/ - // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: statement should be inside braces - // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: statement should be inside braces - // CHECK-MESSAGES: :[[@LINE-3]]:26: warning: statement should be inside braces - // CHECK-MESSAGES: :[[@LINE-4]]:35: warning: statement should be inside braces - // CHECK-MESSAGES: :[[@LINE-5]]:38: warning: statement should be inside braces - // CHECK-FIXES: if (1) { while (2) { if (3) { for (;;) { do { ; } while(false) /**/;/**/ - // CHECK-FIXES-NEXT: } - // CHECK-FIXES-NEXT: } - // CHECK-FIXES-NEXT: } - // CHECK-FIXES-NEXT: } -} Index: test/clang-tidy/misc-function-size.cpp =================================================================== --- test/clang-tidy/misc-function-size.cpp +++ test/clang-tidy/misc-function-size.cpp @@ -1,58 +0,0 @@ -// RUN: rm -rf %t -// RUN: mkdir -p %t -// RUN: sed 's#// *[A-Z-][A-Z-]*:.*#//#' %s > %t/t.cpp -// RUN: echo '{ Checks: "-*,misc-function-size", CheckOptions: [{key: misc-function-size.LineThreshold, value: 0}, {key: misc-function-size.StatementThreshold, value: 0}, {key: misc-function-size.BranchThreshold, value: 0}]}' > %t/.clang-tidy -// RUN: clang-tidy %t/t.cpp -- -std=c++11 2>&1 | FileCheck %s -implicit-check-not='{{warning:|error:|note:}}' - -void foo1() { -} - -void foo2() {;} -// CHECK: warning: function 'foo2' exceeds recommended size/complexity thresholds -// CHECK: note: 1 statements (threshold 0) - -void foo3() { -; - -} -// CHECK: warning: function 'foo3' exceeds recommended size/complexity thresholds -// CHECK: note: 3 lines including whitespace and comments (threshold 0) -// CHECK: note: 1 statements (threshold 0) - -void foo4(int i) { if (i) {} else; {} -} -// CHECK: warning: function 'foo4' exceeds recommended size/complexity thresholds -// CHECK: note: 1 lines including whitespace and comments (threshold 0) -// CHECK: note: 3 statements (threshold 0) -// CHECK: note: 1 branches (threshold 0) - -void foo5(int i) {for(;i;)while(i) -do;while(i); -} -// CHECK: warning: function 'foo5' exceeds recommended size/complexity thresholds -// CHECK: note: 2 lines including whitespace and comments (threshold 0) -// CHECK: note: 7 statements (threshold 0) -// CHECK: note: 3 branches (threshold 0) - -template T foo6(T i) {return i; -} -int x = foo6(0); -// CHECK: warning: function 'foo6' exceeds recommended size/complexity thresholds -// CHECK: note: 1 lines including whitespace and comments (threshold 0) -// CHECK: note: 1 statements (threshold 0) - -void bar1() { [](){;;;;;;;;;;;if(1){}}(); - - -} -// CHECK: warning: function 'bar1' exceeds recommended size/complexity thresholds -// CHECK: note: 3 lines including whitespace and comments (threshold 0) -// CHECK: note: 14 statements (threshold 0) -// CHECK: note: 1 branches (threshold 0) - -void bar2() { class A { void barx() {;;} }; } -// CHECK: warning: function 'bar2' exceeds recommended size/complexity thresholds -// CHECK: note: 3 statements (threshold 0) -// -// CHECK: warning: function 'barx' exceeds recommended size/complexity thresholds -// CHECK: note: 2 statements (threshold 0) Index: test/clang-tidy/readability-braces-around-statements-few-lines.cpp =================================================================== --- test/clang-tidy/readability-braces-around-statements-few-lines.cpp +++ test/clang-tidy/readability-braces-around-statements-few-lines.cpp @@ -1,4 +1,4 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 4}]}" -- +// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 4}]}" -- // REQUIRES: shell void do_something(const char *) {} Index: test/clang-tidy/readability-braces-around-statements-same-line.cpp =================================================================== --- test/clang-tidy/readability-braces-around-statements-same-line.cpp +++ test/clang-tidy/readability-braces-around-statements-same-line.cpp @@ -1,4 +1,4 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 1}]}" -- +// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 1}]}" -- // REQUIRES: shell void do_something(const char *) {} Index: test/clang-tidy/readability-braces-around-statements-single-line.cpp =================================================================== --- test/clang-tidy/readability-braces-around-statements-single-line.cpp +++ test/clang-tidy/readability-braces-around-statements-single-line.cpp @@ -1,4 +1,4 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t -config="{CheckOptions: [{key: misc-braces-around-statements.ShortStatementLines, value: 2}]}" -- +// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t -config="{CheckOptions: [{key: readability-braces-around-statements.ShortStatementLines, value: 2}]}" -- // REQUIRES: shell void do_something(const char *) {} Index: test/clang-tidy/readability-braces-around-statements.cpp =================================================================== --- test/clang-tidy/readability-braces-around-statements.cpp +++ test/clang-tidy/readability-braces-around-statements.cpp @@ -1,4 +1,4 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-braces-around-statements %t +// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-braces-around-statements %t // REQUIRES: shell void do_something(const char *) {} Index: test/clang-tidy/readability-function-size.cpp =================================================================== --- test/clang-tidy/readability-function-size.cpp +++ test/clang-tidy/readability-function-size.cpp @@ -1,7 +1,7 @@ // RUN: rm -rf %t // RUN: mkdir -p %t // RUN: sed 's#// *[A-Z-][A-Z-]*:.*#//#' %s > %t/t.cpp -// RUN: echo '{ Checks: "-*,misc-function-size", CheckOptions: [{key: misc-function-size.LineThreshold, value: 0}, {key: misc-function-size.StatementThreshold, value: 0}, {key: misc-function-size.BranchThreshold, value: 0}]}' > %t/.clang-tidy +// RUN: echo '{ Checks: "-*,readability-function-size", CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}]}' > %t/.clang-tidy // RUN: clang-tidy %t/t.cpp -- -std=c++11 2>&1 | FileCheck %s -implicit-check-not='{{warning:|error:|note:}}' void foo1() { Index: test/clang-tidy/readability-redundant-smartptr-get.cpp =================================================================== --- test/clang-tidy/readability-redundant-smartptr-get.cpp +++ test/clang-tidy/readability-redundant-smartptr-get.cpp @@ -1,4 +1,4 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-redundant-smartptr-get %t +// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s readability-redundant-smartptr-get %t // REQUIRES: shell #define NULL __null @@ -49,7 +49,7 @@ BarPtr u; // CHECK-FIXES: BarPtr u; BarPtr().get()->Do(); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. [misc-redundant-smartptr-get] + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. [readability-redundant-smartptr-get] // CHECK-MESSAGES: BarPtr().get()->Do(); // CHECK-FIXES: BarPtr()->Do(); Index: test/clang-tidy/redundant-smartptr-get.cpp =================================================================== --- test/clang-tidy/redundant-smartptr-get.cpp +++ test/clang-tidy/redundant-smartptr-get.cpp @@ -1,129 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-redundant-smartptr-get %t -// REQUIRES: shell - -#define NULL __null - -namespace std { - -template -struct unique_ptr { - T& operator*() const; - T* operator->() const; - T* get() const; -}; - -template -struct shared_ptr { - T& operator*() const; - T* operator->() const; - T* get() const; -}; - -} // namespace std - -struct Bar { - void Do(); - void ConstDo() const; -}; -struct BarPtr { - Bar* operator->(); - Bar& operator*(); - Bar* get(); -}; -struct int_ptr { - int* get(); - int* operator->(); - int& operator*(); -}; - -struct Fail1 { - Bar* get(); -}; -struct Fail2 { - Bar* get(); - int* operator->(); - int& operator*(); -}; - -void Positive() { - BarPtr u; - // CHECK-FIXES: BarPtr u; - BarPtr().get()->Do(); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. [misc-redundant-smartptr-get] - // CHECK-MESSAGES: BarPtr().get()->Do(); - // CHECK-FIXES: BarPtr()->Do(); - - u.get()->ConstDo(); - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: u.get()->ConstDo(); - // CHECK-FIXES: u->ConstDo(); - - Bar& b = *BarPtr().get(); - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: Bar& b = *BarPtr().get(); - // CHECK-FIXES: Bar& b = *BarPtr(); - - Bar& b2 = *std::unique_ptr().get(); - // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: Bar& b2 = *std::unique_ptr().get(); - // CHECK-FIXES: Bar& b2 = *std::unique_ptr(); - - (*BarPtr().get()).ConstDo(); - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: (*BarPtr().get()).ConstDo(); - // CHECK-FIXES: (*BarPtr()).ConstDo(); - - (*std::unique_ptr().get()).ConstDo(); - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: (*std::unique_ptr().get()).ConstDo(); - // CHECK-FIXES: (*std::unique_ptr()).ConstDo(); - - std::unique_ptr* up; - (*up->get()).Do(); - // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: (*up->get()).Do(); - // CHECK-FIXES: (**up).Do(); - - int_ptr ip; - int i = *ip.get(); - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: int i = *ip.get(); - // CHECK-FIXES: int i = *ip; - - std::unique_ptr uu; - std::shared_ptr *ss; - bool bb = uu.get() == nullptr; - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: uu.get() == nullptr; - // CHECK-FIXES: bool bb = uu == nullptr; - - bb = nullptr != ss->get(); - // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: Redundant get() call on smart pointer. - // CHECK-MESSAGES: nullptr != ss->get(); - // CHECK-FIXES: bb = nullptr != *ss; -} - -void Negative() { - struct NegPtr { - int* get(); - int* operator->() { - return &*this->get(); - } - int& operator*() { - return *get(); - } - }; - - std::unique_ptr* u; - u->get()->Do(); - - Fail1().get()->Do(); - Fail2().get()->Do(); - const Bar& b = *Fail1().get(); - (*Fail2().get()).Do(); - - int_ptr ip; - bool bb = std::unique_ptr().get() == NULL; - bb = ip.get() == nullptr; - bb = u->get() == NULL; -} Index: test/clang-tidy/use-override.cpp =================================================================== --- test/clang-tidy/use-override.cpp +++ test/clang-tidy/use-override.cpp @@ -1,226 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s misc-use-override %t -// REQUIRES: shell - -#define ABSTRACT = 0 - -#define OVERRIDE override -#define VIRTUAL virtual -#define NOT_VIRTUAL -#define NOT_OVERRIDE - -#define MUST_USE_RESULT __attribute__((warn_unused_result)) - -struct MUST_USE_RESULT MustUseResultObject {}; - -struct Base { - virtual ~Base() {} - virtual void a(); - virtual void b(); - virtual void c(); - virtual void d(); - virtual void e() = 0; - virtual void f() = 0; - virtual void g() = 0; - - virtual void j() const; - virtual MustUseResultObject k(); - virtual bool l() MUST_USE_RESULT; - - virtual void m(); -}; - -struct SimpleCases : public Base { -public: - virtual ~SimpleCases(); - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Prefer using 'override' or (rarely) 'final' instead of 'virtual' - // CHECK-FIXES: {{^ ~SimpleCases\(\) override;}} - - void a(); - // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: Annotate this - // CHECK-FIXES: {{^ void a\(\) override;}} - - void b() override; - // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^ void b\(\) override;}} - - virtual void c(); - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void c\(\) override;}} - - virtual void d() override; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ void d\(\) override;}} - - virtual void e() = 0; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void e\(\) override = 0;}} - - virtual void f()=0; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void f\(\)override =0;}} - - virtual void g() ABSTRACT; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void g\(\) override ABSTRACT;}} - - virtual void j() const; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void j\(\) const override;}} - - virtual MustUseResultObject k(); // Has an implicit attribute. - // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: Prefer using - // CHECK-FIXES: {{^ MustUseResultObject k\(\) override;}} - - virtual bool l() MUST_USE_RESULT; // Has an explicit attribute - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ bool l\(\) override MUST_USE_RESULT;}} - - virtual void m() override final; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ void m\(\) final;}} -}; - -// CHECK-MESSAGES-NOT: warning: - -void SimpleCases::c() {} -// CHECK-FIXES: {{^void SimpleCases::c\(\) {}}} - -SimpleCases::~SimpleCases() {} -// CHECK-FIXES: {{^SimpleCases::~SimpleCases\(\) {}}} - -struct DefaultedDestructor : public Base { - DefaultedDestructor() {} - virtual ~DefaultedDestructor() = default; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Prefer using - // CHECK-FIXES: {{^ ~DefaultedDestructor\(\) override = default;}} -}; - -struct FinalSpecified : public Base { -public: - virtual ~FinalSpecified() final; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Annotate this - // CHECK-FIXES: {{^ ~FinalSpecified\(\) final;}} - - void b() final; - // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^ void b\(\) final;}} - - virtual void d() final; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ void d\(\) final;}} - - virtual void e() final = 0; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ void e\(\) final = 0;}} - - virtual void j() const final; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ void j\(\) const final;}} - - virtual bool l() final MUST_USE_RESULT; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ bool l\(\) final MUST_USE_RESULT;}} -}; - -struct InlineDefinitions : public Base { -public: - virtual ~InlineDefinitions() {} - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Prefer using - // CHECK-FIXES: {{^ ~InlineDefinitions\(\) override {}}} - - void a() {} - // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: Annotate this - // CHECK-FIXES: {{^ void a\(\) override {}}} - - void b() override {} - // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^ void b\(\) override {}}} - - virtual void c() {} - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void c\(\) override {}}} - - virtual void d() override {} - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ void d\(\) override {}}} - - virtual void j() const {} - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void j\(\) const override {}}} - - virtual MustUseResultObject k() {} // Has an implicit attribute. - // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: Prefer using - // CHECK-FIXES: {{^ MustUseResultObject k\(\) override {}}} - - virtual bool l() MUST_USE_RESULT {} // Has an explicit attribute - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ bool l\(\) override MUST_USE_RESULT {}}} -}; - -struct Macros : public Base { - // Tests for 'virtual' and 'override' being defined through macros. Basically - // give up for now. - NOT_VIRTUAL void a() NOT_OVERRIDE; - // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: Annotate this - // CHECK-FIXES: {{^ NOT_VIRTUAL void a\(\) override NOT_OVERRIDE;}} - - VIRTUAL void b() NOT_OVERRIDE; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ VIRTUAL void b\(\) override NOT_OVERRIDE;}} - - NOT_VIRTUAL void c() OVERRIDE; - // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^ NOT_VIRTUAL void c\(\) OVERRIDE;}} - - VIRTUAL void d() OVERRIDE; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ VIRTUAL void d\(\) OVERRIDE;}} - -#define FUNC(return_type, name) return_type name() - FUNC(void, e); - // CHECK-FIXES: {{^ FUNC\(void, e\);}} - -#define F virtual void f(); - F - // CHECK-FIXES: {{^ F}} - - VIRTUAL void g() OVERRIDE final; - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Annotate this - // CHECK-FIXES: {{^ VIRTUAL void g\(\) final;}} -}; - -// Tests for templates. -template struct TemplateBase { - virtual void f(T t); -}; - -template struct DerivedFromTemplate : public TemplateBase { - virtual void f(T t); - // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: Prefer using - // CHECK-FIXES: {{^ void f\(T t\) override;}} -}; -void f() { DerivedFromTemplate().f(2); } - -template -struct UnusedMemberInstantiation : public C { - virtual ~UnusedMemberInstantiation() {} - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Prefer using - // CHECK-FIXES: {{^ ~UnusedMemberInstantiation\(\) override {}}} -}; -struct IntantiateWithoutUse : public UnusedMemberInstantiation {}; - -struct Base2 { - virtual ~Base2() {} - virtual void a(); -}; - -// The OverrideAttr isn't propagated to specializations in all cases. Make sure -// we don't add "override" a second time. -template -struct MembersOfSpecializations : public Base2 { - void a() override; - // CHECK-MESSAGES-NOT: warning: - // CHECK-FIXES: {{^ void a\(\) override;}} -}; -template <> void MembersOfSpecializations<3>::a() {} -void ff() { MembersOfSpecializations<3>().a(); }; Index: unittests/clang-tidy/CMakeLists.txt =================================================================== --- unittests/clang-tidy/CMakeLists.txt +++ unittests/clang-tidy/CMakeLists.txt @@ -9,10 +9,10 @@ add_extra_unittest(ClangTidyTests ClangTidyDiagnosticConsumerTest.cpp ClangTidyOptionsTest.cpp - LLVMModuleTest.cpp - ReadabilityChecksTest.cpp GoogleModuleTest.cpp - MiscModuleTest.cpp) + LLVMModuleTest.cpp + MiscModuleTest.cpp + ReadabilityModuleTest.cpp) target_link_libraries(ClangTidyTests clangAST @@ -23,7 +23,7 @@ clangTidyGoogleModule clangTidyLLVMModule clangTidyMiscModule - clangTidyReadability + clangTidyReadabilityModule clangTidyUtils clangTooling ) Index: unittests/clang-tidy/ReadabilityChecksTest.cpp =================================================================== --- unittests/clang-tidy/ReadabilityChecksTest.cpp +++ unittests/clang-tidy/ReadabilityChecksTest.cpp @@ -1,99 +0,0 @@ -#include "ClangTidyTest.h" -#include "readability/NamespaceCommentCheck.h" -#include "gtest/gtest.h" - -namespace clang { -namespace tidy { -namespace test { - -using readability::NamespaceCommentCheck; - -TEST(NamespaceCommentCheckTest, Basic) { - EXPECT_EQ("namespace i {\n} // namespace i", - runCheckOnCode("namespace i {\n}")); - EXPECT_EQ("namespace {\n} // namespace", - runCheckOnCode("namespace {\n}")); - EXPECT_EQ( - "namespace i { namespace j {\n} // namespace j\n } // namespace i", - runCheckOnCode("namespace i { namespace j {\n} }")); -} - -TEST(NamespaceCommentCheckTest, SingleLineNamespaces) { - EXPECT_EQ( - "namespace i { namespace j { } }", - runCheckOnCode("namespace i { namespace j { } }")); -} - -TEST(NamespaceCommentCheckTest, CheckExistingComments) { - EXPECT_EQ("namespace i { namespace j {\n" - "} /* namespace j */ } // namespace i\n" - " /* random comment */", - runCheckOnCode( - "namespace i { namespace j {\n" - "} /* namespace j */ } /* random comment */")); - EXPECT_EQ("namespace {\n" - "} // namespace", - runCheckOnCode("namespace {\n" - "} // namespace")); - EXPECT_EQ("namespace {\n" - "} //namespace", - runCheckOnCode("namespace {\n" - "} //namespace")); - EXPECT_EQ("namespace {\n" - "} // anonymous namespace", - runCheckOnCode("namespace {\n" - "} // anonymous namespace")); - EXPECT_EQ("namespace {\n" - "} // Anonymous namespace.", - runCheckOnCode("namespace {\n" - "} // Anonymous namespace.")); - EXPECT_EQ("namespace q {\n" - "} // namespace q", - runCheckOnCode("namespace q {\n" - "} // anonymous namespace q")); - EXPECT_EQ( - "namespace My_NameSpace123 {\n" - "} // namespace My_NameSpace123", - runCheckOnCode("namespace My_NameSpace123 {\n" - "} // namespace My_NameSpace123")); - EXPECT_EQ( - "namespace My_NameSpace123 {\n" - "} //namespace My_NameSpace123", - runCheckOnCode("namespace My_NameSpace123 {\n" - "} //namespace My_NameSpace123")); - EXPECT_EQ("namespace My_NameSpace123 {\n" - "} // end namespace My_NameSpace123", - runCheckOnCode( - "namespace My_NameSpace123 {\n" - "} // end namespace My_NameSpace123")); - // Understand comments only on the same line. - EXPECT_EQ("namespace {\n" - "} // namespace\n" - "// namespace", - runCheckOnCode("namespace {\n" - "}\n" - "// namespace")); - // Leave unknown comments. - EXPECT_EQ("namespace {\n" - "} // namespace // random text", - runCheckOnCode("namespace {\n" - "} // random text")); -} - -TEST(NamespaceCommentCheckTest, FixWrongComments) { - EXPECT_EQ("namespace i { namespace jJ0_ {\n" - "} // namespace jJ0_\n" - " } // namespace i\n" - " /* random comment */", - runCheckOnCode( - "namespace i { namespace jJ0_ {\n" - "} /* namespace qqq */ } /* random comment */")); - EXPECT_EQ("namespace {\n" - "} // namespace", - runCheckOnCode("namespace {\n" - "} // namespace asdf")); -} - -} // namespace test -} // namespace tidy -} // namespace clang