2014-04-08 20:27:49 +08:00
|
|
|
#include "ClangTidy.h"
|
|
|
|
#include "ClangTidyTest.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
class TestCheck : public ClangTidyCheck {
|
|
|
|
public:
|
2014-09-12 16:53:36 +08:00
|
|
|
TestCheck(StringRef Name, ClangTidyContext *Context)
|
|
|
|
: ClangTidyCheck(Name, Context) {}
|
2014-04-08 20:27:49 +08:00
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override {
|
|
|
|
Finder->addMatcher(ast_matchers::varDecl().bind("var"), this);
|
|
|
|
}
|
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override {
|
|
|
|
const VarDecl *Var = Result.Nodes.getNodeAs<VarDecl>("var");
|
|
|
|
// Add diagnostics in the wrong order.
|
|
|
|
diag(Var->getLocation(), "variable");
|
|
|
|
diag(Var->getTypeSpecStartLoc(), "type specifier");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(ClangTidyDiagnosticConsumer, SortsErrors) {
|
2014-05-09 20:24:09 +08:00
|
|
|
std::vector<ClangTidyError> Errors;
|
|
|
|
runCheckOnCode<TestCheck>("int a;", &Errors);
|
2014-04-08 20:27:49 +08:00
|
|
|
EXPECT_EQ(2ul, Errors.size());
|
2014-09-12 16:53:36 +08:00
|
|
|
EXPECT_EQ("type specifier", Errors[0].Message.Message);
|
|
|
|
EXPECT_EQ("variable", Errors[1].Message.Message);
|
2014-04-08 20:27:49 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
TEST(GlobList, Empty) {
|
|
|
|
GlobList Filter("");
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
EXPECT_TRUE(Filter.contains(""));
|
|
|
|
EXPECT_FALSE(Filter.contains("aaa"));
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
TEST(GlobList, Nothing) {
|
|
|
|
GlobList Filter("-*");
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
EXPECT_FALSE(Filter.contains(""));
|
|
|
|
EXPECT_FALSE(Filter.contains("a"));
|
|
|
|
EXPECT_FALSE(Filter.contains("-*"));
|
|
|
|
EXPECT_FALSE(Filter.contains("-"));
|
|
|
|
EXPECT_FALSE(Filter.contains("*"));
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
TEST(GlobList, Everything) {
|
|
|
|
GlobList Filter("*");
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
EXPECT_TRUE(Filter.contains(""));
|
|
|
|
EXPECT_TRUE(Filter.contains("aaaa"));
|
|
|
|
EXPECT_TRUE(Filter.contains("-*"));
|
|
|
|
EXPECT_TRUE(Filter.contains("-"));
|
|
|
|
EXPECT_TRUE(Filter.contains("*"));
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
TEST(GlobList, Simple) {
|
|
|
|
GlobList Filter("aaa");
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
EXPECT_TRUE(Filter.contains("aaa"));
|
|
|
|
EXPECT_FALSE(Filter.contains(""));
|
|
|
|
EXPECT_FALSE(Filter.contains("aa"));
|
|
|
|
EXPECT_FALSE(Filter.contains("aaaa"));
|
|
|
|
EXPECT_FALSE(Filter.contains("bbb"));
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
}
|
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
TEST(GlobList, Complex) {
|
|
|
|
GlobList Filter("*,-a.*,-b.*,a.1.*,-a.1.A.*,-..,-...,-..+,-*$,-*qwe*");
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
|
2014-08-06 19:49:10 +08:00
|
|
|
EXPECT_TRUE(Filter.contains("aaa"));
|
|
|
|
EXPECT_TRUE(Filter.contains("qqq"));
|
|
|
|
EXPECT_FALSE(Filter.contains("a."));
|
|
|
|
EXPECT_FALSE(Filter.contains("a.b"));
|
|
|
|
EXPECT_FALSE(Filter.contains("b."));
|
|
|
|
EXPECT_FALSE(Filter.contains("b.b"));
|
|
|
|
EXPECT_TRUE(Filter.contains("a.1.b"));
|
|
|
|
EXPECT_FALSE(Filter.contains("a.1.A.a"));
|
|
|
|
EXPECT_FALSE(Filter.contains("qwe"));
|
|
|
|
EXPECT_FALSE(Filter.contains("asdfqweasdf"));
|
|
|
|
EXPECT_TRUE(Filter.contains("asdfqwEasdf"));
|
Change the behavior of clang-tidy -checks=, remove -disable-checks.
Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.
Example:
The default value for -checks= is
'*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
which allows all checks except for the ones named clang-analyzer-alpha* and
others specified with the leading '-'. To allow all google-* checks one can
write:
clang-tidy -checks=google-* ...
If one needs only google-* checks, we first need to remove everything (-*):
clang-tidy -checks=-*,google-*
etc.
I'm not sure if we need to change something here, so I didn't touch the docs
yet.
Reviewers: klimek, alexfh
Reviewed By: alexfh
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D3770
llvm-svn: 208883
2014-05-15 22:27:36 +08:00
|
|
|
}
|
|
|
|
|
2014-04-08 20:27:49 +08:00
|
|
|
} // namespace test
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|