From eafba223a596a82954dfc4bbbe44f47ca72ad063 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 6 May 2021 11:13:31 +0200 Subject: [PATCH] QmlJS: Add test for recursive declared items Tweak the test to allow multiple messages per line. Task-number: QTCREATORBUG-24615 Change-Id: I662ab4801794dc3e49f68667f634337a847bc503 Reviewed-by: Fabian Kosmale --- .../qml/codemodel/check/SmurfNonRecursive.qml | 6 +++ .../qml/codemodel/check/SmurfRecursive.qml | 5 +++ tests/auto/qml/codemodel/check/tst_check.cpp | 44 ++++++++++++------- 3 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 tests/auto/qml/codemodel/check/SmurfNonRecursive.qml create mode 100644 tests/auto/qml/codemodel/check/SmurfRecursive.qml diff --git a/tests/auto/qml/codemodel/check/SmurfNonRecursive.qml b/tests/auto/qml/codemodel/check/SmurfNonRecursive.qml new file mode 100644 index 00000000000..9e09492bccb --- /dev/null +++ b/tests/auto/qml/codemodel/check/SmurfNonRecursive.qml @@ -0,0 +1,6 @@ +import QtQuick 2.0 +import QtQuickControls 2.0 as Controls + +Controls.SmurfNonRecursive { + +} diff --git a/tests/auto/qml/codemodel/check/SmurfRecursive.qml b/tests/auto/qml/codemodel/check/SmurfRecursive.qml new file mode 100644 index 00000000000..5a729ba24b2 --- /dev/null +++ b/tests/auto/qml/codemodel/check/SmurfRecursive.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +SmurfRecursive { // 129 1 14 // 303 1 14 + +} diff --git a/tests/auto/qml/codemodel/check/tst_check.cpp b/tests/auto/qml/codemodel/check/tst_check.cpp index 0df1bca5b6d..35e49392dde 100644 --- a/tests/auto/qml/codemodel/check/tst_check.cpp +++ b/tests/auto/qml/codemodel/check/tst_check.cpp @@ -153,30 +153,40 @@ void tst_Check::test() QList messages = checker(); std::sort(messages.begin(), messages.end(), &offsetComparator); + /* + * expected message are marked inside the respective qml file on the line of their occurrence + * with a comment stating error number, start column, and end column with optional state to mark + * e.g. false positives + * if more than 1 message at a line is expected these can be specified by adding further + * line comments in the same line + */ const QRegularExpression messagePattern(" (-?\\d+) (\\d+) (\\d+)\\s*(# false positive|# wrong warning.*)?"); QList expectedMessages; QHash xfails; for (const SourceLocation &comment : doc->engine()->comments()) { - const QString text = doc->source().mid(comment.begin(), comment.end() - comment.begin()); - const QRegularExpressionMatch match = messagePattern.match(text); - if (!match.hasMatch()) - continue; - const int type = match.captured(1).toInt(); - const int columnStart = match.captured(2).toInt(); - const int columnEnd = match.captured(3).toInt() + 1; + const QString fullComment = doc->source().mid(comment.begin(), comment.end() - comment.begin()); + const QStringList splittedComment = fullComment.split("//"); + for (const QString &text : splittedComment) { + const QRegularExpressionMatch match = messagePattern.match(text); + if (!match.hasMatch()) + continue; + const int type = match.captured(1).toInt(); + const int columnStart = match.captured(2).toInt(); + const int columnEnd = match.captured(3).toInt() + 1; - Message message; - message.location = SourceLocation( - comment.offset - comment.startColumn + columnStart, - columnEnd - columnStart, - comment.startLine, - columnStart), - message.type = static_cast(type); - expectedMessages += message; + Message message; + message.location = SourceLocation( + comment.offset - comment.startColumn + columnStart, + columnEnd - columnStart, + comment.startLine, + columnStart), + message.type = static_cast(type); + expectedMessages += message; - if (messagePattern.captureCount() == 4 && !match.captured(4).isEmpty()) - xfails.insert(expectedMessages.size() - 1, match.captured(4)); + if (messagePattern.captureCount() == 4 && !match.captured(4).isEmpty()) + xfails.insert(expectedMessages.size() - 1, match.captured(4)); + } } for (int i = 0; i < messages.size(); ++i) {