Skip to content

Commit 59ba19c

Browse files
committed
[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" } ] },
1 parent aa1eb51 commit 59ba19c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

llvm/unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,38 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest) {
22392239
EXPECT_TRUE(FS->exists(_h.Path));
22402240
}
22412241

2242+
TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) {
2243+
ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
2244+
ScopedDir _a(TestDirectory + "/a");
2245+
ScopedFile _ab(TestDirectory + "/a/b", "");
2246+
ScopedDir _ac(TestDirectory + "/a/c");
2247+
ScopedFile _acd(TestDirectory + "/a/c/d", "");
2248+
ScopedFile _ace(TestDirectory + "/a/c/e", "");
2249+
ScopedFile _acf(TestDirectory + "/a/c/f", "");
2250+
ScopedDir _ag(TestDirectory + "/a/g");
2251+
ScopedFile _agh(TestDirectory + "/a/g/h", "");
2252+
2253+
vfs::YAMLVFSWriter VFSWriter;
2254+
VFSWriter.addDirectoryMapping(_a.Path, "//root/a");
2255+
VFSWriter.addFileMapping(_ab.Path, "//root/a/b");
2256+
VFSWriter.addDirectoryMapping(_ac.Path, "//root/a/c");
2257+
VFSWriter.addFileMapping(_acd.Path, "//root/a/c/d");
2258+
VFSWriter.addFileMapping(_ace.Path, "//root/a/c/e");
2259+
VFSWriter.addFileMapping(_acf.Path, "//root/a/c/f");
2260+
VFSWriter.addDirectoryMapping(_ag.Path, "//root/a/g");
2261+
VFSWriter.addFileMapping(_agh.Path, "//root/a/g/h");
2262+
2263+
std::string Buffer;
2264+
raw_string_ostream OS(Buffer);
2265+
VFSWriter.write(OS);
2266+
OS.flush();
2267+
2268+
IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
2269+
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
2270+
// FIXME: Missing comma separator between file entries.
2271+
EXPECT_FALSE(FS.get() != nullptr);
2272+
}
2273+
22422274
TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) {
22432275
ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
22442276
ScopedDir _a(TestDirectory + "/a");

0 commit comments

Comments
 (0)