diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2022-05-02 15:58:50 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2022-05-12 17:36:12 +0200 |
commit | 78483744b46419a3bf09b30d03dcd07abb6b65ad (patch) | |
tree | add38d49e8d5b4eb3ebc53e6588bb84ed35febfe /tests | |
parent | 5cd59bff0c2f077ab47c40710a5267c06d3d2aa9 (diff) |
QmlLintQuickPlugin: Warn about various SwipeDelegate issues
Implements anchor related and back/left/behind combination warnings.
Also adds a quality-of-life improvement in tst_qmllint where we print the
line when an expected message is missing.
Task-number: QTBUG-102277
Task-number: QTBUG-102859
Change-Id: I56068c75e3c6187845b079a6689debefa363a5e4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qmllint/data/pluginQuick_swipeDelegate.qml | 19 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 36 |
2 files changed, 49 insertions, 6 deletions
diff --git a/tests/auto/qml/qmllint/data/pluginQuick_swipeDelegate.qml b/tests/auto/qml/qmllint/data/pluginQuick_swipeDelegate.qml new file mode 100644 index 0000000000..a6c3b2c743 --- /dev/null +++ b/tests/auto/qml/qmllint/data/pluginQuick_swipeDelegate.qml @@ -0,0 +1,19 @@ +import QtQuick.Controls +import QtQuick + +Item { + SwipeDelegate { + contentItem: Item { anchors.left: parent.left } + background: Item { anchors.right: parent.right } + + swipe.left: Item {} + swipe.behind: Item {} + } + SwipeDelegate { + contentItem: Item { anchors.centerIn: parent } + background: Item { anchors.fill: parent } + + swipe.right: Item {} + swipe.behind: Item {} + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 72fabba059..8bc293646f 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -1514,23 +1514,28 @@ void TestQmllint::searchWarnings(const QJsonArray &warnings, const QString &subs } const auto toDescription = [](const QJsonArray &warnings, const QString &substring, - bool must = true) { + quint32 line, quint32 column, bool must = true) { // Note: this actually produces a very poorly formatted multi-line // description, but this is how we also do it in cleanQmlCode test case, // so this should suffice. in any case this mainly aids the debugging // and CI stays (or should stay) clean. - return QStringLiteral("qmllint output '%1' %2 contain '%3'") - .arg(QString::fromUtf8(QJsonDocument(warnings).toJson(QJsonDocument::Compact)), - must ? u"must" : u"must NOT", substring); + QString msg = QStringLiteral("qmllint output '%1' %2 contain '%3'") + .arg(QString::fromUtf8( + QJsonDocument(warnings).toJson(QJsonDocument::Compact)), + must ? u"must" : u"must NOT", substring); + if (line != 0 || column != 0) + msg += u" (%1:%2)"_s.arg(line).arg(column); + + return msg; }; if (shouldContain == StringContained) { if (!contains) - qWarning() << toDescription(warnings, substring); + qWarning() << toDescription(warnings, substring, line, column); QVERIFY(contains); } else { if (contains) - qWarning() << toDescription(warnings, substring, false); + qWarning() << toDescription(warnings, substring, line, column, false); QVERIFY(!contains); } } @@ -1715,6 +1720,25 @@ void TestQmllint::quickPlugin() u"LayoutDirection attached property only works with Items and Windows"_s }, Message { u"Layout must be attached to Item elements"_s }, Message { u"StackView attached property only works with Items"_s } } }); + runTest("pluginQuick_swipeDelegate.qml", + Result { { + Message { + u"SwipeDelegate: Cannot use horizontal anchors with contentItem; unable to layout the item."_s, + 6, 43 }, + Message { + u"SwipeDelegate: Cannot use horizontal anchors with background; unable to layout the item."_s, + 7, 43 }, + Message { u"SwipeDelegate: Cannot set both behind and left/right properties"_s, + 9, 9 }, + Message { + u"SwipeDelegate: Cannot use horizontal anchors with contentItem; unable to layout the item."_s, + 13, 47 }, + Message { + u"SwipeDelegate: Cannot use horizontal anchors with background; unable to layout the item."_s, + 14, 42 }, + Message { u"SwipeDelegate: Cannot set both behind and left/right properties"_s, + 16, 9 }, + } }); } #endif |