diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2016-05-14 00:00:18 +0000 |
---|---|---|
committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2016-05-14 00:00:18 +0000 |
commit | 32b2897af6101e843f8fa90750e0de2a8a84d1cd (patch) | |
tree | d1abb0ea65d6781c5f5fe7531b879f4c30806e47 /clang/unittests/Basic/VirtualFileSystemTest.cpp | |
parent | eeae751429e7a0aa251fb1623bafc449181eb901 (diff) | |
download | llvm-32b2897af6101e843f8fa90750e0de2a8a84d1cd.zip llvm-32b2897af6101e843f8fa90750e0de2a8a84d1cd.tar.gz llvm-32b2897af6101e843f8fa90750e0de2a8a84d1cd.tar.bz2 |
[VFS] Add level() method to vfs::recursive_directory_iterator
Unlike sys::fs::recursive_directory_iterator,
vfs::recursive_directory_iterator does not implement the level() method,
which tells how deep in the directory tree the current iterator is. This
is needed in the vfs::recursive_directory_iterator so that future
improvements to the crash reproducer will be able to properly access
header for umbrellas when looking into the VFS.
rdar://problem/25880368
llvm-svn: 269520
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r-- | clang/unittests/Basic/VirtualFileSystemTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index a33f2b1..3b26488 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp @@ -1122,3 +1122,45 @@ TEST_F(VFSFromYAMLTest, DirectoryIterationSameDirMultipleEntries) { checkContents(O->dir_begin("//root/baz/", EC), {"//root/baz/x", "//root/baz/y"}); } + +TEST_F(VFSFromYAMLTest, RecursiveDirectoryIterationLevel) { + + IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + Lower->addDirectory("//root/a"); + Lower->addDirectory("//root/a/b"); + Lower->addDirectory("//root/a/b/c"); + Lower->addRegularFile("//root/a/b/c/file"); + IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( + "{ 'use-external-names': false,\n" + " 'roots': [\n" + "{\n" + " 'type': 'directory',\n" + " 'name': '//root/a/b/c/',\n" + " 'contents': [ {\n" + " 'type': 'file',\n" + " 'name': 'file',\n" + " 'external-contents': '//root/a/b/c/file'\n" + " }\n" + " ]\n" + "},\n" + "]\n" + "}", + Lower); + ASSERT_TRUE(FS.get() != nullptr); + + IntrusiveRefCntPtr<vfs::OverlayFileSystem> O( + new vfs::OverlayFileSystem(Lower)); + O->pushOverlay(FS); + + std::error_code EC; + + // Test recursive_directory_iterator level() + vfs::recursive_directory_iterator I = vfs::recursive_directory_iterator( + *O, "//root", EC), E; + ASSERT_FALSE(EC); + for (int l = 0; I != E; I.increment(EC), ++l) { + ASSERT_FALSE(EC); + EXPECT_EQ(I.level(), l); + } + EXPECT_EQ(I, E); +} |