Skip to content

Commit 58bc507

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

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

llvm/unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,40 @@ TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest2) {
22712271
EXPECT_FALSE(FS.get() != nullptr);
22722272
}
22732273

2274+
TEST_F(VFSFromYAMLTest, YAMLVFSWriterTest3) {
2275+
ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
2276+
ScopedDir _a(TestDirectory + "/a");
2277+
ScopedFile _ab(TestDirectory + "/a/b", "");
2278+
ScopedDir _ac(TestDirectory + "/a/c");
2279+
ScopedDir _acd(TestDirectory + "/a/c/d");
2280+
ScopedDir _acde(TestDirectory + "/a/c/d/e");
2281+
ScopedFile _acdef(TestDirectory + "/a/c/d/e/f", "");
2282+
ScopedFile _acdeg(TestDirectory + "/a/c/d/e/g", "");
2283+
ScopedDir _ah(TestDirectory + "/a/h");
2284+
ScopedFile _ahi(TestDirectory + "/a/h/i", "");
2285+
2286+
vfs::YAMLVFSWriter VFSWriter;
2287+
VFSWriter.addDirectoryMapping(_a.Path, "//root/a");
2288+
VFSWriter.addFileMapping(_ab.Path, "//root/a/b");
2289+
VFSWriter.addDirectoryMapping(_ac.Path, "//root/a/c");
2290+
VFSWriter.addDirectoryMapping(_acd.Path, "//root/a/c/d");
2291+
VFSWriter.addDirectoryMapping(_acde.Path, "//root/a/c/d/e");
2292+
VFSWriter.addFileMapping(_acdef.Path, "//root/a/c/d/e/f");
2293+
VFSWriter.addFileMapping(_acdeg.Path, "//root/a/c/d/e/g");
2294+
VFSWriter.addDirectoryMapping(_ahi.Path, "//root/a/h");
2295+
VFSWriter.addFileMapping(_ahi.Path, "//root/a/h/i");
2296+
2297+
std::string Buffer;
2298+
raw_string_ostream OS(Buffer);
2299+
VFSWriter.write(OS);
2300+
OS.flush();
2301+
2302+
IntrusiveRefCntPtr<ErrorDummyFileSystem> Lower(new ErrorDummyFileSystem());
2303+
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLRawString(Buffer, Lower);
2304+
// FIXME: Spurious comma separator before first file entry in directory.
2305+
EXPECT_FALSE(FS.get() != nullptr);
2306+
}
2307+
22742308
TEST_F(VFSFromYAMLTest, YAMLVFSWriterTestHandleDirs) {
22752309
ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
22762310
ScopedDir _a(TestDirectory + "/a");

0 commit comments

Comments
 (0)