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,12 +153,21 @@ 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 QStringList splittedComment = fullComment.split("//");
for (const QString &text : splittedComment) {
const QRegularExpressionMatch match = messagePattern.match(text); const QRegularExpressionMatch match = messagePattern.match(text);
if (!match.hasMatch()) if (!match.hasMatch())
continue; continue;
@@ -178,6 +187,7 @@ void tst_Check::test()
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) {
if (i >= expectedMessages.size()) if (i >= expectedMessages.size())