r365976 - [DirectoryWatcher][test][NFC] Add information to test failure reports

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 12 17:09:04 PDT 2019


Author: jkorous
Date: Fri Jul 12 17:09:04 2019
New Revision: 365976

URL: http://llvm.org/viewvc/llvm-project?rev=365976&view=rev
Log:
[DirectoryWatcher][test][NFC] Add information to test failure reports

Modified:
    cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Modified: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp?rev=365976&r1=365975&r2=365976&view=diff
==============================================================================
--- cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp (original)
+++ cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp Fri Jul 12 17:09:04 2019
@@ -97,7 +97,9 @@ std::string eventKindToString(const Dire
 
 struct VerifyingConsumer {
   std::vector<DirectoryWatcher::Event> ExpectedInitial;
+  const std::vector<DirectoryWatcher::Event> ExpectedInitialCopy;
   std::vector<DirectoryWatcher::Event> ExpectedNonInitial;
+  const std::vector<DirectoryWatcher::Event> ExpectedNonInitialCopy;
   std::vector<DirectoryWatcher::Event> OptionalNonInitial;
   std::vector<DirectoryWatcher::Event> UnexpectedInitial;
   std::vector<DirectoryWatcher::Event> UnexpectedNonInitial;
@@ -108,8 +110,8 @@ struct VerifyingConsumer {
       const std::vector<DirectoryWatcher::Event> &ExpectedInitial,
       const std::vector<DirectoryWatcher::Event> &ExpectedNonInitial,
       const std::vector<DirectoryWatcher::Event> &OptionalNonInitial = {})
-      : ExpectedInitial(ExpectedInitial),
-        ExpectedNonInitial(ExpectedNonInitial),
+      : ExpectedInitial(ExpectedInitial), ExpectedInitialCopy(ExpectedInitial),
+        ExpectedNonInitial(ExpectedNonInitial), ExpectedNonInitialCopy(ExpectedNonInitial),
         OptionalNonInitial(OptionalNonInitial) {}
 
   // This method is used by DirectoryWatcher.
@@ -181,6 +183,26 @@ struct VerifyingConsumer {
   }
 
   void printUnmetExpectations(llvm::raw_ostream &OS) {
+    // If there was any issue, print the expected state
+    if (
+      !ExpectedInitial.empty()
+      ||
+      !ExpectedNonInitial.empty()
+      ||
+      !UnexpectedInitial.empty()
+      ||
+      !UnexpectedNonInitial.empty()
+    ) {
+      OS << "Expected initial events: \n";
+      for (const auto &E : ExpectedInitialCopy) {
+        OS << eventKindToString(E.Kind) << " " << E.Filename << "\n";
+      }
+      OS << "Expected non-initial events: \n";
+      for (const auto &E : ExpectedNonInitialCopy) {
+        OS << eventKindToString(E.Kind) << " " << E.Filename << "\n";
+      }
+    }
+
     if (!ExpectedInitial.empty()) {
       OS << "Expected but not seen initial events: \n";
       for (const auto &E : ExpectedInitial) {
@@ -218,6 +240,7 @@ void checkEventualResultWithTimeout(Veri
   EXPECT_TRUE(WaitForExpectedStateResult.wait_for(std::chrono::seconds(3)) ==
               std::future_status::ready)
       << "The expected result state wasn't reached before the time-out.";
+  std::unique_lock<std::mutex> L(TestConsumer.Mtx);
   EXPECT_TRUE(TestConsumer.result().hasValue());
   if (TestConsumer.result().hasValue()) {
     EXPECT_TRUE(*TestConsumer.result());




More information about the cfe-commits mailing list