diff options
| -rw-r--r-- | tests/auto/qmldom/reformatter/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | tests/auto/qmldom/reformatter/tst_reformatter.h | 30 | ||||
| -rw-r--r-- | tools/qmldom/qmldomtool.cpp | 4 |
3 files changed, 35 insertions, 1 deletions
diff --git a/tests/auto/qmldom/reformatter/CMakeLists.txt b/tests/auto/qmldom/reformatter/CMakeLists.txt index 1b8cfb0d8a..9f6badfa5c 100644 --- a/tests/auto/qmldom/reformatter/CMakeLists.txt +++ b/tests/auto/qmldom/reformatter/CMakeLists.txt @@ -34,3 +34,5 @@ qt_internal_extend_target(tst_reformatter CONDITION ANDROID OR IOS DEFINES QT_REFORMATTERTEST_DATADIR=":/domdata" ) + +add_dependencies(tst_reformatter Qt6::qmldom) diff --git a/tests/auto/qmldom/reformatter/tst_reformatter.h b/tests/auto/qmldom/reformatter/tst_reformatter.h index b1f58ca8b4..f46f86c0c3 100644 --- a/tests/auto/qmldom/reformatter/tst_reformatter.h +++ b/tests/auto/qmldom/reformatter/tst_reformatter.h @@ -12,7 +12,10 @@ #include <QtTest/QTest> #include <QCborValue> #include <QDebug> +#include <QFile> #include <QLibraryInfo> +#include <QProcess> +#include <QTemporaryDir> #include <memory> @@ -939,6 +942,33 @@ private slots: QCOMPARE(formattedCode, expectedFormattedCode); } +#if QT_CONFIG(process) + void qmldomToolReformat() + { + const QByteArray code = "import QtQml\n\nQtObject {\n}\n"; + const QByteArray in = "\n\n" + code; + const QByteArray out = code; + + QTemporaryDir dir; + QVERIFY(dir.isValid()); + QFile file(dir.filePath("File.qml")); + QVERIFY(file.open(QIODevice::Text | QIODevice::ReadWrite)); + QCOMPARE_NE(file.write(in), -1); + file.close(); + + QProcess qmldom; + qmldom.setProgram(QLibraryInfo::path(QLibraryInfo::BinariesPath) + "/qmldom"_L1); + qmldom.setArguments({ "--reformat"_L1, file.fileName() }); + qmldom.start(); + QVERIFY(qmldom.waitForFinished()); + QCOMPARE(qmldom.exitStatus(), QProcess::NormalExit); + QCOMPARE(qmldom.exitCode(), 0); + + QVERIFY(file.open(QIODevice::Text | QIODevice::ReadOnly)); + QCOMPARE(file.readAll(), out); + } +#endif + private: }; diff --git a/tools/qmldom/qmldomtool.cpp b/tools/qmldom/qmldomtool.cpp index 5c38230ba2..07b63b3920 100644 --- a/tools/qmldom/qmldomtool.cpp +++ b/tools/qmldom/qmldomtool.cpp @@ -200,13 +200,15 @@ int main(int argc, char *argv[]) loadedFiles[iPos] = newIt; }, fileType); + ++iPos; } envPtr->loadPendingDependencies(); bool hadFailures = false; const qsizetype largestFileSizeToCheck = 32000; if (parser.isSet(reformatOption)) { - for (auto &qmlFile : loadedFiles) { + for (const DomItem &loadedFile : std::as_const(loadedFiles)) { + DomItem qmlFile = loadedFile.fileObject(); QString qmlFilePath = qmlFile.canonicalFilePath(); if (qmlFile.internalKind() != DomType::QmlFile) { qWarning() << "cannot reformat" << qmlFile.internalKindStr() << "(" << qmlFilePath |
