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 <fabian.kosmale@qt.io>
This commit is contained in:
Christian Stenger
2021-05-06 11:13:31 +02:00
parent fd64253a62
commit eafba223a5
3 changed files with 38 additions and 17 deletions

View File

@@ -0,0 +1,6 @@
import QtQuick 2.0
import QtQuickControls 2.0 as Controls
Controls.SmurfNonRecursive {
}

View File

@@ -0,0 +1,5 @@
import QtQuick 2.0
SmurfRecursive { // 129 1 14 // 303 1 14
}

View File

@@ -153,30 +153,40 @@ void tst_Check::test()
QList<Message> messages = checker(); QList<Message> messages = checker();
std::sort(messages.begin(), messages.end(), &offsetComparator); 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.*)?"); const QRegularExpression messagePattern(" (-?\\d+) (\\d+) (\\d+)\\s*(# false positive|# wrong warning.*)?");
QList<Message> expectedMessages; QList<Message> expectedMessages;
QHash<int, QString> xfails; QHash<int, QString> xfails;
for (const SourceLocation &comment : doc->engine()->comments()) { for (const SourceLocation &comment : doc->engine()->comments()) {
const QString text = doc->source().mid(comment.begin(), comment.end() - comment.begin()); const QString fullComment = doc->source().mid(comment.begin(), comment.end() - comment.begin());
const QRegularExpressionMatch match = messagePattern.match(text); const QStringList splittedComment = fullComment.split("//");
if (!match.hasMatch()) for (const QString &text : splittedComment) {
continue; const QRegularExpressionMatch match = messagePattern.match(text);
const int type = match.captured(1).toInt(); if (!match.hasMatch())
const int columnStart = match.captured(2).toInt(); continue;
const int columnEnd = match.captured(3).toInt() + 1; 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 message;
message.location = SourceLocation( message.location = SourceLocation(
comment.offset - comment.startColumn + columnStart, comment.offset - comment.startColumn + columnStart,
columnEnd - columnStart, columnEnd - columnStart,
comment.startLine, comment.startLine,
columnStart), columnStart),
message.type = static_cast<QmlJS::StaticAnalysis::Type>(type); message.type = static_cast<QmlJS::StaticAnalysis::Type>(type);
expectedMessages += message; expectedMessages += message;
if (messagePattern.captureCount() == 4 && !match.captured(4).isEmpty()) if (messagePattern.captureCount() == 4 && !match.captured(4).isEmpty())
xfails.insert(expectedMessages.size() - 1, match.captured(4)); xfails.insert(expectedMessages.size() - 1, match.captured(4));
}
} }
for (int i = 0; i < messages.size(); ++i) { for (int i = 0; i < messages.size(); ++i) {