From 8539d2e03395b0484b4eee712f34b60cc7449fde Mon Sep 17 00:00:00 2001 From: Jan Korous Date: Sat, 13 Jul 2019 00:09:04 +0000 Subject: [PATCH] [DirectoryWatcher][test][NFC] Add information to test failure reports git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365976 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../DirectoryWatcher/DirectoryWatcherTest.cpp | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp b/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp index 0808ff47de..72bc86d449 100644 --- a/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp +++ b/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp @@ -97,7 +97,9 @@ std::string eventKindToString(const DirectoryWatcher::Event::EventKind K) { struct VerifyingConsumer { std::vector ExpectedInitial; + const std::vector ExpectedInitialCopy; std::vector ExpectedNonInitial; + const std::vector ExpectedNonInitialCopy; std::vector OptionalNonInitial; std::vector UnexpectedInitial; std::vector UnexpectedNonInitial; @@ -108,8 +110,8 @@ struct VerifyingConsumer { const std::vector &ExpectedInitial, const std::vector &ExpectedNonInitial, const std::vector &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(VerifyingConsumer &TestConsumer) { 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 L(TestConsumer.Mtx); EXPECT_TRUE(TestConsumer.result().hasValue()); if (TestConsumer.result().hasValue()) { EXPECT_TRUE(*TestConsumer.result()); -- 2.40.0