qmllint: Fix diagnostics output for test run

We do want to see the output if the cleanQmlCode test fails.

Change-Id: I6b7e9d3412af9fffac68d2e394418de2faf09626
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
This commit is contained in:
Ulf Hermann 2021-12-06 15:26:07 +01:00
parent 1ddaedbb8e
commit 0b175cb865
3 changed files with 10 additions and 6 deletions

View File

@ -121,7 +121,11 @@ bool QQmlLinter::lintFile(const QString &filename, const QString *fileContents,
QFile file(filename); QFile file(filename);
if (!file.open(QFile::ReadOnly)) { if (!file.open(QFile::ReadOnly)) {
if (json) { if (json) {
result[u"openFailed"] = true; addJsonWarning(QQmlJS::DiagnosticMessage {
QStringLiteral("Failed to open file %1: %2").arg(filename, file.errorString()),
QtCriticalMsg,
QQmlJS::SourceLocation()
});
success = false; success = false;
} else if (!silent) { } else if (!silent) {
qWarning() << "Failed to open file" << filename << file.error(); qWarning() << "Failed to open file" << filename << file.error();

View File

@ -1048,14 +1048,14 @@ void TestQmllint::callQmllint(const QString &fileToLint, bool shouldSucceed, QJs
bool success = m_linter.lintFile(QFileInfo(fileToLint).isAbsolute() ? fileToLint bool success = m_linter.lintFile(QFileInfo(fileToLint).isAbsolute() ? fileToLint
: testFile(fileToLint), : testFile(fileToLint),
nullptr, true, warnings ? &jsonOutput : nullptr, nullptr, false, warnings ? &jsonOutput : nullptr,
m_defaultImportPaths, QStringList(), QStringList(), {}); m_defaultImportPaths, QStringList(), QStringList(), {});
QCOMPARE(success, shouldSucceed);
if (warnings) { if (warnings) {
Q_ASSERT(jsonOutput.size() == 1); QVERIFY2(jsonOutput.size() == 1, QJsonDocument(jsonOutput).toJson());
*warnings = jsonOutput.at(0)[u"warnings"_qs].toArray(); *warnings = jsonOutput.at(0)[u"warnings"_qs].toArray();
} }
QCOMPARE(success, shouldSucceed);
} }
void TestQmllint::requiredProperty() void TestQmllint::requiredProperty()

View File

@ -51,7 +51,7 @@
#include <cstdio> #include <cstdio>
constexpr int JSON_LOGGING_FORMAT_REVISION = 1; constexpr int JSON_LOGGING_FORMAT_REVISION = 2;
int main(int argv, char *argc[]) int main(int argv, char *argc[])
{ {