2018-10-02 10:43:55 +00:00
|
|
|
//===-- FSTests.cpp - File system related tests -----------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-10-02 10:43:55 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "FS.h"
|
|
|
|
#include "TestFS.h"
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
TEST(FSTests, PreambleStatusCache) {
|
2019-01-07 15:45:19 +00:00
|
|
|
llvm::StringMap<std::string> Files;
|
2018-10-02 10:43:55 +00:00
|
|
|
Files["x"] = "";
|
|
|
|
Files["y"] = "";
|
2018-10-09 08:27:31 +00:00
|
|
|
Files["main"] = "";
|
2018-10-02 10:43:55 +00:00
|
|
|
auto FS = buildTestFS(Files);
|
|
|
|
|
2018-10-09 08:27:31 +00:00
|
|
|
PreambleFileStatusCache StatCache(testPath("main"));
|
2018-10-02 10:43:55 +00:00
|
|
|
auto ProduceFS = StatCache.getProducingFS(FS);
|
|
|
|
EXPECT_TRUE(ProduceFS->openFileForRead("x"));
|
|
|
|
EXPECT_TRUE(ProduceFS->status("y"));
|
2018-10-09 08:27:31 +00:00
|
|
|
EXPECT_TRUE(ProduceFS->status("main"));
|
2018-10-02 10:43:55 +00:00
|
|
|
|
2022-07-12 22:47:41 -07:00
|
|
|
EXPECT_TRUE(StatCache.lookup(testPath("x")).has_value());
|
|
|
|
EXPECT_TRUE(StatCache.lookup(testPath("y")).has_value());
|
2018-10-09 08:27:31 +00:00
|
|
|
// Main file is not cached.
|
2022-07-12 22:47:41 -07:00
|
|
|
EXPECT_FALSE(StatCache.lookup(testPath("main")).has_value());
|
2018-10-02 10:43:55 +00:00
|
|
|
|
2019-07-01 10:11:18 +00:00
|
|
|
llvm::vfs::Status S("fake", llvm::sys::fs::UniqueID(123, 456),
|
2019-01-07 15:45:19 +00:00
|
|
|
std::chrono::system_clock::now(), 0, 0, 1024,
|
|
|
|
llvm::sys::fs::file_type::regular_file,
|
|
|
|
llvm::sys::fs::all_all);
|
2023-05-23 09:47:57 +02:00
|
|
|
StatCache.update(*FS, S, "real");
|
2018-10-02 10:43:55 +00:00
|
|
|
auto ConsumeFS = StatCache.getConsumingFS(FS);
|
2023-05-23 09:47:57 +02:00
|
|
|
EXPECT_FALSE(ConsumeFS->status(testPath("fake")));
|
|
|
|
auto Cached = ConsumeFS->status(testPath("real"));
|
2018-10-02 10:43:55 +00:00
|
|
|
EXPECT_TRUE(Cached);
|
2023-05-23 09:47:57 +02:00
|
|
|
EXPECT_EQ(Cached->getName(), testPath("real"));
|
2019-07-01 10:11:18 +00:00
|
|
|
EXPECT_EQ(Cached->getUniqueID(), S.getUniqueID());
|
|
|
|
|
2023-05-23 09:47:57 +02:00
|
|
|
// real and temp/../real should hit the same cache entry.
|
2019-07-01 10:11:18 +00:00
|
|
|
// However, the Status returned reflects the actual path requested.
|
2023-05-23 09:47:57 +02:00
|
|
|
auto CachedDotDot = ConsumeFS->status(testPath("temp/../real"));
|
2019-07-01 10:11:18 +00:00
|
|
|
EXPECT_TRUE(CachedDotDot);
|
2023-05-23 09:47:57 +02:00
|
|
|
EXPECT_EQ(CachedDotDot->getName(), testPath("temp/../real"));
|
2019-07-01 10:11:18 +00:00
|
|
|
EXPECT_EQ(CachedDotDot->getUniqueID(), S.getUniqueID());
|
2018-10-02 10:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|