Bump version to 19.1.0git
[llvm-project.git] / clang-tools-extra / clangd / unittests / TidyProviderTests.cpp
blob56b984c8e5333a80f166062a3efd3777c3ecddaf
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 //===----------------------------------------------------------------------===//
9 #include "Feature.h"
10 #include "TestFS.h"
11 #include "TidyProvider.h"
12 #include "llvm/Testing/Support/SupportHelpers.h"
13 #include "gtest/gtest.h"
15 namespace clang {
16 namespace clangd {
18 namespace {
20 TEST(TidyProvider, NestedDirectories) {
21 MockFS FS;
22 FS.Files[testPath(".clang-tidy")] = R"yaml(
23 Checks: 'llvm-*'
24 CheckOptions:
25 TestKey: 1
26 )yaml";
27 FS.Files[testPath("sub1/.clang-tidy")] = R"yaml(
28 Checks: 'misc-*'
29 CheckOptions:
30 TestKey: 2
31 )yaml";
32 FS.Files[testPath("sub1/sub2/.clang-tidy")] = R"yaml(
33 Checks: 'bugprone-*'
34 CheckOptions:
35 TestKey: 3
36 InheritParentConfig: true
37 )yaml";
39 TidyProvider Provider = provideClangTidyFiles(FS);
41 auto BaseOptions = getTidyOptionsForFile(Provider, testPath("File.cpp"));
42 ASSERT_TRUE(BaseOptions.Checks.has_value());
43 EXPECT_EQ(*BaseOptions.Checks, "llvm-*");
44 EXPECT_EQ(BaseOptions.CheckOptions.lookup("TestKey").Value, "1");
46 auto Sub1Options = getTidyOptionsForFile(Provider, testPath("sub1/File.cpp"));
47 ASSERT_TRUE(Sub1Options.Checks.has_value());
48 EXPECT_EQ(*Sub1Options.Checks, "misc-*");
49 EXPECT_EQ(Sub1Options.CheckOptions.lookup("TestKey").Value, "2");
51 auto Sub2Options =
52 getTidyOptionsForFile(Provider, testPath("sub1/sub2/File.cpp"));
53 ASSERT_TRUE(Sub2Options.Checks.has_value());
54 EXPECT_EQ(*Sub2Options.Checks, "misc-*,bugprone-*");
55 EXPECT_EQ(Sub2Options.CheckOptions.lookup("TestKey").Value, "3");
58 TEST(TidyProvider, IsFastTidyCheck) {
59 EXPECT_THAT(isFastTidyCheck("misc-const-correctness"), llvm::ValueIs(false));
60 EXPECT_THAT(isFastTidyCheck("bugprone-suspicious-include"),
61 llvm::ValueIs(true));
62 // Linked in (ParsedASTTests.cpp) but not measured.
63 EXPECT_EQ(isFastTidyCheck("replay-preamble-check"), std::nullopt);
66 #if CLANGD_TIDY_CHECKS
67 TEST(TidyProvider, IsValidCheck) {
68 EXPECT_TRUE(isRegisteredTidyCheck("bugprone-argument-comment"));
69 EXPECT_FALSE(isRegisteredTidyCheck("bugprone-argument-clinic"));
71 #endif
73 } // namespace
74 } // namespace clangd
75 } // namespace clang