diff options
Diffstat (limited to 'clang/unittests/Basic')
-rw-r--r-- | clang/unittests/Basic/FileEntryTest.cpp | 6 | ||||
-rw-r--r-- | clang/unittests/Basic/FileManagerTest.cpp | 20 |
2 files changed, 25 insertions, 1 deletions
diff --git a/clang/unittests/Basic/FileEntryTest.cpp b/clang/unittests/Basic/FileEntryTest.cpp index b1755e0..0878063 100644 --- a/clang/unittests/Basic/FileEntryTest.cpp +++ b/clang/unittests/Basic/FileEntryTest.cpp @@ -9,6 +9,7 @@ #include "clang/Basic/FileEntry.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/StringMap.h" +#include "llvm/Support/Path.h" #include "gtest/gtest.h" using namespace llvm; @@ -51,11 +52,14 @@ public: .first); } FileEntryRef addFileRedirect(StringRef Name, FileEntryRef Base) { + auto Dir = addDirectory(llvm::sys::path::parent_path(Name)); + return FileEntryRef( *Files .insert({Name, FileEntryRef::MapValue( const_cast<FileEntryRef::MapEntry &>( - Base.getMapEntry()))}) + Base.getMapEntry()), + Dir)}) .first); } }; diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index 146a609..4c8205b 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -310,6 +310,26 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) { EXPECT_EQ(&F2->getFileEntry(), &F2Alias2->getFileEntry()); } +TEST_F(FileManagerTest, getFileRefReturnsCorrectDirNameForDifferentStatPath) { + // Inject files with the same inode into distinct directories (name & inode). + auto StatCache = std::make_unique<FakeStatCache>(); + StatCache->InjectDirectory("dir1", 40); + StatCache->InjectDirectory("dir2", 41); + StatCache->InjectFile("dir1/f.cpp", 42); + StatCache->InjectFile("dir2/f.cpp", 42, "dir1/f.cpp"); + + manager.setStatCache(std::move(StatCache)); + auto Dir1F = manager.getFileRef("dir1/f.cpp"); + auto Dir2F = manager.getFileRef("dir2/f.cpp"); + + ASSERT_FALSE(!Dir1F); + ASSERT_FALSE(!Dir2F); + EXPECT_EQ("dir1", Dir1F->getDir().getName()); + EXPECT_EQ("dir2", Dir2F->getDir().getName()); + EXPECT_EQ("dir1/f.cpp", Dir1F->getNameAsRequested()); + EXPECT_EQ("dir2/f.cpp", Dir2F->getNameAsRequested()); +} + // getFile() returns the same FileEntry for virtual files that have // corresponding real files that are aliases. TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedVirtualFiles) { |