diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2020-03-26 01:00:11 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-04-09 10:08:41 +0200 |
commit | 2812184e1bb87cd94d2989162bc6ea954bb585c4 (patch) | |
tree | 25460548730e2ddc1f6f328d54e97d3fbfb49d21 /tests/auto/qml/qmlformat/tst_qmlformat.cpp | |
parent | cd4a99a7ba92968bf88da9af2624bb738d71e726 (diff) | |
parent | bf205b45a29ba80d94df3b6bac5fec4c7cd79bf9 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
src/qml/jsruntime/qv4executablecompilationunit.cpp
src/qml/jsruntime/qv4executablecompilationunit_p.h
src/qml/qml/qqmlobjectcreator.cpp
src/qml/qml/qqmlpropertycachecreator_p.h
src/qml/qml/qqmltypecompiler.cpp
src/qml/qml/qqmltypedata.cpp
tests/auto/qml/qmlformat/tst_qmlformat.cpp
tools/qmllint/scopetree.cpp
src/qml/qml/qqmlapplicationengine_p.h
Adjusted tools/qmllint/findunqualified.cpp to use newer API
Change-Id: Ibfb4678ca39d626d47527265e3c96e43313873d4
Diffstat (limited to 'tests/auto/qml/qmlformat/tst_qmlformat.cpp')
-rw-r--r-- | tests/auto/qml/qmlformat/tst_qmlformat.cpp | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index 21d5ae46a9..997a5cc753 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -27,8 +27,11 @@ ****************************************************************************/ #include <QtTest/QtTest> +#include <QDir> +#include <QFile> #include <QProcess> #include <QString> +#include <QTemporaryDir> #include <util.h> @@ -43,6 +46,9 @@ private Q_SLOTS: void testFormatNoSort(); void testAnnotations(); void testAnnotationsNoSort(); + void testLineEndings(); + void testFrontInline(); + void testIfBlocks(); void testReadOnlyProps(); void testStatesAndTransitions(); @@ -55,7 +61,7 @@ private Q_SLOTS: private: QString readTestFile(const QString &path); - QString runQmlformat(const QString &fileToFormat, bool sortImports, bool shouldSucceed); + QString runQmlformat(const QString &fileToFormat, bool sortImports, bool shouldSucceed, const QString &newlineFormat = "native"); QString m_qmlformatPath; QStringList m_excludedDirs; @@ -113,6 +119,7 @@ void TestQmlformat::initTestCase() m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.1.qml"; m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/numberParsing_error.2.qml"; m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/incrDecrSemicolon_error1.qml"; + m_invalidFiles << "tests/auto/qml/qqmlecmascript/data/incrDecrSemicolon_error1.qml"; m_invalidFiles << "tests/auto/qml/debugger/qqmlpreview/data/broken.qml"; m_invalidFiles << "tests/auto/qml/qqmllanguage/data/fuzzed.2.qml"; m_invalidFiles << "tests/auto/qml/qqmllanguage/data/fuzzed.3.qml"; @@ -197,6 +204,16 @@ void TestQmlformat::testAnnotationsNoSort() QCOMPARE(runQmlformat(testFile("Annotations.qml"), false, true), readTestFile("Annotations.formatted.nosort.qml")); } +void TestQmlformat::testFrontInline() +{ + QCOMPARE(runQmlformat(testFile("FrontInline.qml"), false, true), readTestFile("FrontInline.formatted.qml")); +} + +void TestQmlformat::testIfBlocks() +{ + QCOMPARE(runQmlformat(testFile("IfBlocks.qml"), false, true), readTestFile("IfBlocks.formatted.qml")); +} + void TestQmlformat::testReadOnlyProps() { QCOMPARE(runQmlformat(testFile("readOnlyProps.qml"), false, true), readTestFile("readOnlyProps.formatted.qml")); @@ -212,6 +229,23 @@ void TestQmlformat::testLargeBindings() QCOMPARE(runQmlformat(testFile("largeBindings.qml"), false, true), readTestFile("largeBindings.formatted.qml")); } +void TestQmlformat::testLineEndings() +{ + // macos + const QString macosContents = runQmlformat(testFile("Example1.formatted.qml"), false, true, "macos"); + QVERIFY(!macosContents.contains("\n")); + QVERIFY(macosContents.contains("\r")); + + // windows + const QString windowsContents = runQmlformat(testFile("Example1.formatted.qml"), false, true, "windows"); + QVERIFY(windowsContents.contains("\r\n")); + + // unix + const QString unixContents = runQmlformat(testFile("Example1.formatted.qml"), false, true, "unix"); + QVERIFY(unixContents.contains("\n")); + QVERIFY(!unixContents.contains("\r")); +} + #if !defined(QTEST_CROSS_COMPILED) // sources not available when cross compiled void TestQmlformat::testExample_data() { @@ -240,15 +274,22 @@ void TestQmlformat::testExample() } #endif -QString TestQmlformat::runQmlformat(const QString &fileToFormat, bool sortImports, bool shouldSucceed) +QString TestQmlformat::runQmlformat(const QString &fileToFormat, bool sortImports, bool shouldSucceed, const QString &newlineFormat) { + // Copy test file to temporary location + QTemporaryDir tempDir; + const QString tempFile = tempDir.path() + QDir::separator() + "to_format.qml"; + QFile::copy(fileToFormat, tempFile); + QStringList args; - args << fileToFormat; + args << "-i"; + args << tempFile; if (!sortImports) args << "-n"; - QString output; + args << "-l" << newlineFormat; + auto verify = [&]() { QProcess process; process.start(m_qmlformatPath, args); @@ -256,13 +297,15 @@ QString TestQmlformat::runQmlformat(const QString &fileToFormat, bool sortImport QCOMPARE(process.exitStatus(), QProcess::NormalExit); if (shouldSucceed) QCOMPARE(process.exitCode(), 0); - else - QVERIFY(process.exitCode() != 0); - output = process.readAllStandardOutput(); }; verify(); - return output; + QFile temp(tempFile); + + temp.open(QIODevice::ReadOnly); + QString formatted = QString::fromUtf8(temp.readAll()); + + return formatted; } QTEST_MAIN(TestQmlformat) |