llvm-project
75 строк · 2.3 Кб
1//===-- TidyProviderTests.cpp - Clang tidy configuration provider tests ---===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "Feature.h"
10#include "TestFS.h"
11#include "TidyProvider.h"
12#include "llvm/Testing/Support/SupportHelpers.h"
13#include "gtest/gtest.h"
14
15namespace clang {
16namespace clangd {
17
18namespace {
19
20TEST(TidyProvider, NestedDirectories) {
21MockFS FS;
22FS.Files[testPath(".clang-tidy")] = R"yaml(
23Checks: 'llvm-*'
24CheckOptions:
25TestKey: 1
26)yaml";
27FS.Files[testPath("sub1/.clang-tidy")] = R"yaml(
28Checks: 'misc-*'
29CheckOptions:
30TestKey: 2
31)yaml";
32FS.Files[testPath("sub1/sub2/.clang-tidy")] = R"yaml(
33Checks: 'bugprone-*'
34CheckOptions:
35TestKey: 3
36InheritParentConfig: true
37)yaml";
38
39TidyProvider Provider = provideClangTidyFiles(FS);
40
41auto BaseOptions = getTidyOptionsForFile(Provider, testPath("File.cpp"));
42ASSERT_TRUE(BaseOptions.Checks.has_value());
43EXPECT_EQ(*BaseOptions.Checks, "llvm-*");
44EXPECT_EQ(BaseOptions.CheckOptions.lookup("TestKey").Value, "1");
45
46auto Sub1Options = getTidyOptionsForFile(Provider, testPath("sub1/File.cpp"));
47ASSERT_TRUE(Sub1Options.Checks.has_value());
48EXPECT_EQ(*Sub1Options.Checks, "misc-*");
49EXPECT_EQ(Sub1Options.CheckOptions.lookup("TestKey").Value, "2");
50
51auto Sub2Options =
52getTidyOptionsForFile(Provider, testPath("sub1/sub2/File.cpp"));
53ASSERT_TRUE(Sub2Options.Checks.has_value());
54EXPECT_EQ(*Sub2Options.Checks, "misc-*,bugprone-*");
55EXPECT_EQ(Sub2Options.CheckOptions.lookup("TestKey").Value, "3");
56}
57
58TEST(TidyProvider, IsFastTidyCheck) {
59EXPECT_THAT(isFastTidyCheck("misc-const-correctness"), llvm::ValueIs(false));
60EXPECT_THAT(isFastTidyCheck("bugprone-suspicious-include"),
61llvm::ValueIs(true));
62// Linked in (ParsedASTTests.cpp) but not measured.
63EXPECT_EQ(isFastTidyCheck("replay-preamble-check"), std::nullopt);
64}
65
66#if CLANGD_TIDY_CHECKS
67TEST(TidyProvider, IsValidCheck) {
68EXPECT_TRUE(isRegisteredTidyCheck("bugprone-argument-comment"));
69EXPECT_FALSE(isRegisteredTidyCheck("bugprone-argument-clinic"));
70}
71#endif
72
73} // namespace
74} // namespace clangd
75} // namespace clang
76