[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"
              }
            ]
          }
        ]
      }
    ]
  },
This commit is contained in:
Jonas Devlieghere 2020-05-12 14:55:17 -07:00
parent 59ba19c56e
commit 58bc507b6f
1 changed files with 34 additions and 0 deletions

View File

@ -2271,6 +2271,40 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) {
EXPECT_FALSE(FS.get() != nullptr); 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<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
// FIXME: Spurious comma separator before first file entry in directory.
EXPECT_FALSE(FS.get() != nullptr);
}
TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) { TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) {
ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
ScopedDir _a(TestDirectory + "/a"); ScopedDir _a(TestDirectory + "/a");