From 00473e6f5f0012e8caa6717c6847257a0a019c19 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 3 Sep 2013 19:29:04 +0100 Subject: [PATCH] improved error reporting in BlackCoreTest::Expect --- tests/blackcore/expect.cpp | 14 +++++++++++++- tests/blackcore/expect.h | 6 ++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/blackcore/expect.cpp b/tests/blackcore/expect.cpp index 6d7df102f..e6fa3804d 100644 --- a/tests/blackcore/expect.cpp +++ b/tests/blackcore/expect.cpp @@ -73,12 +73,12 @@ void Expect::wait(const SourceLocation& srcloc, int timeout) QTimer timer; timer.setSingleShot(true); QObject::connect(&timer, &QTimer::timeout, [=, &unitsCopy]{ + reportTimeout(srcloc, unitsCopy); for (auto i = unitsCopy.begin(); i != unitsCopy.end(); ++i) { (*i)->onDone(nullptr); //paranoia } unitsCopy.clear(); - QTest::qFail("*** Timed Out ***", qPrintable(srcloc.file), srcloc.line); m_failed = true; }); timer.start(timeout * 1000); @@ -89,4 +89,16 @@ void Expect::wait(const SourceLocation& srcloc, int timeout) } } +void Expect::reportTimeout(const SourceLocation& srcloc, const QSet& units) +{ + QString msg = "*** Timed Out ***"; + QString prefix = "\nwhile waiting for "; + for (auto i = units.begin(); i != units.end(); ++i) + { + msg += prefix + (*i)->m_waitingFor; + prefix = "\nand "; + } + QTest::qFail(qPrintable(msg), qPrintable(srcloc.file), srcloc.line); +} + } //namespace BlackCoreTest \ No newline at end of file diff --git a/tests/blackcore/expect.h b/tests/blackcore/expect.h index 2310fc62e..e3dc1a322 100644 --- a/tests/blackcore/expect.h +++ b/tests/blackcore/expect.h @@ -7,6 +7,7 @@ #define BLACKCORETEST_EXPECT_H #include +#include #include #include #include @@ -87,6 +88,9 @@ public: { auto subj = subject(); m_expects.push_back([=]{ + m_waitingFor = subj->metaObject()->className(); + m_waitingFor += "::"; + m_waitingFor += QMetaMethod::fromSignal(signal).name(); m_guard += QObject::connect(subj, signal, slot); m_guard += QObject::connect(subj, signal, [=]{ next(); }); }); @@ -118,6 +122,7 @@ private: QPointer m_parent; QPointer m_subject; SourceLocation m_srcloc; + QString m_waitingFor; QVector> m_sends; QVector> m_expects; mutable QVector>::const_iterator m_nextExpect; @@ -184,6 +189,7 @@ private: friend class ExpectUnit; void wait(const SourceLocation& srcloc, int timeout); + void reportTimeout(const SourceLocation& srcloc, const QSet& units); QPointer m_subject; QSet m_units;