| 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 | TestKey: 1 |
| 24 | )yaml"; |
| 25 | FS.Files[testPath("sub1/.clang-tidy")] = R"yaml( |
| 26 | Checks: 'misc-*' |
| 27 | CheckOptions: |
| 28 | TestKey: 2 |
| 29 | )yaml"; |
| 30 | FS.Files[testPath("sub1/sub2/.clang-tidy")] = R"yaml( |
| 31 | Checks: 'bugprone-*' |
| 32 | CheckOptions: |
| 33 | TestKey: 3 |
| 34 | InheritParentConfig: true |
| 35 | )yaml"; |
| 36 | |
| 37 | TidyProvider Provider = provideClangTidyFiles(FS); |
| 38 | |
| 39 | auto BaseOptions = getTidyOptionsForFile(Provider, testPath("File.cpp")); |
| 40 | ASSERT_TRUE(BaseOptions.Checks.has_value()); |
| 41 | EXPECT_EQ(*BaseOptions.Checks, "llvm-*"); |
| 42 | EXPECT_EQ(BaseOptions.CheckOptions.lookup("TestKey").Value, "1"); |
| 43 | |
| 44 | auto Sub1Options = getTidyOptionsForFile(Provider, testPath("sub1/File.cpp")); |
| 45 | ASSERT_TRUE(Sub1Options.Checks.has_value()); |
| 46 | EXPECT_EQ(*Sub1Options.Checks, "misc-*"); |
| 47 | EXPECT_EQ(Sub1Options.CheckOptions.lookup("TestKey").Value, "2"); |
| 48 | |
| 49 | auto Sub2Options = |
| 50 | getTidyOptionsForFile(Provider, testPath("sub1/sub2/File.cpp")); |
| 51 | ASSERT_TRUE(Sub2Options.Checks.has_value()); |
| 52 | EXPECT_EQ(*Sub2Options.Checks, "misc-*,bugprone-*"); |
| 53 | EXPECT_EQ(Sub2Options.CheckOptions.lookup("TestKey").Value, "3"); |
| 54 | } |
| 55 | } // namespace |
| 56 | } // namespace clangd |
| 57 | } // namespace clang |