1 //===-- TidyProviderTests.cpp - Clang tidy configuration provider tests ---===//
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
7 //===----------------------------------------------------------------------===//
11 #include "TidyProvider.h"
12 #include "llvm/Testing/Support/SupportHelpers.h"
13 #include "gtest/gtest.h"
20 TEST(TidyProvider
, NestedDirectories
) {
22 FS
.Files
[testPath(".clang-tidy")] = R
"yaml(
27 FS
.Files
[testPath("sub1/.clang-tidy")] = R
"yaml(
32 FS
.Files
[testPath("sub1/sub2/.clang-tidy")] = R
"yaml(
36 InheritParentConfig: true
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");
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"),
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"));