#include "ClangTidy.h" #include "ClangTidyTest.h" #include "gtest/gtest.h" namespace clang { namespace tidy { namespace test { namespace { class TestCheck : public ClangTidyCheck { public: TestCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context) { diag("DiagWithNoLoc"); } 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 auto *Var = Result.Nodes.getNodeAs("var"); // Add diagnostics in the wrong order. diag(Var->getLocation(), "variable"); diag(Var->getTypeSpecStartLoc(), "type specifier"); } }; } // namespace TEST(ClangTidyDiagnosticConsumer, SortsErrors) { std::vector Errors; runCheckOnCode("int a;", &Errors); EXPECT_EQ(3ul, Errors.size()); EXPECT_EQ("DiagWithNoLoc", Errors[0].Message.Message); EXPECT_EQ("type specifier", Errors[1].Message.Message); EXPECT_EQ("variable", Errors[2].Message.Message); } } // namespace test } // namespace tidy } // namespace clang