]> granicus.if.org Git - clang/commitdiff
[VFS] Put the incoming name in the file status to make InMemoryFS behave more like...
authorBenjamin Kramer <benny.kra@googlemail.com>
Tue, 6 Oct 2015 14:45:16 +0000 (14:45 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Tue, 6 Oct 2015 14:45:16 +0000 (14:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249409 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/VirtualFileSystem.cpp
unittests/Basic/VirtualFileSystemTest.cpp

index 5486331d4af3c3953d643e489827356c00e1ba54..b3805b2ff9203a904a0f806e39904f8b7b4ad5ab 100644 (file)
@@ -501,7 +501,7 @@ void InMemoryFileSystem::addFile(const Twine &P, time_t ModificationTime,
       if (I == E) {
         // End of the path, create a new file.
         // FIXME: expose the status details in the interface.
-        Status Stat(Path, getNextVirtualUniqueID(),
+        Status Stat(P.str(), getNextVirtualUniqueID(),
                     llvm::sys::TimeValue(ModificationTime, 0), 0, 0,
                     Buffer->getBufferSize(),
                     llvm::sys::fs::file_type::regular_file,
index 0b767dd0c8de1da9921c1c41dc7bd12b2e6706ef..005737e9de33e545e108d5d61bc71ab174364592 100644 (file)
@@ -602,6 +602,19 @@ TEST_F(InMemoryFileSystemTest, DirectoryIteration) {
   ASSERT_EQ(vfs::directory_iterator(), I);
 }
 
+TEST_F(InMemoryFileSystemTest, WorkingDirectory) {
+  FS.setCurrentWorkingDirectory("/b");
+  FS.addFile("c", 0, MemoryBuffer::getMemBuffer(""));
+
+  auto Stat = FS.status("/b/c");
+  ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+  ASSERT_EQ("c", Stat->getName());
+  ASSERT_EQ("/b", *FS.getCurrentWorkingDirectory());
+
+  Stat = FS.status("c");
+  ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+}
+
 // NOTE: in the tests below, we use '//root/' as our root directory, since it is
 // a legal *absolute* path on Windows as well as *nix.
 class VFSFromYAMLTest : public ::testing::Test {