From fd1c290a483429e09a25c19beb6697bb70f17e8d Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 7 Oct 2016 13:03:00 +0200 Subject: [PATCH] Qmake: Add tests for MakefileParser Change-Id: I6206faad1e98f0867aba67b05b64916deb77b9f8 Reviewed-by: Tim Jenssen --- .../qmakeprojectmanager/makefileparse.cpp | 205 +++++++++++++++--- .../qmakeprojectmanager/makefileparse.h | 2 + .../qmakeprojectmanagerplugin.h | 2 + 3 files changed, 178 insertions(+), 31 deletions(-) diff --git a/src/plugins/qmakeprojectmanager/makefileparse.cpp b/src/plugins/qmakeprojectmanager/makefileparse.cpp index 2b284d9808c..fe97ea06d67 100644 --- a/src/plugins/qmakeprojectmanager/makefileparse.cpp +++ b/src/plugins/qmakeprojectmanager/makefileparse.cpp @@ -301,38 +301,8 @@ MakeFileParse::MakeFileParse(const QString &makefile) } line = trimLine(line); + parseCommandLine(line); - QList assignments; - QList afterAssignments; - // Split up args into assignments and other arguments, writes m_unparsedArguments - parseArgs(line, &assignments, &afterAssignments); - qCDebug(logging()) << " Initial assignments:"; - dumpQMakeAssignments(assignments); - - // Filter out CONFIG arguments we know into m_qmakeBuildConfig and m_config - parseAssignments(&assignments); - qCDebug(logging()) << " After parsing"; - dumpQMakeAssignments(assignments); - - qCDebug(logging()) << " Explicit Debug" << m_qmakeBuildConfig.explicitDebug; - qCDebug(logging()) << " Explicit Release" << m_qmakeBuildConfig.explicitRelease; - qCDebug(logging()) << " Explicit BuildAll" << m_qmakeBuildConfig.explicitBuildAll; - qCDebug(logging()) << " Explicit NoBuildAll" << m_qmakeBuildConfig.explicitNoBuildAll; - qCDebug(logging()) << " TargetArch" << m_config.archConfig; - qCDebug(logging()) << " OsType" << m_config.osType; - qCDebug(logging()) << " LinkQmlDebuggingQQ2" << m_config.linkQmlDebuggingQQ2; - qCDebug(logging()) << " Qt Quick Compiler" << m_config.useQtQuickCompiler; - qCDebug(logging()) << " Separate Debug Info" << m_config.separateDebugInfo; - - - // Create command line of all unfiltered arguments - foreach (const QMakeAssignment &qa, assignments) - QtcProcess::addArg(&m_unparsedArguments, qa.variable + qa.op + qa.value); - if (!afterAssignments.isEmpty()) { - QtcProcess::addArg(&m_unparsedArguments, QLatin1String("-after")); - foreach (const QMakeAssignment &qa, afterAssignments) - QtcProcess::addArg(&m_unparsedArguments, qa.variable + qa.op + qa.value); - } m_state = Okay; } @@ -382,3 +352,176 @@ const QLoggingCategory &MakeFileParse::logging() return category; } +void MakeFileParse::parseCommandLine(const QString &command) +{ + + QList assignments; + QList afterAssignments; + // Split up args into assignments and other arguments, writes m_unparsedArguments + parseArgs(command, &assignments, &afterAssignments); + qCDebug(logging()) << " Initial assignments:"; + dumpQMakeAssignments(assignments); + + // Filter out CONFIG arguments we know into m_qmakeBuildConfig and m_config + parseAssignments(&assignments); + qCDebug(logging()) << " After parsing"; + dumpQMakeAssignments(assignments); + + qCDebug(logging()) << " Explicit Debug" << m_qmakeBuildConfig.explicitDebug; + qCDebug(logging()) << " Explicit Release" << m_qmakeBuildConfig.explicitRelease; + qCDebug(logging()) << " Explicit BuildAll" << m_qmakeBuildConfig.explicitBuildAll; + qCDebug(logging()) << " Explicit NoBuildAll" << m_qmakeBuildConfig.explicitNoBuildAll; + qCDebug(logging()) << " TargetArch" << m_config.archConfig; + qCDebug(logging()) << " OsType" << m_config.osType; + qCDebug(logging()) << " LinkQmlDebuggingQQ2" << m_config.linkQmlDebuggingQQ2; + qCDebug(logging()) << " Qt Quick Compiler" << m_config.useQtQuickCompiler; + qCDebug(logging()) << " Separate Debug Info" << m_config.separateDebugInfo; + + // Create command line of all unfiltered arguments + foreach (const QMakeAssignment &qa, assignments) + QtcProcess::addArg(&m_unparsedArguments, qa.variable + qa.op + qa.value); + if (!afterAssignments.isEmpty()) { + QtcProcess::addArg(&m_unparsedArguments, QLatin1String("-after")); + foreach (const QMakeAssignment &qa, afterAssignments) + QtcProcess::addArg(&m_unparsedArguments, qa.variable + qa.op + qa.value); + } +} + + +// Unit tests: + +#ifdef WITH_TESTS +# include + +# include "qmakeprojectmanagerplugin.h" + +# include "projectexplorer/outputparser_test.h" + +using namespace QmakeProjectManager::Internal; +using namespace ProjectExplorer; + +void QmakeProjectManagerPlugin::testMakefileParser_data() +{ + QTest::addColumn("command"); + QTest::addColumn("project"); + QTest::addColumn("unparsedArguments"); + QTest::addColumn("archConfig"); + QTest::addColumn("osType"); + QTest::addColumn("linkQmlDebuggingQQ2"); + QTest::addColumn("useQtQuickCompiler"); + QTest::addColumn("separateDebugInfo"); + QTest::addColumn("effectiveBuildConfig"); + + QTest::newRow("Qt 5.7") + << QString::fromLatin1("-spec linux-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../untitled7/untitled7.pro") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.7 extra1") + << QString::fromLatin1("SOMETHING=ELSE -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../untitled7/untitled7.pro") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.7 extra2") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE CONFIG+=debug CONFIG+=qml_debug -o Makefile ../untitled7/untitled7.pro") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.7 extra3") + << QString::fromLatin1("-spec linux-g++ CONFIG+=debug SOMETHING=ELSE CONFIG+=qml_debug -o Makefile ../untitled7/untitled7.pro") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.7 extra4") + << QString::fromLatin1("-spec linux-g++ CONFIG+=debug CONFIG+=qml_debug SOMETHING=ELSE -o Makefile ../untitled7/untitled7.pro") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.7 extra5") + << QString::fromLatin1("-spec linux-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile SOMETHING=ELSE ../untitled7/untitled7.pro") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.7 extra6") + << QString::fromLatin1("-spec linux-g++ CONFIG+=debug CONFIG+=qml_debug -o Makefile ../untitled7/untitled7.pro SOMETHING=ELSE") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.8") + << QString::fromLatin1("-o Makefile ../untitled7/untitled7.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.8 extra1") + << QString::fromLatin1("SOMETHING=ELSE -o Makefile ../untitled7/untitled7.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.8 extra2") + << QString::fromLatin1("-o Makefile SOMETHING=ELSE ../untitled7/untitled7.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.8 extra3") + << QString::fromLatin1("-o Makefile ../untitled7/untitled7.pro SOMETHING=ELSE -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.8 extra4") + << QString::fromLatin1("-o Makefile ../untitled7/untitled7.pro -spec linux-g++ SOMETHING=ELSE CONFIG+=debug CONFIG+=qml_debug") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.8 extra5") + << QString::fromLatin1("-o Makefile ../untitled7/untitled7.pro -spec linux-g++ CONFIG+=debug SOMETHING=ELSE CONFIG+=qml_debug") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; + QTest::newRow("Qt 5.8 extra6") + << QString::fromLatin1("-o Makefile ../untitled7/untitled7.pro -spec linux-g++ CONFIG+=debug CONFIG+=qml_debug SOMETHING=ELSE") + << QString::fromLatin1("../untitled7/untitled7.pro") + << QString::fromLatin1("-spec linux-g++ SOMETHING=ELSE") + << static_cast(QMakeStepConfig::NoArch) << static_cast(QMakeStepConfig::NoOsType) + << true << false << false << 2; +} + +void QmakeProjectManagerPlugin::testMakefileParser() +{ + QFETCH(QString, command); + QFETCH(QString, project); + QFETCH(QString, unparsedArguments); + QFETCH(int, archConfig); + QFETCH(int, osType); + QFETCH(bool, linkQmlDebuggingQQ2); + QFETCH(bool, useQtQuickCompiler); + QFETCH(bool, separateDebugInfo); + QFETCH(int, effectiveBuildConfig); + + MakeFileParse parser("/tmp/something"); + parser.parseCommandLine(command, project); + + QCOMPARE(Utils::QtcProcess::splitArgs(parser.unparsedArguments()), + Utils::QtcProcess::splitArgs(unparsedArguments)); + QCOMPARE(parser.effectiveBuildConfig(0), effectiveBuildConfig); + + const QMakeStepConfig qmsc = parser.config(); + QCOMPARE(qmsc.archConfig, static_cast(archConfig)); + QCOMPARE(qmsc.osType, static_cast(osType)); + QCOMPARE(qmsc.linkQmlDebuggingQQ2, linkQmlDebuggingQQ2); + QCOMPARE(qmsc.useQtQuickCompiler, useQtQuickCompiler); + QCOMPARE(qmsc.separateDebugInfo, separateDebugInfo); +} +#endif diff --git a/src/plugins/qmakeprojectmanager/makefileparse.h b/src/plugins/qmakeprojectmanager/makefileparse.h index 9a8783d2476..57eb706180f 100644 --- a/src/plugins/qmakeprojectmanager/makefileparse.h +++ b/src/plugins/qmakeprojectmanager/makefileparse.h @@ -62,6 +62,8 @@ public: static const QLoggingCategory &logging(); + void parseCommandLine(const QString &command); + private: void parseArgs(const QString &args, QList *assignments, QList *afterAssignments); void parseAssignments(QList *assignments); diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h index 473065f5f17..3aa04d5607d 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.h @@ -61,6 +61,8 @@ public: private slots: void testQmakeOutputParsers_data(); void testQmakeOutputParsers(); + void testMakefileParser_data(); + void testMakefileParser(); #endif private: