From 59ba19c56e1cf6d01e6acce1bf405a57f19c340c Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Tue, 12 May 2020 14:46:23 -0700 Subject: [VirtualFileSystem] Add unit test that showcases YAMLVFSWriter bug This scenario generates a broken YAML mapping as illustrated below. { 'type': 'directory', 'name': "c", 'contents': [ { 'type': 'file', 'name': "d", 'external-contents': "//root/a/c/d" } { 'type': 'file', 'name': "e", 'external-contents': "//root/a/c/e" } { 'type': 'file', 'name': "f", 'external-contents': "//root/a/c/f" } ] }, --- llvm/unittests/Support/VirtualFileSystemTest.cpp | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp') diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index 8c08cb1..7c35710 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -2239,6 +2239,38 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest) { EXPECT_TRUE(FS->exists(_h.Path)); } +TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) { + ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); + ScopedDir _a(TestDirectory + "/a"); + ScopedFile _ab(TestDirectory + "/a/b", ""); + ScopedDir _ac(TestDirectory + "/a/c"); + ScopedFile _acd(TestDirectory + "/a/c/d", ""); + ScopedFile _ace(TestDirectory + "/a/c/e", ""); + ScopedFile _acf(TestDirectory + "/a/c/f", ""); + ScopedDir _ag(TestDirectory + "/a/g"); + ScopedFile _agh(TestDirectory + "/a/g/h", ""); + + vfs::YAMLVFSWriter VFSWriter; + VFSWriter.addDirectoryMapping(_a.Path, "//root/a"); + VFSWriter.addFileMapping(_ab.Path, "//root/a/b"); + VFSWriter.addDirectoryMapping(_ac.Path, "//root/a/c"); + VFSWriter.addFileMapping(_acd.Path, "//root/a/c/d"); + VFSWriter.addFileMapping(_ace.Path, "//root/a/c/e"); + VFSWriter.addFileMapping(_acf.Path, "//root/a/c/f"); + VFSWriter.addDirectoryMapping(_ag.Path, "//root/a/g"); + VFSWriter.addFileMapping(_agh.Path, "//root/a/g/h"); + + std::string Buffer; + raw_string_ostream OS(Buffer); + VFSWriter.write(OS); + OS.flush(); + + IntrusiveRefCntPtr Lower(new ErrorDummyFileSystem()); + IntrusiveRefCntPtr FS = getFromYAMLRawString(Buffer, Lower); + // FIXME: Missing comma separator between file entries. + EXPECT_FALSE(FS.get() != nullptr); +} + TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) { ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); ScopedDir _a(TestDirectory + "/a"); -- cgit v1.1