mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
improved error reporting in BlackCoreTest::Expect
This commit is contained in:
@@ -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<const ExpectUnit*>& 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
|
||||
@@ -7,6 +7,7 @@
|
||||
#define BLACKCORETEST_EXPECT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaMethod>
|
||||
#include <QPointer>
|
||||
#include <QVector>
|
||||
#include <QSet>
|
||||
@@ -87,6 +88,9 @@ public:
|
||||
{
|
||||
auto subj = subject<F1>();
|
||||
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<Expect> m_parent;
|
||||
QPointer<QObject> m_subject;
|
||||
SourceLocation m_srcloc;
|
||||
QString m_waitingFor;
|
||||
QVector<std::function<void()>> m_sends;
|
||||
QVector<std::function<void()>> m_expects;
|
||||
mutable QVector<std::function<void()>>::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<const ExpectUnit*>& units);
|
||||
|
||||
QPointer<QObject> m_subject;
|
||||
QSet<const ExpectUnit*> m_units;
|
||||
|
||||
Reference in New Issue
Block a user