tests: Abort tests if there were warnings
This commit is contained in:
@@ -79,6 +79,8 @@ void Platform::tests_initPlatform(int &argc, char **argv, KDDockWidgets::Fronten
|
||||
break;
|
||||
}
|
||||
|
||||
Platform::instance()->m_numWarningsEmitted = 0;
|
||||
|
||||
/// Any additional setup
|
||||
Platform::instance()->tests_initPlatform_impl();
|
||||
|
||||
|
||||
@@ -165,6 +165,7 @@ public:
|
||||
|
||||
static QString s_expectedWarning;
|
||||
static WarningObserver *s_warningObserver;
|
||||
int m_numWarningsEmitted = 0;
|
||||
|
||||
protected:
|
||||
/// @brief Implement any needed initializations before tests starting to run, if any
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
using namespace KDDockWidgets;
|
||||
|
||||
#ifdef DOCKS_DEVELOPER_MODE
|
||||
|
||||
namespace KDDockWidgets::Tests {
|
||||
|
||||
static QtMessageHandler s_original = nullptr;
|
||||
@@ -54,10 +56,9 @@ static void fatalWarningsMessageHandler(QtMsgType t, const QMessageLogContext &c
|
||||
{
|
||||
if (shouldBlacklistWarning(msg, QLatin1String(context.category)))
|
||||
return;
|
||||
|
||||
s_original(t, context, msg);
|
||||
if (t == QtWarningMsg) {
|
||||
|
||||
if (t == QtWarningMsg) {
|
||||
if (!s_expectedWarning.isEmpty() && msg.contains(s_expectedWarning))
|
||||
return;
|
||||
|
||||
@@ -66,6 +67,7 @@ static void fatalWarningsMessageHandler(QtMsgType t, const QMessageLogContext &c
|
||||
if (Platform::s_warningObserver)
|
||||
Platform::s_warningObserver->onFatal();
|
||||
|
||||
Platform::instance()->m_numWarningsEmitted++;
|
||||
QFAIL("Test caused warning");
|
||||
}
|
||||
}
|
||||
@@ -95,7 +97,7 @@ public:
|
||||
EventFilter::~EventFilter() = default;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Platform_qt::Platform_qt()
|
||||
{
|
||||
@@ -251,6 +253,8 @@ void Platform_qt::tests_initPlatform_impl()
|
||||
|
||||
void Platform_qt::tests_deinitPlatform_impl()
|
||||
{
|
||||
qInstallMessageHandler(Tests::s_original);
|
||||
Tests::s_original = nullptr;
|
||||
delete qApp;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,13 @@ int main(int argc, char **argv)
|
||||
|
||||
std::cout << "\nStarting tests for Platform" << Platform::instance()->name() << "\n";
|
||||
|
||||
const int code = ctx.run();
|
||||
int code = ctx.run();
|
||||
|
||||
if (Platform::instance()->m_numWarningsEmitted > 0) {
|
||||
std::cout << "ABORTING! Test caused a warning.\n";
|
||||
code = 1;
|
||||
}
|
||||
|
||||
if (code != 0)
|
||||
exitCode = code;
|
||||
|
||||
|
||||
@@ -28,27 +28,9 @@ using namespace KDDockWidgets;
|
||||
|
||||
static int st = Item::separatorThickness;
|
||||
|
||||
static QtMessageHandler s_original = nullptr;
|
||||
static QString s_expectedWarning;
|
||||
|
||||
class TestMultiSplitter;
|
||||
static TestMultiSplitter *s_testObject = nullptr;
|
||||
|
||||
static void fatalWarningsMessageHandler(QtMsgType t, const QMessageLogContext &context, const QString &msg)
|
||||
{
|
||||
if (t == QtWarningMsg) {
|
||||
if (msg.contains(QLatin1String("checkSanity")) || msg.contains(QLatin1String("This plugin does not support"))) {
|
||||
// These will already fail in QVERIFY(checkSanity())
|
||||
return;
|
||||
}
|
||||
|
||||
s_original(t, context, msg);
|
||||
if (s_expectedWarning.isEmpty() || !msg.contains(s_expectedWarning))
|
||||
qFatal("Got a warning, category=%s", context.category);
|
||||
} else {
|
||||
s_original(t, context, msg);
|
||||
}
|
||||
}
|
||||
|
||||
class TestMultiSplitter : public QObject
|
||||
{
|
||||
@@ -57,7 +39,6 @@ class TestMultiSplitter : public QObject
|
||||
public Q_SLOTS:
|
||||
void initTestCase()
|
||||
{
|
||||
s_original = qInstallMessageHandler(fatalWarningsMessageHandler);
|
||||
s_testObject = this;
|
||||
|
||||
Layouting::Config::self().setSeparatorFactoryFunc([](Controllers::Separator *controller, View *parent) -> View * {
|
||||
@@ -552,7 +533,7 @@ void TestMultiSplitter::tst_resize()
|
||||
|
||||
void TestMultiSplitter::tst_resizeWithConstraints()
|
||||
{
|
||||
s_expectedWarning = QStringLiteral("New size doesn't respect size constraints");
|
||||
Platform::s_expectedWarning = QStringLiteral("New size doesn't respect size constraints");
|
||||
|
||||
{
|
||||
// Test that resizing below minSize isn't permitted.
|
||||
@@ -587,7 +568,7 @@ void TestMultiSplitter::tst_resizeWithConstraints()
|
||||
|
||||
// TODO: Resize further
|
||||
}
|
||||
s_expectedWarning.clear();
|
||||
Platform::s_expectedWarning.clear();
|
||||
}
|
||||
|
||||
void TestMultiSplitter::tst_availableSize()
|
||||
|
||||
Reference in New Issue
Block a user