From: Bruno Cardoso Lopes Date: Wed, 11 May 2016 20:58:47 +0000 (+0000) Subject: [VFS][Unittests] Make dir iteration tests depend only on content X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbbb14f15ffbdad77db30d0cbcc7ab65dd8f624a;p=clang [VFS][Unittests] Make dir iteration tests depend only on content Do not rely on any specific order while comparing the results of directory iteration. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269234 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/unittests/Basic/VirtualFileSystemTest.cpp b/unittests/Basic/VirtualFileSystemTest.cpp index d2f4a7d8f0..b8e675e75f 100644 --- a/unittests/Basic/VirtualFileSystemTest.cpp +++ b/unittests/Basic/VirtualFileSystemTest.cpp @@ -370,16 +370,23 @@ TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) { } template -static void checkContents(DirIter I, ArrayRef Expected) { +static void checkContents(DirIter I, ArrayRef 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 Expected(ExpectedOut.begin(), ExpectedOut.end()); + SmallVector 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) {