Clang: Watch directories instead of files

Because there a limited resources to watch files we watch now directories.
So we need much less resources.

Change-Id: Iac558832e9521a7a1a67c5ea99b42ad1b0b5129c
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2019-06-06 10:57:55 +02:00
parent 9d290fc682
commit bbd58ca30b
38 changed files with 1485 additions and 541 deletions

View File

@@ -31,6 +31,7 @@
namespace {
using ClangBackEnd::DirectoryPathId;
using ClangBackEnd::FilePathId;
using Cache = ClangBackEnd::FilePathCache<NiceMock<MockFilePathStorage>>;
using ClangBackEnd::FilePathId;
@@ -166,4 +167,153 @@ TEST_F(FilePathCache, DuplicateFilePathsAreEqual)
ASSERT_THAT(filePath2Id, Eq(filePath1Id));
}
TEST_F(FilePathCache, DirectoryPathIdCallsFetchDirectoryId)
{
EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to")));
cache.directoryPathId(Utils::SmallString("/path/to"));
}
TEST_F(FilePathCache, SecondDirectoryPathIdCallsNotFetchDirectoryId)
{
cache.directoryPathId(Utils::SmallString("/path/to"));
EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to"))).Times(0);
cache.directoryPathId(Utils::SmallString("/path/to"));
}
TEST_F(FilePathCache, DirectoryPathIdWithTrailingSlash)
{
EXPECT_CALL(mockStorage, fetchDirectoryId(Eq("/path/to")));
cache.directoryPathId(Utils::SmallString("/path/to/"));
}
TEST_F(FilePathCache, DirectoryPathId)
{
auto id = cache.directoryPathId(Utils::SmallString("/path/to"));
ASSERT_THAT(id, Eq(DirectoryPathId{5}));
}
TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCache)
{
auto firstId = cache.directoryPathId(Utils::SmallString("/path/to"));
auto secondId = cache.directoryPathId(Utils::SmallString("/path/to"));
ASSERT_THAT(secondId, firstId);
}
TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCacheWithTrailingSlash)
{
auto firstId = cache.directoryPathId(Utils::SmallString("/path/to/"));
auto secondId = cache.directoryPathId(Utils::SmallString("/path/to/"));
ASSERT_THAT(secondId, firstId);
}
TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCacheWithAndWithoutTrailingSlash)
{
auto firstId = cache.directoryPathId(Utils::SmallString("/path/to/"));
auto secondId = cache.directoryPathId(Utils::SmallString("/path/to"));
ASSERT_THAT(secondId, firstId);
}
TEST_F(FilePathCache, DirectoryPathIdIsAlreadyInCacheWithoutAndWithTrailingSlash)
{
auto firstId = cache.directoryPathId(Utils::SmallString("/path/to"));
auto secondId = cache.directoryPathId(Utils::SmallString("/path/to/"));
ASSERT_THAT(secondId, firstId);
}
TEST_F(FilePathCache, ThrowForGettingADirectoryPathWithAnInvalidId)
{
DirectoryPathId directoryPathId;
ASSERT_THROW(cache.directoryPath(directoryPathId),
ClangBackEnd::NoDirectoryPathForInvalidDirectoryPathId);
}
TEST_F(FilePathCache, GetADirectoryPath)
{
DirectoryPathId directoryPathId{5};
auto directoryPath = cache.directoryPath(directoryPathId);
ASSERT_THAT(directoryPath, Eq(Utils::SmallStringView{"/path/to"}));
}
TEST_F(FilePathCache, GetADirectoryPathWithCachedDirectoryPathId)
{
DirectoryPathId directoryPathId{5};
cache.directoryPath(directoryPathId);
auto directoryPath = cache.directoryPath(directoryPathId);
ASSERT_THAT(directoryPath, Eq(Utils::SmallStringView{"/path/to"}));
}
TEST_F(FilePathCache, DirectoryPathCallsFetchDirectoryPath)
{
EXPECT_CALL(mockStorage, fetchDirectoryPath(Eq(DirectoryPathId{5})));
cache.directoryPath(5);
}
TEST_F(FilePathCache, SecondDirectoryPathCallsNotFetchDirectoryPath)
{
cache.directoryPath(5);
EXPECT_CALL(mockStorage, fetchDirectoryPath(_)).Times(0);
cache.directoryPath(5);
}
TEST_F(FilePathCache, ThrowForGettingADirectoryPathIdWithAnInvalidFilePathId)
{
FilePathId filePathId;
ASSERT_THROW(cache.directoryPathId(filePathId), ClangBackEnd::NoFilePathForInvalidFilePathId);
}
TEST_F(FilePathCache, FetchDirectoryPathIdByFilePathId)
{
auto directoryId = cache.directoryPathId(42);
ASSERT_THAT(directoryId, Eq(5));
}
TEST_F(FilePathCache, FetchDirectoryPathIdByFilePathIdCached)
{
cache.directoryPathId(42);
auto directoryId = cache.directoryPathId(42);
ASSERT_THAT(directoryId, Eq(5));
}
TEST_F(FilePathCache, FetchFilePathAfterFetchingDirectoryIdByFilePathId)
{
cache.directoryPathId(42);
auto filePath = cache.filePath(42);
ASSERT_THAT(filePath, Eq("/path/to/file.cpp"));
}
TEST_F(FilePathCache, FetchDirectoryPathIdAfterFetchingFilePathByFilePathId)
{
cache.filePath(42);
auto directoryId = cache.directoryPathId(42);
ASSERT_THAT(directoryId, Eq(5));
}
} // namespace