aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmllint/tst_qmllint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qmllint/tst_qmllint.cpp')
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp71
1 files changed, 51 insertions, 20 deletions
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 57cb7228d8..7f7b5317cc 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -105,14 +105,18 @@ private Q_SLOTS:
void valueTypesFromString();
void ignoreSettingsNotCommandLineOptions();
+ void backslashedQmldirPath();
void environment_data();
void environment();
+ void maxWarnings();
+
#if QT_CONFIG(library)
void testPlugin();
void quickPlugin();
#endif
+
private:
enum DefaultImportOption { NoDefaultImports, UseDefaultImports };
enum ContainOption { StringNotContained, StringContained };
@@ -123,6 +127,11 @@ private:
enum LintType { LintFile, LintModule };
+ static QStringList warningsShouldFailArgs() {
+ static QStringList args {"-W", "0"};
+ return args;
+ }
+
QString runQmllint(const QString &fileToLint, std::function<void(QProcess &)> handleResult,
const QStringList &extraArgs = QStringList(), bool ignoreSettings = true,
bool addImportDirs = true, bool absolutePath = true,
@@ -409,7 +418,7 @@ void TestQmllint::autoqmltypes()
{
QProcess process;
process.setWorkingDirectory(testFile("autoqmltypes"));
- process.start(m_qmllintPath, { QStringLiteral("test.qml") });
+ process.start(m_qmllintPath, warningsShouldFailArgs() << QStringLiteral("test.qml") );
process.waitForFinished();
@@ -423,7 +432,7 @@ void TestQmllint::autoqmltypes()
{
QProcess bare;
bare.setWorkingDirectory(testFile("autoqmltypes"));
- bare.start(m_qmllintPath, { QStringLiteral("--bare"), QStringLiteral("test.qml") });
+ bare.start(m_qmllintPath, warningsShouldFailArgs() << QStringLiteral("--bare") << QStringLiteral("test.qml") );
bare.waitForFinished();
const QByteArray errors = bare.readAllStandardError();
@@ -1026,7 +1035,7 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)",
{ Message { QStringLiteral("Ready") } } } };
QTest::newRow("nullBinding") << QStringLiteral("nullBinding.qml")
<< Result{ { Message{ QStringLiteral(
- "Cannot assign literal of type null to qreal") } } };
+ "Cannot assign literal of type null to double") } } };
QTest::newRow("missingRequiredAlias")
<< QStringLiteral("missingRequiredAlias.qml")
<< Result { { Message {
@@ -1345,6 +1354,8 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("locale") << QStringLiteral("locale.qml");
QTest::newRow("constInvokable") << QStringLiteral("useConstInvokable.qml");
QTest::newRow("dontCheckJSTypes") << QStringLiteral("dontCheckJSTypes.qml");
+ QTest::newRow("jsonObjectIsRecognized") << QStringLiteral("jsonObjectIsRecognized.qml");
+ QTest::newRow("jsonArrayIsRecognized") << QStringLiteral("jsonArrayIsRecognized.qml");
}
void TestQmllint::cleanQmlCode()
@@ -1370,8 +1381,7 @@ void TestQmllint::compilerWarnings_data()
QTest::newRow("shadowable")
<< QStringLiteral("shadowable.qml")
- << Result { { Message {QStringLiteral(
- "with type NotSoSimple (stored as QQuickItem) can be shadowed") } } }
+ << Result { { Message {QStringLiteral("with type NotSoSimple can be shadowed") } } }
<< true;
QTest::newRow("tooFewParameters")
<< QStringLiteral("tooFewParams.qml")
@@ -1407,20 +1417,20 @@ void TestQmllint::compilerWarnings_data()
<< QStringLiteral("returnTypeAnnotation_component.qml")
<< Result{ { { "Could not compile function comp: function without return type "
"annotation returns (component in" },
- { "returnTypeAnnotation_component.qml)::c with type Comp (stored as "
- "QQuickItem). This may prevent proper compilation to Cpp." } } }
+ { "returnTypeAnnotation_component.qml)::c with type Comp. "
+ "This may prevent proper compilation to Cpp." } } }
<< true;
QTest::newRow("returnTypeAnnotation-enum")
<< QStringLiteral("returnTypeAnnotation_enum.qml")
<< Result{ { { "Could not compile function enumeration: function without return type "
- "annotation returns QQuickText::HAlignment::AlignRight (stored as int). "
+ "annotation returns QQuickText::HAlignment::AlignRight. "
"This may prevent proper compilation to Cpp." } } }
<< true;
QTest::newRow("returnTypeAnnotation-method")
<< QStringLiteral("returnTypeAnnotation_method.qml")
<< Result{ { { "Could not compile function method: function without return type "
"annotation returns (component in " }, // Don't check the build folder path
- { "returnTypeAnnotation_method.qml)::f(...) (stored as QJSValue). This may "
+ { "returnTypeAnnotation_method.qml)::f(...). This may "
"prevent proper compilation to Cpp." } } }
<< true;
QTest::newRow("returnTypeAnnotation-property")
@@ -1792,17 +1802,17 @@ void TestQmllint::requiredProperty()
void TestQmllint::settingsFile()
{
- QVERIFY(runQmllint("settings/unqualifiedSilent/unqualified.qml", true, QStringList(), false)
+ QVERIFY(runQmllint("settings/unqualifiedSilent/unqualified.qml", true, warningsShouldFailArgs(), false)
.isEmpty());
- QVERIFY(runQmllint("settings/unusedImportWarning/unused.qml", false, QStringList(), false)
+ QVERIFY(runQmllint("settings/unusedImportWarning/unused.qml", false, warningsShouldFailArgs(), false)
.contains(QStringLiteral("Warning: %1:2:1: Unused import")
.arg(testFile("settings/unusedImportWarning/unused.qml"))));
- QVERIFY(runQmllint("settings/bare/bare.qml", false, {}, false, false)
+ QVERIFY(runQmllint("settings/bare/bare.qml", false, warningsShouldFailArgs(), false, false)
.contains(QStringLiteral("Failed to find the following builtins: "
- "builtins.qmltypes, jsroot.qmltypes")));
- QVERIFY(runQmllint("settings/qmltypes/qmltypes.qml", false, QStringList(), false)
+ "jsroot.qmltypes, builtins.qmltypes")));
+ QVERIFY(runQmllint("settings/qmltypes/qmltypes.qml", false, warningsShouldFailArgs(), false)
.contains(QStringLiteral("not a qmldir file. Assuming qmltypes.")));
- QVERIFY(runQmllint("settings/qmlimports/qmlimports.qml", true, QStringList(), false).isEmpty());
+ QVERIFY(runQmllint("settings/qmlimports/qmlimports.qml", true, warningsShouldFailArgs(), false).isEmpty());
}
void TestQmllint::additionalImplicitImport()
@@ -1907,13 +1917,13 @@ void TestQmllint::missingBuiltinsNoCrash()
checkResult(warnings,
Result { { Message { QStringLiteral("Failed to find the following builtins: "
- "builtins.qmltypes, jsroot.qmltypes") } } });
+ "jsroot.qmltypes, builtins.qmltypes") } } });
}
void TestQmllint::absolutePath()
{
- QString absPathOutput = runQmllint("memberNotFound.qml", false, {}, true, true, true);
- QString relPathOutput = runQmllint("memberNotFound.qml", false, {}, true, true, false);
+ QString absPathOutput = runQmllint("memberNotFound.qml", false, warningsShouldFailArgs(), true, true, true);
+ QString relPathOutput = runQmllint("memberNotFound.qml", false, warningsShouldFailArgs(), true, true, false);
const QString absolutePath = QFileInfo(testFile("memberNotFound.qml")).absoluteFilePath();
QVERIFY(absPathOutput.contains(absolutePath));
@@ -2120,7 +2130,7 @@ void TestQmllint::quickPlugin()
Message { u"SplitView attached property only works with Items"_s },
Message { u"ScrollIndicator must be attached to a Flickable"_s },
Message { u"ScrollBar must be attached to a Flickable or ScrollView"_s },
- Message { u"Accessible must be attached to an Item"_s },
+ Message { u"Accessible must be attached to an Item or an Action"_s },
Message { u"EnterKey attached property only works with Items"_s },
Message {
u"LayoutDirection attached property only works with Items and Windows"_s },
@@ -2205,7 +2215,7 @@ void TestQmllint::environment_data()
const QString noWarningExpected;
QTest::addRow("missing-import-dir")
- << fileThatNeedsImportPath << false << QStringList{}
+ << fileThatNeedsImportPath << false << warningsShouldFailArgs()
<< Environment{ { u"QML_IMPORT_PATH"_s, importPath } } << noWarningExpected;
QTest::addRow("import-dir-via-arg")
@@ -2239,6 +2249,18 @@ void TestQmllint::environment()
}
}
+void TestQmllint::maxWarnings()
+{
+ // warnings are not fatal by default
+ runQmllint(testFile("badScript.qml"), true);
+ // or when max-warnings is set to -1
+ runQmllint(testFile("badScript.qml"), true, {"-W", "-1"});
+ // 1 warning => should fail
+ runQmllint(testFile("badScript.qml"), false, {"--max-warnings", "0"});
+ // only 1 warning => should exit normally
+ runQmllint(testFile("badScript.qml"), true, {"--max-warnings", "1"});
+}
+
#endif
void TestQmllint::ignoreSettingsNotCommandLineOptions()
@@ -2252,5 +2274,14 @@ void TestQmllint::ignoreSettingsNotCommandLineOptions()
QCOMPARE(output, QString());
}
+void TestQmllint::backslashedQmldirPath()
+{
+ const QString qmldirPath
+ = testFile(u"ImportPath/ModuleInImportPath/qmldir"_s).replace('/', QDir::separator());
+ const QString output = runQmllint(
+ testFile(u"something.qml"_s), true, QStringList{ u"-i"_s, qmldirPath });
+ QVERIFY(output.isEmpty());
+}
+
QTEST_GUILESS_MAIN(TestQmllint)
#include "tst_qmllint.moc"