1d725f1ceSNathan James //===---- ObjCModuleTest.cpp - clang-tidy ---------------------------------===//
2d725f1ceSNathan James //
3d725f1ceSNathan James // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4d725f1ceSNathan James // See https://llvm.org/LICENSE.txt for license information.
5d725f1ceSNathan James // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d725f1ceSNathan James //
7d725f1ceSNathan James //===----------------------------------------------------------------------===//
8d725f1ceSNathan James
9d725f1ceSNathan James #include "ClangTidyOptions.h"
10d725f1ceSNathan James #include "clang/Basic/LLVM.h"
11d725f1ceSNathan James #include "llvm/Support/MemoryBuffer.h"
12d725f1ceSNathan James #include "llvm/Support/VirtualFileSystem.h"
13d725f1ceSNathan James #include "gtest/gtest.h"
14d725f1ceSNathan James
15d725f1ceSNathan James namespace clang {
16d725f1ceSNathan James namespace tidy {
17d725f1ceSNathan James namespace test {
18d725f1ceSNathan James
TEST(ClangTidyOptionsProvider,InMemoryFileSystems)19d725f1ceSNathan James TEST(ClangTidyOptionsProvider, InMemoryFileSystems) {
20d725f1ceSNathan James llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> FileSystem(
21d725f1ceSNathan James new llvm::vfs::InMemoryFileSystem);
22d725f1ceSNathan James
23d725f1ceSNathan James StringRef BaseClangTidy = R"(
24d725f1ceSNathan James Checks: -*,clang-diagnostic-*
25d725f1ceSNathan James )";
26d725f1ceSNathan James StringRef Sub1ClangTidy = R"(
27d725f1ceSNathan James Checks: readability-*
28d725f1ceSNathan James InheritParentConfig: true
29d725f1ceSNathan James )";
30d725f1ceSNathan James StringRef Sub2ClangTidy = R"(
31d725f1ceSNathan James Checks: bugprone-*,misc-*,clang-diagnostic-*
32d725f1ceSNathan James InheritParentConfig: false
33d725f1ceSNathan James )";
34d725f1ceSNathan James FileSystem->addFile("ProjectRoot/.clang-tidy", 0,
35d725f1ceSNathan James llvm::MemoryBuffer::getMemBuffer(BaseClangTidy));
36d725f1ceSNathan James FileSystem->addFile("ProjectRoot/SubDir1/.clang-tidy", 0,
37d725f1ceSNathan James llvm::MemoryBuffer::getMemBuffer(Sub1ClangTidy));
38d725f1ceSNathan James FileSystem->addFile("ProjectRoot/SubDir1/File.cpp", 0,
39d725f1ceSNathan James llvm::MemoryBuffer::getMemBuffer(""));
40d725f1ceSNathan James FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/.clang-tidy", 0,
41d725f1ceSNathan James llvm::MemoryBuffer::getMemBuffer(Sub2ClangTidy));
42d725f1ceSNathan James FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/File.cpp", 0,
43d725f1ceSNathan James llvm::MemoryBuffer::getMemBuffer(""));
44d725f1ceSNathan James FileSystem->addFile("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp", 0,
45d725f1ceSNathan James llvm::MemoryBuffer::getMemBuffer(""));
46d725f1ceSNathan James
47d725f1ceSNathan James FileOptionsProvider FileOpt({}, {}, {}, FileSystem);
48d725f1ceSNathan James
49d725f1ceSNathan James ClangTidyOptions File1Options =
50d725f1ceSNathan James FileOpt.getOptions("ProjectRoot/SubDir1/File.cpp");
51d725f1ceSNathan James ClangTidyOptions File2Options =
52d725f1ceSNathan James FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/File.cpp");
53d725f1ceSNathan James ClangTidyOptions File3Options =
54d725f1ceSNathan James FileOpt.getOptions("ProjectRoot/SubDir1/SubDir2/SubDir3/File.cpp");
55d725f1ceSNathan James
56*53daa177SKazu Hirata ASSERT_TRUE(File1Options.Checks.has_value());
57d725f1ceSNathan James EXPECT_EQ(*File1Options.Checks, "-*,clang-diagnostic-*,readability-*");
58*53daa177SKazu Hirata ASSERT_TRUE(File2Options.Checks.has_value());
59d725f1ceSNathan James EXPECT_EQ(*File2Options.Checks, "bugprone-*,misc-*,clang-diagnostic-*");
60d725f1ceSNathan James
61d725f1ceSNathan James // 2 and 3 should use the same config so these should also be the same.
62d725f1ceSNathan James EXPECT_EQ(File2Options.Checks, File3Options.Checks);
63d725f1ceSNathan James }
64d725f1ceSNathan James
65d725f1ceSNathan James } // namespace test
66d725f1ceSNathan James } // namespace tidy
67d725f1ceSNathan James } // namespace clang
68