aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2025-04-07 16:57:53 +0200
committerSami Shalayel <sami.shalayel@qt.io>2025-04-24 14:48:57 +0200
commitcf748fce71bf06f3695248024c21d2083ee4c714 (patch)
tree02803934c29c8267d97365e92ed2e73bd69a8760
parent9b2cff650a5452d38b45c6e40f8b7eea7a048d77 (diff)
tst_qmlls_modules: encapsulate expected warnings
Encapsulate the expected warnings into an own struct to prepare for the test of the context property feature, where warnings are emitted twice: once without required properties and once once the context properties were loaded. Task-number: QTBUG-128232 Change-Id: I0f2e8ac8e94913b0f4d1acba8c07201e7965f7da Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
-rw-r--r--tests/auto/qmlls/modules/tst_qmlls_modules.cpp31
-rw-r--r--tests/auto/qmlls/modules/tst_qmlls_modules.h7
2 files changed, 24 insertions, 14 deletions
diff --git a/tests/auto/qmlls/modules/tst_qmlls_modules.cpp b/tests/auto/qmlls/modules/tst_qmlls_modules.cpp
index ed9cb0f332..8526735de4 100644
--- a/tests/auto/qmlls/modules/tst_qmlls_modules.cpp
+++ b/tests/auto/qmlls/modules/tst_qmlls_modules.cpp
@@ -1297,29 +1297,32 @@ void tst_qmlls_modules::linting()
void tst_qmlls_modules::warnings_data()
{
QTest::addColumn<QString>("filePath");
- QTest::addColumn<QStringList>("expectedWarnings");
+ QTest::addColumn<ExpectedWarnings>("expectedWarnings");
- QTest::addRow("unqualifiedAccess") << u"warnings/withoutQmllintIni/unqualifiedAccess.qml"_s
- << QStringList{ u"Unqualified access [unqualified]"_s };
+ QTest::addRow("unqualifiedAccess")
+ << u"warnings/withoutQmllintIni/unqualifiedAccess.qml"_s
+ << ExpectedWarnings{ { u"Unqualified access [unqualified]"_s } };
QTest::addRow("disableUnqualifiedEnabledCompiler")
<< u"warnings/disableUnqualifiedEnableCompiler/unqualifiedAccess.qml"_s
- << QStringList { u"Could not compile binding for i: Cannot access value for name unqualifiedAccess [compiler]"_s };
+ << ExpectedWarnings{
+ { u"Could not compile binding for i: Cannot access value for name unqualifiedAccess [compiler]"_s }
+ };
QTest::addRow("enableQmllsGenerationIniViaCMake")
<< u"warnings/InvalidImport.qml"_s
- << QStringList{
- u"Warnings occurred while importing module \"foobar\": [import]"_s,
- u"Failed to import foobar. Are your import paths set up properly? Did you build your project? If yes, did you set the \"QT_QML_GENERATE_QMLLS_INI\" CMake variable on your project to \"ON\"? [import]"_s,
- u"Warnings occurred while importing module \"foobaz\": [import]"_s,
- u"Failed to import foobaz. Are your import paths set up properly? Did you build your project? If yes, did you set the \"QT_QML_GENERATE_QMLLS_INI\" CMake variable on your project to \"ON\"? [import]"_s,
- };
+ << ExpectedWarnings{ {
+ u"Warnings occurred while importing module \"foobar\": [import]"_s,
+ u"Failed to import foobar. Are your import paths set up properly? Did you build your project? If yes, did you set the \"QT_QML_GENERATE_QMLLS_INI\" CMake variable on your project to \"ON\"? [import]"_s,
+ u"Warnings occurred while importing module \"foobaz\": [import]"_s,
+ u"Failed to import foobaz. Are your import paths set up properly? Did you build your project? If yes, did you set the \"QT_QML_GENERATE_QMLLS_INI\" CMake variable on your project to \"ON\"? [import]"_s,
+ } };
}
void tst_qmlls_modules::warnings()
{
QFETCH(QString, filePath);
- QFETCH(QStringList, expectedWarnings);
+ QFETCH(ExpectedWarnings, expectedWarnings);
bool diagnosticOk = false;
const auto uri = openFile(filePath);
@@ -1330,7 +1333,7 @@ void tst_qmlls_modules::warnings()
if (p.uri != *uri || !p.version)
return;
- if (expectedWarnings.isEmpty()) {
+ if (expectedWarnings.warnings.isEmpty()) {
for (const auto& x: p.diagnostics)
qDebug() << "Received unexpected message:" << x.message;
QCOMPARE(p.diagnostics.size(), 0);
@@ -1338,9 +1341,9 @@ void tst_qmlls_modules::warnings()
return;
}
- QCOMPARE(p.diagnostics.size(), expectedWarnings.size());
+ QCOMPARE(p.diagnostics.size(), expectedWarnings.warnings.size());
for (qsizetype i = 0; i < p.diagnostics.size(); ++i) {
- QCOMPARE(p.diagnostics[i].message, expectedWarnings[i].toUtf8());
+ QCOMPARE(p.diagnostics[i].message, expectedWarnings.warnings[i].toUtf8());
}
diagnosticOk = true;
});
diff --git a/tests/auto/qmlls/modules/tst_qmlls_modules.h b/tests/auto/qmlls/modules/tst_qmlls_modules.h
index 363ec1e0e9..77e33002c6 100644
--- a/tests/auto/qmlls/modules/tst_qmlls_modules.h
+++ b/tests/auto/qmlls/modules/tst_qmlls_modules.h
@@ -59,6 +59,13 @@ private slots:
void renameUsages();
void linting_data();
void linting();
+
+private:
+ struct ExpectedWarnings
+ {
+ QStringList warnings;
+ };
+private slots:
void warnings_data();
void warnings();
void rangeFormatting_data();