clang-tools  9.0.0
FSTests.cpp
Go to the documentation of this file.
1 //===-- FSTests.cpp - File system related tests -----------------*- C++ -*-===//
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 "FS.h"
10 #include "TestFS.h"
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
13 
14 namespace clang {
15 namespace clangd {
16 namespace {
17 
18 TEST(FSTests, PreambleStatusCache) {
19  llvm::StringMap<std::string> Files;
20  Files["x"] = "";
21  Files["y"] = "";
22  Files["main"] = "";
23  auto FS = buildTestFS(Files);
24  FS->setCurrentWorkingDirectory(testRoot());
25 
26  PreambleFileStatusCache StatCache(testPath("main"));
27  auto ProduceFS = StatCache.getProducingFS(FS);
28  EXPECT_TRUE(ProduceFS->openFileForRead("x"));
29  EXPECT_TRUE(ProduceFS->status("y"));
30  EXPECT_TRUE(ProduceFS->status("main"));
31 
32  EXPECT_TRUE(StatCache.lookup(testPath("x")).hasValue());
33  EXPECT_TRUE(StatCache.lookup(testPath("y")).hasValue());
34  // Main file is not cached.
35  EXPECT_FALSE(StatCache.lookup(testPath("main")).hasValue());
36 
37  llvm::vfs::Status S("fake", llvm::sys::fs::UniqueID(123, 456),
38  std::chrono::system_clock::now(), 0, 0, 1024,
39  llvm::sys::fs::file_type::regular_file,
40  llvm::sys::fs::all_all);
41  StatCache.update(*FS, S);
42  auto ConsumeFS = StatCache.getConsumingFS(FS);
43  auto Cached = ConsumeFS->status(testPath("fake"));
44  EXPECT_TRUE(Cached);
45  EXPECT_EQ(Cached->getName(), testPath("fake"));
46  EXPECT_EQ(Cached->getUniqueID(), S.getUniqueID());
47 
48  // fake and temp/../fake should hit the same cache entry.
49  // However, the Status returned reflects the actual path requested.
50  auto CachedDotDot = ConsumeFS->status(testPath("temp/../fake"));
51  EXPECT_TRUE(CachedDotDot);
52  EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../fake"));
53  EXPECT_EQ(CachedDotDot->getUniqueID(), S.getUniqueID());
54 }
55 
56 } // namespace
57 } // namespace clangd
58 } // namespace clang
MockFSProvider FS
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > buildTestFS(llvm::StringMap< std::string > const &Files, llvm::StringMap< time_t > const &Timestamps)
Definition: TestFS.cpp:22
TEST(BackgroundQueueTest, Priority)
std::string testPath(PathRef File)
Definition: TestFS.cpp:82
const char * testRoot()
Definition: TestFS.cpp:74
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::StringMap< std::string > Files