diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-07-20 13:44:35 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-27 12:59:33 +0000 |
commit | e95621b75fbc6108ab1d1487a83599a5f2dae7dc (patch) | |
tree | acf9799c2ee91daef5bd3dcfff756b6df9c9e793 /tests | |
parent | cfb3438ecc3af26e8ad146ba0d8509315db028bb (diff) |
tst_qmllscompletions: Correctly handle test failures
testlib's VERIFY and COMPARE macros only work in the function directly
invoked by the test framework.
Temporarily use a copy of the upcoming QTEST_CHECKED marco from testlib
to check that the indirectly called functions actually behaved
currently.
Moreover, move the call to the clean function into a scope guard, so
that it also will be called when the callback returns early due to
failed testlib change – otherwise, we'll end up waiting until the
timeout in QTRY_COMPARE_WITH_TIMEOUT.
Change-Id: I371c021f55f11e32950b12a57cf52ad0edb1fd7b
Reviewed-by: Moody Liu <mooodyhunter@outlook.com>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
(cherry picked from commit 9c8e04f9895b37bcf910b23a388d2d4e1f03878f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qmlls/completions/tst_qmllscompletions.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/tests/auto/qmlls/completions/tst_qmllscompletions.cpp b/tests/auto/qmlls/completions/tst_qmllscompletions.cpp index d3215dc988..e10b400887 100644 --- a/tests/auto/qmlls/completions/tst_qmllscompletions.cpp +++ b/tests/auto/qmlls/completions/tst_qmllscompletions.cpp @@ -15,6 +15,16 @@ #include <iostream> #include <variant> +// Check if QTest already has a QTEST_CHECKED macro +#ifndef QTEST_CHECKED +#define QTEST_CHECKED(...) \ +do { \ + __VA_ARGS__; \ + if (QTest::currentTestFailed()) \ + return; \ +} while (false) +#endif + QT_USE_NAMESPACE using namespace Qt::StringLiterals; using namespace QLspSpecification; @@ -224,6 +234,7 @@ void tst_QmllsCompletions::checkCompletions(QByteArray uri, int lineNr, int char m_protocol.requestCompletion( cParams, [clean, uri, expected, notExpected](auto res) { + QScopeGuard cleanup(clean); const QList<CompletionItem> *cItems = std::get_if<QList<CompletionItem>>(&res); if (!cItems) { @@ -275,13 +286,11 @@ void tst_QmllsCompletions::checkCompletions(QByteArray uri, int lineNr, int char QVERIFY2(!labels.contains(nexp), u"found unexpected completion %1"_s.arg(nexp).toUtf8()); } - - clean(); }, [clean](const ResponseError &err) { + QScopeGuard cleanup(clean); ProtocolBase::defaultResponseErrorHandler(err); QVERIFY2(false, "error computing the completion"); - clean(); }); QTRY_VERIFY_WITH_TIMEOUT(*didFinish, 30000); } @@ -294,20 +303,20 @@ void tst_QmllsCompletions::completions() QFETCH(ExpectedCompletions, expected); QFETCH(QStringList, notExpected); - checkCompletions(uri, lineNr, character, expected, notExpected); + QTEST_CHECKED(checkCompletions(uri, lineNr, character, expected, notExpected)); } void tst_QmllsCompletions::buildDir() { QString filePath = u"completions/fromBuildDir.qml"_s; QByteArray uri = testFileUrl(filePath).toString().toUtf8(); - checkCompletions(uri, 3, 0, + QTEST_CHECKED(checkCompletions(uri, 3, 0, ExpectedCompletions({ { u"property"_s, CompletionItemKind::Keyword }, { u"function"_s, CompletionItemKind::Keyword }, { u"Rectangle"_s, CompletionItemKind::Class }, }), - QStringList({ u"BuildDirType"_s, u"QtQuick"_s, u"width"_s, u"vector4d"_s })); + QStringList({ u"BuildDirType"_s, u"QtQuick"_s, u"width"_s, u"vector4d"_s }))); Notifications::AddBuildDirsParams bDirs; UriToBuildDirs ub; ub.baseUri = uri; @@ -323,7 +332,7 @@ void tst_QmllsCompletions::buildDir() change.text = file.readAll(); didChange.contentChanges.append(change); m_protocol.notifyDidChangeTextDocument(didChange); - checkCompletions(uri, 3, 0, + QTEST_CHECKED(checkCompletions(uri, 3, 0, ExpectedCompletions({ { u"BuildDirType"_s, CompletionItemKind::Class }, { u"Rectangle"_s, CompletionItemKind::Class }, @@ -331,7 +340,7 @@ void tst_QmllsCompletions::buildDir() { u"width"_s, CompletionItemKind::Property }, { u"function"_s, CompletionItemKind::Keyword }, }), - QStringList({ u"QtQuick"_s, u"vector4d"_s })); + QStringList({ u"QtQuick"_s, u"vector4d"_s }))); } void tst_QmllsCompletions::cleanupTestCase() { |