aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-09-19 10:42:51 +0200
committerUlf Hermann <ulf.hermann@qt.io>2019-09-19 11:28:19 +0200
commit567fc7b40efb451f12eddd9615bae892dcba707f (patch)
tree8efc116c9e7397ff0cd6eb45d672a06e90671fda /tests/auto
parent33635f60a708ef2aa7f90c680628878ecadc5168 (diff)
Clean up qmllint test
There were several test functions that did effectively the same thing. Unify them. Change-Id: I2d1a9c1534b1c21498c9f0b7a8b80cd4f2a508b5 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp124
1 files changed, 65 insertions, 59 deletions
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 2d225aebd3..9dc0a4dd42 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -38,16 +38,17 @@ class TestQmllint: public QQmlDataTest
private Q_SLOTS:
void initTestCase() override;
- void test();
- void test_data();
+
void testUnqualified();
void testUnqualified_data();
+
+ void cleanQmlCode_data();
+ void cleanQmlCode();
+
+ void dirtyQmlCode_data();
+ void dirtyQmlCode();
+
void testUnqualifiedNoSpuriousParentWarning();
- void catchIdentifierNoFalsePositive();
- void testUnmatchedSignalHandler();
- void uiQml();
- void methodInScope();
- void importWithPrefix();
private:
QString runQmllint(const QString &fileToLint, bool shouldSucceed);
@@ -68,24 +69,8 @@ void TestQmllint::initTestCase()
}
}
-void TestQmllint::test_data()
-{
- QTest::addColumn<QString>("filename");
- QTest::addColumn<bool>("isValid");
-
- // Valid files:
- QTest::newRow("Simple_QML") << QStringLiteral("Simple.qml") << true;
- QTest::newRow("QML_importing_JS") << QStringLiteral("importing_js.qml") << true;
- QTest::newRow("QTBUG-45916_JS_with_pragma_and_import") << QStringLiteral("QTBUG-45916.js") << true;
-
- // Invalid files:
- QTest::newRow("Invalid_syntax_QML") << QStringLiteral("failure1.qml") << false;
- QTest::newRow("Invalid_syntax_JS") << QStringLiteral("failure1.js") << false;
-}
-
void TestQmllint::testUnqualified()
{
- auto qmlImportDir = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
QFETCH(QString, filename);
QFETCH(QString, warningMessage);
QFETCH(int, warningLine);
@@ -118,54 +103,66 @@ void TestQmllint::testUnqualified_data()
QTest::newRow("SignalHandlerShort2") << QStringLiteral("SignalHandler.qml") << QStringLiteral("onPressAndHold: (mouse) => {...") << 12 << 34;
// access catch identifier outside catch block
QTest::newRow("CatchStatement") << QStringLiteral("CatchStatement.qml") << QStringLiteral("err") << 6 << 21;
-}
-void TestQmllint::testUnqualifiedNoSpuriousParentWarning()
-{
- runQmllint("spuriousParentWarning.qml", true);
- runQmllint("nonSpuriousParentWarning.qml", false);
+ QTest::newRow("NonSpuriousParent") << QStringLiteral("nonSpuriousParentWarning.qml") << QStringLiteral("property int x: <id>.parent.x") << 6 << 25;
}
-void TestQmllint::catchIdentifierNoFalsePositive()
+void TestQmllint::testUnqualifiedNoSpuriousParentWarning()
{
- runQmllint("catchIdentifierNoWarning.qml", true);
+ const QString unknownNotFound = runQmllint("spuriousParentWarning.qml", true);
+ QVERIFY(unknownNotFound.contains(
+ QStringLiteral("warning: Unknown was not found. Did you add all import paths?")));
}
-void TestQmllint::testUnmatchedSignalHandler()
+void TestQmllint::dirtyQmlCode_data()
{
- const QString output = runQmllint("UnmatchedSignalHandler.qml", false);
- QVERIFY(output.contains(QString::asprintf(
- "Warning: no matching signal found for handler \"onClicked\" at %d:%d", 12, 13)));
- QVERIFY(!output.contains(QStringLiteral("onMouseXChanged")));
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<QString>("warningMessage");
+ QTest::addColumn<QString>("notContained");
+
+ QTest::newRow("Invalid_syntax_QML")
+ << QStringLiteral("failure1.qml")
+ << QStringLiteral("failure1.qml:4 : Expected token `:'")
+ << QString();
+ QTest::newRow("Invalid_syntax_JS")
+ << QStringLiteral("failure1.js")
+ << QStringLiteral("failure1.js:4 : Expected token `;'")
+ << QString();
+ QTest::newRow("UnmatchedSignalHandler")
+ << QStringLiteral("UnmatchedSignalHandler.qml")
+ << QString("Warning: no matching signal found for handler \"onClicked\" at 12:13")
+ << QStringLiteral("onMouseXChanged");
}
-void TestQmllint::uiQml()
+void TestQmllint::dirtyQmlCode()
{
- const QString output = runQmllint("FormUser.qml", true);
- QVERIFY(output.isEmpty());
-}
+ QFETCH(QString, filename);
+ QFETCH(QString, warningMessage);
+ QFETCH(QString, notContained);
-void TestQmllint::methodInScope()
-{
- const QString output = runQmllint("MethodInScope.qml", true);
- QVERIFY(output.isEmpty());
+ const QString output = runQmllint(filename, false);
+ QVERIFY(output.contains(warningMessage));
+ if (!notContained.isEmpty())
+ QVERIFY(!output.contains(notContained));
}
-void TestQmllint::importWithPrefix()
+void TestQmllint::cleanQmlCode_data()
{
- const QString output = runQmllint("ImportWithPrefix.qml", true);
- QVERIFY(output.isEmpty());
+ QTest::addColumn<QString>("filename");
+ QTest::newRow("Simple_QML") << QStringLiteral("Simple.qml");
+ QTest::newRow("QML_importing_JS") << QStringLiteral("importing_js.qml");
+ QTest::newRow("JS_with_pragma_and_import") << QStringLiteral("QTBUG-45916.js");
+ QTest::newRow("uiQml") << QStringLiteral("FormUser.qml");
+ QTest::newRow("methodInScope") << QStringLiteral("MethodInScope.qml");
+ QTest::newRow("importWithPrefix") << QStringLiteral("ImportWithPrefix.qml");
+ QTest::newRow("catchIdentifier") << QStringLiteral("catchIdentifierNoWarning.qml");
}
-void TestQmllint::test()
+void TestQmllint::cleanQmlCode()
{
QFETCH(QString, filename);
- QFETCH(bool, isValid);
- QStringList args;
- args << QStringLiteral("--silent") << testFile(filename);
-
- bool success = QProcess::execute(m_qmllintPath, args) == 0;
- QCOMPARE(success, isValid);
+ const QString warnings = runQmllint(filename, true);
+ QVERIFY(warnings.isEmpty());
}
QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed)
@@ -173,18 +170,27 @@ QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed)
auto qmlImportDir = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath);
QStringList args;
args << QStringLiteral("-U") << testFile(fileToLint)
- << QStringLiteral("-I") << qmlImportDir;
- QProcess process;
- process.start(m_qmllintPath, args);
- [&]() {
+ << QStringLiteral("-I") << qmlImportDir
+ << QStringLiteral("--silent");
+ QString errors;
+ auto verify = [&](bool isSilent) {
+ QProcess process;
+ process.start(m_qmllintPath, args);
QVERIFY(process.waitForFinished());
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
if (shouldSucceed)
QCOMPARE(process.exitCode(), 0);
else
QVERIFY(process.exitCode() != 0);
- }();
- return process.readAllStandardError();
+ errors = process.readAllStandardError();
+
+ if (isSilent)
+ QVERIFY(errors.isEmpty());
+ };
+ verify(true);
+ args.removeLast();
+ verify(false);
+ return errors;
}
QTEST_MAIN(TestQmllint)