From 29ebd4979a1ab2e400bb16be1fc59af3b2f86c7e Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Wed, 11 May 2016 20:58:47 +0000 Subject: [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 --- clang/unittests/Basic/VirtualFileSystemTest.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'clang/unittests/Basic/VirtualFileSystemTest.cpp') diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp index d2f4a7d8f02..b8e675e75fa 100644 --- a/clang/unittests/Basic/VirtualFileSystemTest.cpp +++ b/clang/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) { -- cgit v1.2.3