diff options
author | Fawzi Mohamed <fawzi@gmx.ch> | 2021-09-15 10:35:16 +0200 |
---|---|---|
committer | Fawzi Mohamed <fawzi@gmx.ch> | 2021-11-26 08:48:20 +0100 |
commit | 7f5db0b5e3abe6373087af4cea31bd6b2fa72d14 (patch) | |
tree | 4c8bec695b25dde1fd171ab320b19059065099d9 /tests/auto/qml/qmlformat | |
parent | 8da3036f098b8be3c4d31b3630a940375a707a89 (diff) |
qmlformat: test normalize on some examples
runs the normalization (AttributesSequence::Normalize) on some
examples, and do not just test the AttributesSequence::Preserve
reformatting.
Change-Id: I7d53f84174e841de1d63e8d3e1bdc339cf727f5f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmlformat')
-rw-r--r-- | tests/auto/qml/qmlformat/tst_qmlformat.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index f7795b4a88..6f35282164 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -59,6 +59,8 @@ private Q_SLOTS: #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled void testExample(); void testExample_data(); + void normalizeExample(); + void normalizeExample_data(); #endif private: @@ -324,6 +326,37 @@ void TestQmlformat::testExample_data() for (const QString &file : files) QTest::newRow(qPrintable(file)) << file; } + +void TestQmlformat::normalizeExample_data() +{ + if (QTestPrivate::isRunningArmOnX86()) + QSKIP("Crashes in QEMU. (timeout)"); + QTest::addColumn<QString>("file"); + + QString examples = QLatin1String(SRCDIR) + "/../../../../examples/"; + QString tests = QLatin1String(SRCDIR) + "/../../../../tests/"; + + // normalizeExample is similar to testExample, so we test it only on nExamples + nTests + // files to avoid making too many + QStringList files; + const int nExamples = 10; + int i = 0; + for (const auto &f : findFiles(QDir(examples))) { + files << f; + if (++i == nExamples) + break; + } + const int nTests = 10; + i = 0; + for (const auto &f : findFiles(QDir(tests))) { + files << f; + if (++i == nTests) + break; + } + + for (const QString &file : files) + QTest::newRow(qPrintable(file)) << file; +} #endif #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled @@ -339,6 +372,19 @@ void TestQmlformat::testExample() if (!isInvalid) QVERIFY(wasSuccessful && !output.isEmpty()); } + +void TestQmlformat::normalizeExample() +{ + QFETCH(QString, file); + const bool isInvalid = isInvalidFile(QFileInfo(file)); + bool wasSuccessful; + LineWriterOptions opts; + opts.attributesSequence = LineWriterOptions::AttributesSequence::Normalize; + QString output = formatInMemory(file, &wasSuccessful, opts); + + if (!isInvalid) + QVERIFY(wasSuccessful && !output.isEmpty()); +} #endif QString TestQmlformat::runQmlformat(const QString &fileToFormat, QStringList args, |