mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-11 14:45:33 +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;
|
QTimer timer;
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
QObject::connect(&timer, &QTimer::timeout, [=, &unitsCopy]{
|
QObject::connect(&timer, &QTimer::timeout, [=, &unitsCopy]{
|
||||||
|
reportTimeout(srcloc, unitsCopy);
|
||||||
for (auto i = unitsCopy.begin(); i != unitsCopy.end(); ++i)
|
for (auto i = unitsCopy.begin(); i != unitsCopy.end(); ++i)
|
||||||
{
|
{
|
||||||
(*i)->onDone(nullptr); //paranoia
|
(*i)->onDone(nullptr); //paranoia
|
||||||
}
|
}
|
||||||
unitsCopy.clear();
|
unitsCopy.clear();
|
||||||
QTest::qFail("*** Timed Out ***", qPrintable(srcloc.file), srcloc.line);
|
|
||||||
m_failed = true;
|
m_failed = true;
|
||||||
});
|
});
|
||||||
timer.start(timeout * 1000);
|
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
|
} //namespace BlackCoreTest
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#define BLACKCORETEST_EXPECT_H
|
#define BLACKCORETEST_EXPECT_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QMetaMethod>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
@@ -87,6 +88,9 @@ public:
|
|||||||
{
|
{
|
||||||
auto subj = subject<F1>();
|
auto subj = subject<F1>();
|
||||||
m_expects.push_back([=]{
|
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, slot);
|
||||||
m_guard += QObject::connect(subj, signal, [=]{ next(); });
|
m_guard += QObject::connect(subj, signal, [=]{ next(); });
|
||||||
});
|
});
|
||||||
@@ -118,6 +122,7 @@ private:
|
|||||||
QPointer<Expect> m_parent;
|
QPointer<Expect> m_parent;
|
||||||
QPointer<QObject> m_subject;
|
QPointer<QObject> m_subject;
|
||||||
SourceLocation m_srcloc;
|
SourceLocation m_srcloc;
|
||||||
|
QString m_waitingFor;
|
||||||
QVector<std::function<void()>> m_sends;
|
QVector<std::function<void()>> m_sends;
|
||||||
QVector<std::function<void()>> m_expects;
|
QVector<std::function<void()>> m_expects;
|
||||||
mutable QVector<std::function<void()>>::const_iterator m_nextExpect;
|
mutable QVector<std::function<void()>>::const_iterator m_nextExpect;
|
||||||
@@ -184,6 +189,7 @@ private:
|
|||||||
friend class ExpectUnit;
|
friend class ExpectUnit;
|
||||||
|
|
||||||
void wait(const SourceLocation& srcloc, int timeout);
|
void wait(const SourceLocation& srcloc, int timeout);
|
||||||
|
void reportTimeout(const SourceLocation& srcloc, const QSet<const ExpectUnit*>& units);
|
||||||
|
|
||||||
QPointer<QObject> m_subject;
|
QPointer<QObject> m_subject;
|
||||||
QSet<const ExpectUnit*> m_units;
|
QSet<const ExpectUnit*> m_units;
|
||||||
|
|||||||
Reference in New Issue
Block a user