summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Stenger <christian.stenger@qt.io>2021-05-06 11:13:31 +0200
committerChristian Stenger <christian.stenger@qt.io>2021-05-06 09:31:20 +0000
commiteafba223a596a82954dfc4bbbe44f47ca72ad063 (patch)
treecca9c86fcf0ddaf56c09edbc82febbbcbec14ba4
parentfd64253a62929fa6db6f865dc9a9e30098eb7524 (diff)
downloadqt-creator-eafba223a596a82954dfc4bbbe44f47ca72ad063.tar.gz
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>
-rw-r--r--tests/auto/qml/codemodel/check/SmurfNonRecursive.qml6
-rw-r--r--tests/auto/qml/codemodel/check/SmurfRecursive.qml5
-rw-r--r--tests/auto/qml/codemodel/check/tst_check.cpp48
3 files changed, 40 insertions, 19 deletions
diff --git a/tests/auto/qml/codemodel/check/SmurfNonRecursive.qml b/tests/auto/qml/codemodel/check/SmurfNonRecursive.qml
new file mode 100644
index 0000000000..9e09492bcc
--- /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 0000000000..5a729ba24b
--- /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 0df1bca5b6..35e49392dd 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<Message> 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<Message> expectedMessages;
QHash<int, QString> 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;
-
- Message message;
- message.location = SourceLocation(
- comment.offset - comment.startColumn + columnStart,
- columnEnd - columnStart,
- comment.startLine,
- columnStart),
- message.type = static_cast<QmlJS::StaticAnalysis::Type>(type);
- expectedMessages += message;
-
- if (messagePattern.captureCount() == 4 && !match.captured(4).isEmpty())
- xfails.insert(expectedMessages.size() - 1, match.captured(4));
+ 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<QmlJS::StaticAnalysis::Type>(type);
+ expectedMessages += message;
+
+ if (messagePattern.captureCount() == 4 && !match.captured(4).isEmpty())
+ xfails.insert(expectedMessages.size() - 1, match.captured(4));
+ }
}
for (int i = 0; i < messages.size(); ++i) {