Bump version to 19.1.0git
[llvm-project.git] / clang-tools-extra / unittests / clang-tidy / OptionsProviderTest.cpp
blob5aa3730ac5ccf8932434e55b6785ce7040f7a1b7
1 //===---- ObjCModuleTest.cpp - clang-tidy ---------------------------------===//
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 "ClangTidyOptions.h"
10 #include "clang/Basic/LLVM.h"
11 #include "llvm/Support/MemoryBuffer.h"
12 #include "llvm/Support/VirtualFileSystem.h"
13 #include "gtest/gtest.h"
15 namespace clang {
16 namespace tidy {
17 namespace test {
19 TEST(ClangTidyOptionsProvider, InMemoryFileSystems) {
20 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FileSystem(
21 new llvm::vfs::InMemoryFileSystem);
23 StringRef BaseClangTidy = R"(
24 Checks: -*,clang-diagnostic-*
25 )";
26 StringRef Sub1ClangTidy = R"(
27 Checks: readability-*
28 InheritParentConfig: true
29 )";
30 StringRef Sub2ClangTidy = R"(
31 Checks: bugprone-*,misc-*,clang-diagnostic-*
32 InheritParentConfig: false
33 )";
34 FileSystem->addFile("ProjectRoot/.clang-tidy", 0,
35 llvm::MemoryBuffer::getMemBuffer(BaseClangTidy));
36 FileSystem->addFile("ProjectRoot/SubDir1/.clang-tidy", 0,
37 llvm::MemoryBuffer::getMemBuffer(Sub1ClangTidy));
38 FileSystem->addFile("ProjectRoot/SubDir1/File.cpp", 0,
39 llvm::MemoryBuffer::getMemBuffer(""));
40 FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/.clang-tidy", 0,
41 llvm::MemoryBuffer::getMemBuffer(Sub2ClangTidy));
42 FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/File.cpp", 0,
43 llvm::MemoryBuffer::getMemBuffer(""));
44 FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp", 0,
45 llvm::MemoryBuffer::getMemBuffer(""));
47 FileOptionsProvider FileOpt({}, {}, {}, FileSystem);
49 ClangTidyOptions File1Options =
50 FileOpt.getOptions("ProjectRoot/SubDir1/File.cpp");
51 ClangTidyOptions File2Options =
52 FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/File.cpp");
53 ClangTidyOptions File3Options =
54 FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp");
56 ASSERT_TRUE(File1Options.Checks.has_value());
57 EXPECT_EQ(*File1Options.Checks, "-*,clang-diagnostic-*,readability-*");
58 ASSERT_TRUE(File2Options.Checks.has_value());
59 EXPECT_EQ(*File2Options.Checks, "bugprone-*,misc-*,clang-diagnostic-*");
61 // 2 and 3 should use the same config so these should also be the same.
62 EXPECT_EQ(File2Options.Checks, File3Options.Checks);
65 } // namespace test
66 } // namespace tidy
67 } // namespace clang