clang-tools  14.0.0git
TidyProviderTests.cpp
Go to the documentation of this file.
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 "TestFS.h"
10 #include "TidyProvider.h"
11 #include "gtest/gtest.h"
12 
13 namespace clang {
14 namespace clangd {
15 
16 namespace {
17 
18 TEST(TidyProvider, NestedDirectories) {
19  MockFS FS;
20  FS.Files[testPath(".clang-tidy")] = R"yaml(
21  Checks: 'llvm-*'
22  CheckOptions:
23  - key: TestKey
24  value: 1
25 )yaml";
26  FS.Files[testPath("sub1/.clang-tidy")] = R"yaml(
27  Checks: 'misc-*'
28  CheckOptions:
29  - key: TestKey
30  value: 2
31 )yaml";
32  FS.Files[testPath("sub1/sub2/.clang-tidy")] = R"yaml(
33  Checks: 'bugprone-*'
34  CheckOptions:
35  - key: TestKey
36  value: 3
37  InheritParentConfig: true
38 )yaml";
39 
40  TidyProvider Provider = provideClangTidyFiles(FS);
41 
42  auto BaseOptions = getTidyOptionsForFile(Provider, testPath("File.cpp"));
43  ASSERT_TRUE(BaseOptions.Checks.hasValue());
44  EXPECT_EQ(*BaseOptions.Checks, "llvm-*");
45  EXPECT_EQ(BaseOptions.CheckOptions.lookup("TestKey").Value, "1");
46 
47  auto Sub1Options = getTidyOptionsForFile(Provider, testPath("sub1/File.cpp"));
48  ASSERT_TRUE(Sub1Options.Checks.hasValue());
49  EXPECT_EQ(*Sub1Options.Checks, "misc-*");
50  EXPECT_EQ(Sub1Options.CheckOptions.lookup("TestKey").Value, "2");
51 
52  auto Sub2Options =
53  getTidyOptionsForFile(Provider, testPath("sub1/sub2/File.cpp"));
54  ASSERT_TRUE(Sub2Options.Checks.hasValue());
55  EXPECT_EQ(*Sub2Options.Checks, "misc-*,bugprone-*");
56  EXPECT_EQ(Sub2Options.CheckOptions.lookup("TestKey").Value, "3");
57 }
58 } // namespace
59 } // namespace clangd
60 } // namespace clang
clang::clangd::TEST
TEST(BackgroundQueueTest, Priority)
Definition: BackgroundIndexTests.cpp:751
clang::clangd::testPath
std::string testPath(PathRef File, llvm::sys::path::Style Style)
Definition: TestFS.cpp:82
clang::clangd::getTidyOptionsForFile
tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider, llvm::StringRef Filename)
Definition: TidyProvider.cpp:279
clang::clangd::provideClangTidyFiles
TidyProvider provideClangTidyFiles(ThreadsafeFS &TFS)
Provider that searches for .clang-tidy configuration files in the directory tree.
Definition: TidyProvider.cpp:261
TidyProvider.h
clang::clangd::TidyProvider
llvm::unique_function< void(tidy::ClangTidyOptions &, llvm::StringRef) const > TidyProvider
A factory to modify a tidy::ClangTidyOptions.
Definition: TidyProvider.h:24
TestFS.h
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27