aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Basic/VirtualFileSystemTest.cpp
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2016-05-11 20:58:47 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2016-05-11 20:58:47 +0000
commit29ebd4979a1ab2e400bb16be1fc59af3b2f86c7e (patch)
tree14b1e31a98fb4afc3c78c5cc7e5ed637f8f635e4 /clang/unittests/Basic/VirtualFileSystemTest.cpp
parent556e963e4e8bec385940e08bb26b87dd832b9aab (diff)
downloadllvm-29ebd4979a1ab2e400bb16be1fc59af3b2f86c7e.zip
llvm-29ebd4979a1ab2e400bb16be1fc59af3b2f86c7e.tar.gz
llvm-29ebd4979a1ab2e400bb16be1fc59af3b2f86c7e.tar.bz2
[VFS][Unittests] Make dir iteration tests depend only on content
Do not rely on any specific order while comparing the results of directory iteration. llvm-svn: 269234
Diffstat (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp')
-rw-r--r--clang/unittests/Basic/VirtualFileSystemTest.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp
index d2f4a7d..b8e675e 100644
--- a/clang/unittests/Basic/VirtualFileSystemTest.cpp
+++ b/clang/unittests/Basic/VirtualFileSystemTest.cpp
@@ -370,16 +370,23 @@ TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) {
}
template <typename DirIter>
-static void checkContents(DirIter I, ArrayRef<StringRef> Expected) {
+static void checkContents(DirIter I, ArrayRef<StringRef> ExpectedOut) {
std::error_code EC;
- auto ExpectedIter = Expected.begin(), ExpectedEnd = Expected.end();
- for (DirIter E;
- !EC && I != E && ExpectedIter != ExpectedEnd;
- I.increment(EC), ++ExpectedIter)
- EXPECT_EQ(*ExpectedIter, I->getName());
-
- EXPECT_EQ(ExpectedEnd, ExpectedIter);
- EXPECT_EQ(DirIter(), I);
+ SmallVector<StringRef, 4> Expected(ExpectedOut.begin(), ExpectedOut.end());
+ SmallVector<std::string, 4> InputToCheck;
+
+ // Do not rely on iteration order to check for contents, sort both
+ // content vectors before comparison.
+ for (DirIter E; !EC && I != E; I.increment(EC))
+ InputToCheck.push_back(I->getName());
+
+ std::sort(InputToCheck.begin(), InputToCheck.end());
+ std::sort(Expected.begin(), Expected.end());
+ EXPECT_EQ(InputToCheck.size(), Expected.size());
+
+ unsigned LastElt = std::min(InputToCheck.size(), Expected.size());
+ for (unsigned Idx = 0; Idx != LastElt; ++Idx)
+ EXPECT_EQ(Expected[Idx], StringRef(InputToCheck[Idx]));
}
TEST(VirtualFileSystemTest, OverlayIteration) {