From: Jonas Devlieghere Date: Tue, 12 May 2020 21:55:17 +0000 (-0700) Subject: [VirtualFileSystem] Add unit test that showcases another YAMLVFSWriter bug X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58bc507b6fe6c6276a7c858a7d1de83ca02e999e;p=platform%2Fupstream%2Fllvm.git [VirtualFileSystem] Add unit test that showcases another YAMLVFSWriter bug This scenario generates another broken YAML mapping as illustrated below. { 'type': 'directory', 'name': "c", 'contents': [ , { 'type': 'directory', 'name': "d", 'contents': [ , { 'type': 'directory', 'name': "e", 'contents': [ { 'type': 'file', 'name': "f", 'external-contents': "//root/a/c/d/e/f" } { 'type': 'file', 'name': "g", 'external-contents': "//root/a/c/d/e/g" } ] } ] } ] }, --- diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index 7c35710..5e314f7 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -2271,6 +2271,40 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) { EXPECT_FALSE(FS.get() != nullptr); } +TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) { + ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); + ScopedDir _a(TestDirectory + "/a"); + ScopedFile _ab(TestDirectory + "/a/b", ""); + ScopedDir _ac(TestDirectory + "/a/c"); + ScopedDir _acd(TestDirectory + "/a/c/d"); + ScopedDir _acde(TestDirectory + "/a/c/d/e"); + ScopedFile _acdef(TestDirectory + "/a/c/d/e/f", ""); + ScopedFile _acdeg(TestDirectory + "/a/c/d/e/g", ""); + ScopedDir _ah(TestDirectory + "/a/h"); + ScopedFile _ahi(TestDirectory + "/a/h/i", ""); + + vfs::YAMLVFSWriter VFSWriter; + VFSWriter.addDirectoryMapping(_a.Path, "//root/a"); + VFSWriter.addFileMapping(_ab.Path, "//root/a/b"); + VFSWriter.addDirectoryMapping(_ac.Path, "//root/a/c"); + VFSWriter.addDirectoryMapping(_acd.Path, "//root/a/c/d"); + VFSWriter.addDirectoryMapping(_acde.Path, "//root/a/c/d/e"); + VFSWriter.addFileMapping(_acdef.Path, "//root/a/c/d/e/f"); + VFSWriter.addFileMapping(_acdeg.Path, "//root/a/c/d/e/g"); + VFSWriter.addDirectoryMapping(_ahi.Path, "//root/a/h"); + VFSWriter.addFileMapping(_ahi.Path, "//root/a/h/i"); + + std::string Buffer; + raw_string_ostream OS(Buffer); + VFSWriter.write(OS); + OS.flush(); + + IntrusiveRefCntPtr Lower(new ErrorDummyFileSystem()); + IntrusiveRefCntPtr FS = getFromYAMLRawString(Buffer, Lower); + // FIXME: Spurious comma separator before first file entry in directory. + EXPECT_FALSE(FS.get() != nullptr); +} + TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) { ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); ScopedDir _a(TestDirectory + "/a");