diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2018-10-31 23:36:10 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2018-10-31 23:36:10 +0000 |
commit | d886fa4497261da972a721aee3992c052250dfb7 (patch) | |
tree | c112dfe916ea7a255d3470a147e7b8a7633cd828 /unittests | |
parent | 585b6667b4712e3c7f32401e929855b3313b4ff2 (diff) |
[VFS] Add support for "no_push" to VFS recursive iterators.
The "regular" file system has a useful feature that makes it possible to
stop recursing when using the recursive directory iterators. This
functionality was missing for the VFS recursive iterator and this patch
adds that.
Differential revision: https://reviews.llvm.org/D53465
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345793 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Support/VirtualFileSystemTest.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/unittests/Support/VirtualFileSystemTest.cpp b/unittests/Support/VirtualFileSystemTest.cpp index 992704c18fa..d5c01141bba 100644 --- a/unittests/Support/VirtualFileSystemTest.cpp +++ b/unittests/Support/VirtualFileSystemTest.cpp @@ -478,6 +478,85 @@ TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) { EXPECT_EQ(1, Counts[3]); // d } +TEST(VirtualFileSystemTest, BasicRealFSRecursiveIterationNoPush) { + ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); + + ScopedDir _a(TestDirectory + "/a"); + ScopedDir _ab(TestDirectory + "/a/b"); + ScopedDir _c(TestDirectory + "/c"); + ScopedDir _cd(TestDirectory + "/c/d"); + ScopedDir _e(TestDirectory + "/e"); + ScopedDir _ef(TestDirectory + "/e/f"); + ScopedDir _g(TestDirectory + "/g"); + + IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem(); + + // Test that calling no_push on entries without subdirectories has no effect. + { + std::error_code EC; + auto I = vfs::recursive_directory_iterator(*FS, Twine(TestDirectory), EC); + ASSERT_FALSE(EC); + + std::vector<std::string> Contents; + for (auto E = vfs::recursive_directory_iterator(); !EC && I != E; + I.increment(EC)) { + Contents.push_back(I->path()); + char last = I->path().back(); + switch (last) { + case 'b': + case 'd': + case 'f': + case 'g': + I.no_push(); + break; + default: + break; + } + } + EXPECT_EQ(7U, Contents.size()); + } + + // Test that calling no_push skips subdirectories. + { + std::error_code EC; + auto I = vfs::recursive_directory_iterator(*FS, Twine(TestDirectory), EC); + ASSERT_FALSE(EC); + + std::vector<std::string> Contents; + for (auto E = vfs::recursive_directory_iterator(); !EC && I != E; + I.increment(EC)) { + Contents.push_back(I->path()); + char last = I->path().back(); + switch (last) { + case 'a': + case 'c': + case 'e': + I.no_push(); + break; + default: + break; + } + } + + // Check contents, which may be in any order + EXPECT_EQ(4U, Contents.size()); + int Counts[7] = {0, 0, 0, 0, 0, 0, 0}; + for (const std::string &Name : Contents) { + ASSERT_FALSE(Name.empty()); + int Index = Name[Name.size() - 1] - 'a'; + ASSERT_TRUE(Index >= 0 && Index < 7); + Counts[Index]++; + } + EXPECT_EQ(1, Counts[0]); // a + EXPECT_EQ(0, Counts[1]); // b + EXPECT_EQ(1, Counts[2]); // c + EXPECT_EQ(0, Counts[3]); // d + EXPECT_EQ(1, Counts[4]); // e + EXPECT_EQ(0, Counts[5]); // f + EXPECT_EQ(1, Counts[6]); // g + } +} + #ifdef LLVM_ON_UNIX TEST(VirtualFileSystemTest, BrokenSymlinkRealFSRecursiveIteration) { ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true); |