[llvm] 42df3e2 - [VirtualFileSystem] Add unit test for vfs::YAMLVFSWriter
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 23 18:49:14 PDT 2020
Author: Jonas Devlieghere
Date: 2020-03-23T18:49:06-07:00
New Revision: 42df3e298561e875f621f305ecb76e233c497f84
URL: https://github.com/llvm/llvm-project/commit/42df3e298561e875f621f305ecb76e233c497f84
DIFF: https://github.com/llvm/llvm-project/commit/42df3e298561e875f621f305ecb76e233c497f84.diff
LOG: [VirtualFileSystem] Add unit test for vfs::YAMLVFSWriter
Add a unit test for vfs::YAMLVFSWriter.
This patch exposes an issue in the writer: when we call addFileMapping
with a directory, the VFS writer will emit it as a regular file, causing
any of the nested files or directories to not be found.
Added:
Modified:
llvm/unittests/Support/VirtualFileSystemTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp
index acd526409f2f..8ac454b511e8 100644
--- a/llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -2188,3 +2188,59 @@ TEST_F(VFSFromYAMLTest, WorkingDirectoryFallthroughInvalid) {
Status = FS->status("foo/a");
ASSERT_TRUE(Status.getError());
}
+
+TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest) {
+ ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
+ ScopedDir _a(TestDirectory + "/a");
+ ScopedFile _ab(TestDirectory + "/a/b", "");
+ ScopedDir _c(TestDirectory + "/c");
+ ScopedFile _cd(TestDirectory + "/c/d", "");
+ ScopedDir _e(TestDirectory + "/e");
+ ScopedDir _ef(TestDirectory + "/e/f");
+ ScopedDir _g(TestDirectory + "/g");
+ ScopedFile _h(TestDirectory + "/h", "");
+
+ // This test exposes a bug/shortcoming in the YAMLVFSWriter. Below we call
+ // addFileMapping for _a and _e, which causes _ab and _ef not to exists in
+ // the deserialized file system, because _a and _e got emitted as regular
+ // files. The counter example is _c, if we only call addFileMapping for _cd,
+ // things work as expected.
+
+ vfs::YAMLVFSWriter VFSWriter;
+ VFSWriter.addFileMapping(_a.Path, "//root/a");
+ VFSWriter.addFileMapping(_ab.Path, "//root/a/b");
+ VFSWriter.addFileMapping(_cd.Path, "//root/c/d");
+ VFSWriter.addFileMapping(_e.Path, "//root/e");
+ VFSWriter.addFileMapping(_ef.Path, "//root/e/f");
+ VFSWriter.addFileMapping(_g.Path, "//root/g");
+ VFSWriter.addFileMapping(_h.Path, "//root/h");
+
+ std::string Buffer;
+ raw_string_ostream OS(Buffer);
+ VFSWriter.write(OS);
+ OS.flush();
+
+ IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
+ Lower->addDirectory("//root/");
+ Lower->addDirectory("//root/a");
+ Lower->addRegularFile("//root/a/b");
+ Lower->addDirectory("//root/b");
+ Lower->addDirectory("//root/c");
+ Lower->addRegularFile("//root/c/d");
+ Lower->addDirectory("//root/e");
+ Lower->addDirectory("//root/e/f");
+ Lower->addDirectory("//root/g");
+ Lower->addRegularFile("//root/h");
+
+ IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
+ ASSERT_TRUE(FS.get() != nullptr);
+
+ EXPECT_TRUE(FS->exists(_a.Path));
+ EXPECT_FALSE(FS->exists(_ab.Path)); // FIXME: See explanation above.
+ EXPECT_TRUE(FS->exists(_c.Path));
+ EXPECT_TRUE(FS->exists(_cd.Path));
+ EXPECT_TRUE(FS->exists(_e.Path));
+ EXPECT_FALSE(FS->exists(_ef.Path)); // FIXME: See explanation above.
+ EXPECT_TRUE(FS->exists(_g.Path));
+ EXPECT_TRUE(FS->exists(_h.Path));
+}
More information about the llvm-commits
mailing list