r269234 - [VFS][Unittests] Make dir iteration tests depend only on content

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Wed May 11 13:58:47 PDT 2016


Author: bruno
Date: Wed May 11 15:58:47 2016
New Revision: 269234

URL: http://llvm.org/viewvc/llvm-project?rev=269234&view=rev
Log:
[VFS][Unittests] Make dir iteration tests depend only on content

Do not rely on any specific order while comparing the results of
directory iteration.

Modified:
    cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp

Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=269234&r1=269233&r2=269234&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original)
+++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Wed May 11 15:58:47 2016
@@ -370,16 +370,23 @@ TEST(VirtualFileSystemTest, BasicRealFSR
 }
 
 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());
+  SmallVector<StringRef, 4> Expected(ExpectedOut.begin(), ExpectedOut.end());
+  SmallVector<std::string, 4> InputToCheck;
 
-  EXPECT_EQ(ExpectedEnd, ExpectedIter);
-  EXPECT_EQ(DirIter(), I);
+  // 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) {




More information about the cfe-commits mailing list