Skip to content

Commit

Permalink
Prefer QFAIL("Informative message") over QVERIFY(false)
Browse files Browse the repository at this point in the history
Change-Id: I706b0aedfa870452331a8c2c488d55b279ee452a
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
ediosyncratic committed Jun 14, 2021
1 parent d2a4a5e commit accdfbb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
10 changes: 5 additions & 5 deletions tests/auto/corelib/global/qflags/tst_qflags.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
Expand Down Expand Up @@ -165,10 +165,10 @@ void tst_QFlags::constExpr()
{
Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
switch (btn) {
case Qt::LeftButton: QVERIFY(false); break;
case Qt::RightButton: QVERIFY(false); break;
case int(Qt::LeftButton | Qt::RightButton): QVERIFY(true); break;
default: QVERIFY(false);
case Qt::LeftButton: QVERIFY(false); break;
case Qt::RightButton: QVERIFY(false); break;
case int(Qt::LeftButton | Qt::RightButton): QVERIFY(true); break;
default: QFAIL(qPrintable(QStringLiteral("Unexpected button: %1").arg(btn)));
}

QVERIFY(verifyConstExpr<uint((Qt::LeftButton | Qt::RightButton) & Qt::LeftButton)>(Qt::LeftButton));
Expand Down
6 changes: 3 additions & 3 deletions tests/auto/corelib/serialization/json/tst_qtjson.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
Expand Down Expand Up @@ -956,13 +956,13 @@ void tst_QtJson::testObjectIteration()
QJsonObject object;

for (QJsonObject::iterator it = object.begin(); it != object.end(); ++it)
QVERIFY(false);
QFAIL("Iterator of default-initialized object should be empty");

const QString property = "kkk";
object.insert(property, 11);
object.take(property);
for (QJsonObject::iterator it = object.begin(); it != object.end(); ++it)
QVERIFY(false);
QFAIL("Iterator after property add-and-remove should be empty");

for (int i = 0; i < 10; ++i)
object[QString::number(i)] = (double)i;
Expand Down
14 changes: 7 additions & 7 deletions tests/auto/gui/rhi/qshader/tst_qshader.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
Expand Down Expand Up @@ -101,7 +101,7 @@ void tst_QShader::simpleCompileCheckResults()
QCOMPARE(v.type, QShaderDescription::Vec3);
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
break;
}
}
Expand All @@ -113,7 +113,7 @@ void tst_QShader::simpleCompileCheckResults()
QCOMPARE(v.type, QShaderDescription::Vec3);
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
break;
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ void tst_QShader::simpleCompileCheckResults()
QCOMPARE(v.type, QShaderDescription::Float);
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Too many blocks: %1").arg(blk.members.count())));
break;
}
}
Expand Down Expand Up @@ -409,7 +409,7 @@ void tst_QShader::loadV4()
QCOMPARE(v.type, QShaderDescription::Vec2);
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
break;
}
}
Expand All @@ -421,7 +421,7 @@ void tst_QShader::loadV4()
QCOMPARE(v.type, QShaderDescription::Vec4);
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Bad location: %1").arg(v.location)));
break;
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ void tst_QShader::loadV4()
QCOMPARE(v.type, QShaderDescription::Float);
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Bad many blocks: %1").arg(blk.members.count())));
break;
}
}
Expand Down
5 changes: 2 additions & 3 deletions tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
Expand Down Expand Up @@ -6539,8 +6539,7 @@ void tst_QNetworkReply::abortOnEncrypted()
server.connect(&server, &SslServer::newEncryptedConnection, [&server]() {
// MSVC 201X C4573-misunderstands connect() or QObject::connect(), so use server.connect():
server.connect(server.socket, &QTcpSocket::readyRead, server.socket, []() {
// This slot must not be invoked!
QVERIFY(false);
QFAIL("This slot must not be invoked!");
});
});

Expand Down
4 changes: 2 additions & 2 deletions tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
Expand Down Expand Up @@ -438,7 +438,7 @@ void tst_QListView::cursorMove()
}
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Unexpected key: %1").arg(key)));
}

QCoreApplication::processEvents();
Expand Down
4 changes: 2 additions & 2 deletions tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
Expand Down Expand Up @@ -1878,7 +1878,7 @@ void tst_QTreeView::keyboardNavigation()
}
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Unexpected key: %1").arg(key)));
}

QCOMPARE(view.currentIndex().row(), row);
Expand Down
4 changes: 2 additions & 2 deletions tests/auto/widgets/itemviews/qtreewidget/tst_qtreewidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
Expand Down Expand Up @@ -1540,7 +1540,7 @@ void tst_QTreeWidget::keyboardNavigation()
}
break;
default:
QVERIFY(false);
QFAIL(qPrintable(QStringLiteral("Unexpected key: %1").arg(key)));
}

QTreeWidgetItem *current = testWidget->currentItem();
Expand Down

0 comments on commit accdfbb

Please sign in to comment.