[PATCH] D79552: [YAMLVFSWriter][Tests][NFC] Add couple tests

Jan Korous via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 22:08:50 PDT 2020


jkorous created this revision.
jkorous added a reviewer: JDevlieghere.
Herald added subscribers: llvm-commits, dexonsmith.
Herald added a project: LLVM.

I wrote a couple tests. Shall we add them?


https://reviews.llvm.org/D79552

Files:
  llvm/unittests/Support/VirtualFileSystemTest.cpp


Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===================================================================
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -2274,3 +2274,54 @@
   EXPECT_FALSE(FS->exists(AnotherEntry.Path + "/anotherentry"));
   EXPECT_FALSE(FS->exists(YetAnotherEntry.Path + "/yetanotherentry"));
 }
+
+TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestEmbeddedDirs) {
+  ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
+  ScopedDir a(TestDirectory + "/a");
+  ScopedDir a_aa(TestDirectory + "/a/aa");
+  ScopedDir b(TestDirectory + "/b");
+  ScopedDir b_bb(TestDirectory + "/b/bb");
+  ScopedDir c(TestDirectory + "/c");
+  ScopedDir c_cc(TestDirectory + "/c/cc");
+
+  vfs::YAMLVFSWriter VFSWriter;
+  VFSWriter.addDirectoryMapping(a.Path, "//root/a");
+  VFSWriter.addDirectoryMapping(a_aa.Path, "//root/a/aa");
+  VFSWriter.addDirectoryMapping(b.Path, "//root/b");
+  VFSWriter.addDirectoryMapping(b_bb.Path, "//root/b/bb");
+  VFSWriter.addDirectoryMapping(c.Path, "//root/c");
+  VFSWriter.addDirectoryMapping(c_cc.Path, "//root/c/cc");
+
+  std::string Buffer;
+  raw_string_ostream OS(Buffer);
+  VFSWriter.write(OS);
+  OS.flush();
+
+  IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
+  Lower->addDirectory("//root/a");
+  Lower->addDirectory("//root/a/aa");
+  Lower->addDirectory("//root/b");
+  Lower->addDirectory("//root/b/bb");
+  Lower->addDirectory("//root/c");
+  Lower->addDirectory("//root/c/cc");
+
+  IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
+  ASSERT_TRUE(FS.get() != nullptr);
+
+  EXPECT_TRUE(FS->exists(a.Path));
+  EXPECT_TRUE(FS->exists(a_aa.Path));
+  EXPECT_TRUE(FS->exists(b.Path));
+  EXPECT_TRUE(FS->exists(b_bb.Path));
+  EXPECT_TRUE(FS->exists(c.Path));
+  EXPECT_TRUE(FS->exists(c_cc.Path));
+}
+
+TEST(YAMLVFSWriterTest, HandleRootAsVPath) {
+  llvm::vfs::YAMLVFSWriter W;
+  W.addDirectoryMapping("/", "/tmp");
+  W.addDirectoryMapping("/foo", "/tmp/bar");
+  std::string Dump;
+  llvm::raw_string_ostream ToBeIgnored(Dump);
+
+  EXPECT_NO_FATAL_FAILURE(W.write(ToBeIgnored));
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79552.262545.patch
Type: text/x-patch
Size: 2191 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200507/7666c666/attachment.bin>


More information about the llvm-commits mailing list