From aa470fa92d8139ea849c00e01db5ffc537fe6981 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 29 Apr 2020 10:47:19 +0200 Subject: qmllint: warn when passing a directory to -i option It should be a file. Change-Id: I52f4ebcf8bdd8ddd1fedd66ceffe9a060139c1d9 Fixes: QTBUG-83861 Pick-to: 5.15 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qmllint/tst_qmllint.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tests/auto/qml/qmllint') diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 235748f55e..0f6fac4ddf 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -50,8 +50,10 @@ private Q_SLOTS: void testUnknownCausesFail(); + void directoryPassedAsQmlTypesFile(); + private: - QString runQmllint(const QString &fileToLint, bool shouldSucceed); + QString runQmllint(const QString &fileToLint, bool shouldSucceed, const QStringList &extraArgs = QStringList()); QString m_qmllintPath; }; @@ -114,6 +116,15 @@ void TestQmllint::testUnknownCausesFail() QStringLiteral("warning: Unknown was not found. Did you add all import paths?"))); } +void TestQmllint::directoryPassedAsQmlTypesFile() +{ + const QStringList iArg = QStringList() << QStringLiteral("-i") << dataDirectory(); + const QString errorMessages = runQmllint("unknownElement.qml", false, iArg); + const QString expectedError = QStringLiteral("warning: QML types file cannot be a directory: ") + dataDirectory(); + QVERIFY2(errorMessages.contains(expectedError), qPrintable(QString::fromLatin1( + "Expected error to contain \"%1\", but it didn't: %2").arg(expectedError, errorMessages))); +} + void TestQmllint::dirtyQmlCode_data() { QTest::addColumn("filename"); @@ -214,14 +225,15 @@ void TestQmllint::cleanQmlCode() QVERIFY(warnings.isEmpty()); } -QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed) +QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed, const QStringList &extraArgs) { auto qmlImportDir = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath); QStringList args; args << testFile(fileToLint) << QStringLiteral("-I") << qmlImportDir - << QStringLiteral("-I") << dataDirectory() - << QStringLiteral("--silent"); + << QStringLiteral("-I") << dataDirectory(); + args << extraArgs; + args << QStringLiteral("--silent"); QString errors; auto verify = [&](bool isSilent) { QProcess process; -- cgit v1.2.3