summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorBen Hamilton <benhamilton@google.com>2017-11-16 19:34:08 +0000
committerBen Hamilton <benhamilton@google.com>2017-11-16 19:34:08 +0000
commit0c858e9e12a1d03b851ae5e3f05d7a45d2055374 (patch)
tree42291de1939717ef06a93466fde5ca65b396edfc /unittests
parent66d04356461847b5172092ea960a3583379307c9 (diff)
[VirtualFileSystem] Support creating directories then adding files inside
Summary: In https://reviews.llvm.org/D39572 , I added support for specifying `Type` when invoking `InMemoryFileSystem::addFile()`. However, I didn't account for the fact that when `Type` is `directory_file`, we need to construct an `InMemoryDirectory`, not an `InMemoryFile`, or else clients cannot create files inside that directory. This diff fixes the bug and adds a test. Test Plan: New test added. Ran test with: % make -j12 check-clang-tools Reviewers: bkramer, hokein Reviewed By: bkramer Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D40140 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318445 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Basic/VirtualFileSystemTest.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp
index 513e812576..f9efbeaee5 100644
--- a/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/unittests/Basic/VirtualFileSystemTest.cpp
@@ -829,6 +829,19 @@ TEST_F(InMemoryFileSystemTest, AddFileWithPerms) {
Stat->getPermissions());
}
+TEST_F(InMemoryFileSystemTest, AddDirectoryThenAddChild) {
+ FS.addFile("/a", 0, MemoryBuffer::getMemBuffer(""), /*User=*/None,
+ /*Group=*/None, sys::fs::file_type::directory_file);
+ FS.addFile("/a/b", 0, MemoryBuffer::getMemBuffer("abc"), /*User=*/None,
+ /*Group=*/None, sys::fs::file_type::regular_file);
+ auto Stat = FS.status("/a");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isDirectory());
+ Stat = FS.status("/a/b");
+ ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
+ ASSERT_TRUE(Stat->isRegularFile());
+}
+
// 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 {