diff --git a/src/plugins/autotest/autotestconstants.h b/src/plugins/autotest/autotestconstants.h index 9b1f1a2adbc..2862e406dbc 100644 --- a/src/plugins/autotest/autotestconstants.h +++ b/src/plugins/autotest/autotestconstants.h @@ -42,14 +42,4 @@ const char UNNAMED_QUICKTESTS[] = QT_TR_NOOP(""); const char AUTOTEST_SETTINGS_CATEGORY[] = "ZY.Tests"; } // namespace Constants - -namespace Internal { - -enum TestType -{ - TestTypeQt, - TestTypeGTest -}; - -} // namespace Internal } // namespace Autotest diff --git a/src/plugins/autotest/testconfiguration.cpp b/src/plugins/autotest/testconfiguration.cpp index ba4597b36dc..543d3b8c034 100644 --- a/src/plugins/autotest/testconfiguration.cpp +++ b/src/plugins/autotest/testconfiguration.cpp @@ -24,6 +24,8 @@ ****************************************************************************/ #include "testconfiguration.h" +#include "testoutputreader.h" +#include "testsettings.h" #include #include @@ -43,19 +45,8 @@ using namespace ProjectExplorer; namespace Autotest { namespace Internal { -TestConfiguration::TestConfiguration(const QString &testClass, const QStringList &testCases, - int testCaseCount, QObject *parent) - : QObject(parent), - m_testClass(testClass), - m_testCases(testCases), - m_testCaseCount(testCaseCount), - m_unnamedOnly(false), - m_project(0), - m_guessedConfiguration(false), - m_type(TestTypeQt) +TestConfiguration::TestConfiguration() { - if (testCases.size() != 0) - m_testCaseCount = testCases.size(); } TestConfiguration::~TestConfiguration() @@ -252,19 +243,73 @@ void TestConfiguration::setProject(Project *project) m_project = project; } -void TestConfiguration::setUnnamedOnly(bool unnamedOnly) -{ - m_unnamedOnly = unnamedOnly; -} - void TestConfiguration::setGuessedConfiguration(bool guessed) { m_guessedConfiguration = guessed; } -void TestConfiguration::setTestType(TestType type) +TestOutputReader *QtTestConfiguration::outputReader(const QFutureInterface &fi, + QProcess *app) const { - m_type = type; + return new QtTestOutputReader(fi, app, buildDirectory()); +} + +QStringList QtTestConfiguration::argumentsForTestRunner(const TestSettings &settings) const +{ + QStringList arguments("-xml"); + + const QString &metricsOption = TestSettings::metricsTypeToOption(settings.metrics); + if (!metricsOption.isEmpty()) + arguments << metricsOption; + if (testCases().count()) + arguments << testCases(); + return arguments; +} + +TestOutputReader *QuickTestConfiguration::outputReader(const QFutureInterface &fi, + QProcess *app) const +{ + return new QtTestOutputReader(fi, app, buildDirectory()); +} + +QStringList QuickTestConfiguration::argumentsForTestRunner(const TestSettings &settings) const +{ + QStringList arguments("-xml"); + + const QString &metricsOption = TestSettings::metricsTypeToOption(settings.metrics); + if (!metricsOption.isEmpty()) + arguments << metricsOption; + if (testCases().count()) + arguments << testCases(); + return arguments; +} + +void QuickTestConfiguration::setUnnamedOnly(bool unnamedOnly) +{ + m_unnamedOnly = unnamedOnly; +} + +TestOutputReader *GoogleTestConfiguration::outputReader(const QFutureInterface &fi, + QProcess *app) const +{ + return new GTestOutputReader(fi, app, buildDirectory()); +} + +QStringList GoogleTestConfiguration::argumentsForTestRunner(const TestSettings &settings) const +{ + QStringList arguments; + const QStringList &testSets = testCases(); + if (testSets.size()) + arguments << QLatin1String("--gtest_filter=") + testSets.join(QLatin1Char(':')); + if (settings.gtestRunDisabled) + arguments << QLatin1String("--gtest_also_run_disabled_tests"); + if (settings.gtestRepeat) + arguments << QString::fromLatin1("--gtest_repeat=%1").arg(settings.gtestIterations); + if (settings.gtestShuffle) { + arguments << QLatin1String("--gtest_shuffle") + << QString::fromLatin1("--gtest_random_seed=%1").arg(settings.gtestSeed); + } + return arguments; } } // namespace Internal diff --git a/src/plugins/autotest/testconfiguration.h b/src/plugins/autotest/testconfiguration.h index ff00ad0d9f6..51a3e16e7e1 100644 --- a/src/plugins/autotest/testconfiguration.h +++ b/src/plugins/autotest/testconfiguration.h @@ -30,21 +30,30 @@ #include #include +#include #include #include #include +QT_BEGIN_NAMESPACE +class QProcess; +QT_END_NAMESPACE + namespace Autotest { namespace Internal { -class TestConfiguration : public QObject +class TestOutputReader; +class TestResult; +class TestSettings; + +using TestResultPtr = QSharedPointer; + +class TestConfiguration { - Q_OBJECT public: - explicit TestConfiguration(const QString &testClass, const QStringList &testCases, - int testCaseCount = 0, QObject *parent = 0); - ~TestConfiguration(); + explicit TestConfiguration(); + virtual ~TestConfiguration(); void completeTestInformation(); @@ -58,11 +67,8 @@ public: void setDisplayName(const QString &displayName); void setEnvironment(const Utils::Environment &env); void setProject(ProjectExplorer::Project *project); - void setUnnamedOnly(bool unnamedOnly); void setGuessedConfiguration(bool guessed); - void setTestType(TestType type); - QString testClass() const { return m_testClass; } QStringList testCases() const { return m_testCases; } int testCaseCount() const { return m_testCaseCount; } QString proFile() const { return m_proFile; } @@ -73,16 +79,15 @@ public: QString displayName() const { return m_displayName; } Utils::Environment environment() const { return m_environment; } ProjectExplorer::Project *project() const { return m_project.data(); } - bool unnamedOnly() const { return m_unnamedOnly; } bool guessedConfiguration() const { return m_guessedConfiguration; } - TestType testType() const { return m_type; } + + virtual TestOutputReader *outputReader(const QFutureInterface &fi, + QProcess *app) const = 0; + virtual QStringList argumentsForTestRunner(const TestSettings &settings) const = 0; private: - QString m_testClass; QStringList m_testCases; - int m_testCaseCount; - QString m_mainFilePath; - bool m_unnamedOnly; + int m_testCaseCount = 0; QString m_proFile; QString m_targetFile; QString m_targetName; @@ -91,8 +96,40 @@ private: QString m_displayName; Utils::Environment m_environment; QPointer m_project; - bool m_guessedConfiguration; - TestType m_type; + bool m_guessedConfiguration = false; +}; + +class QtTestConfiguration : public TestConfiguration +{ +public: + explicit QtTestConfiguration() {} + TestOutputReader *outputReader(const QFutureInterface &fi, + QProcess *app) const override; + QStringList argumentsForTestRunner(const TestSettings &settings) const override; +}; + +class QuickTestConfiguration : public TestConfiguration +{ +public: + explicit QuickTestConfiguration() {} + TestOutputReader *outputReader(const QFutureInterface &fi, + QProcess *app) const override; + QStringList argumentsForTestRunner(const TestSettings &settings) const override; + + void setUnnamedOnly(bool unnamedOnly); + bool unnamedOnly() const { return m_unnamedOnly; } + +private: + bool m_unnamedOnly = false; +}; + +class GoogleTestConfiguration : public TestConfiguration +{ +public: + explicit GoogleTestConfiguration() {} + TestOutputReader *outputReader(const QFutureInterface &fi, + QProcess *app) const override; + QStringList argumentsForTestRunner(const TestSettings &settings) const override; }; } // namespace Internal diff --git a/src/plugins/autotest/testrunner.cpp b/src/plugins/autotest/testrunner.cpp index 04e72db7925..dd781f02689 100644 --- a/src/plugins/autotest/testrunner.cpp +++ b/src/plugins/autotest/testrunner.cpp @@ -122,7 +122,6 @@ static void performTestRun(QFutureInterface &futureInterface, const TestSettings &settings) { const int timeout = settings.timeout; - const QString &metricsOption = TestSettings::metricsTypeToOption(settings.metrics); QEventLoop eventLoop; int testCaseCount = 0; foreach (TestConfiguration *config, selectedTests) { @@ -144,16 +143,8 @@ static void performTestRun(QFutureInterface &futureInterface, foreach (const TestConfiguration *testConfiguration, selectedTests) { QScopedPointer outputReader; - switch (testConfiguration->testType()) { - case TestTypeQt: - outputReader.reset(new QtTestOutputReader(futureInterface, &testProcess, - testConfiguration->buildDirectory())); - break; - case TestTypeGTest: - outputReader.reset(new GTestOutputReader(futureInterface, &testProcess, - testConfiguration->buildDirectory())); - break; - } + outputReader.reset(testConfiguration->outputReader(futureInterface, &testProcess)); + QTC_ASSERT(outputReader, continue); if (futureInterface.isCanceled()) break; @@ -170,31 +161,7 @@ static void performTestRun(QFutureInterface &futureInterface, continue; } - if (testConfiguration->testType() == TestTypeQt) { - QStringList argumentList(QLatin1String("-xml")); - if (!metricsOption.isEmpty()) - argumentList << metricsOption; - if (testConfiguration->testCases().count()) - argumentList << testConfiguration->testCases(); - testProcess.setArguments(argumentList); - } else { // TestTypeGTest - QStringList argumentList; - const QStringList &testSets = testConfiguration->testCases(); - if (testSets.size()) { - argumentList << QLatin1String("--gtest_filter=") - + testSets.join(QLatin1Char(':')); - } - if (settings.gtestRunDisabled) - argumentList << QLatin1String("--gtest_also_run_disabled_tests"); - if (settings.gtestRepeat) - argumentList << QString::fromLatin1("--gtest_repeat=%1").arg(settings.gtestIterations); - if (settings.gtestShuffle) { - argumentList << QLatin1String("--gtest_shuffle"); - argumentList << QString::fromLatin1("--gtest_random_seed=%1").arg(settings.gtestSeed); - } - testProcess.setArguments(argumentList); - } - + testProcess.setArguments(testConfiguration->argumentsForTestRunner(settings)); testProcess.setWorkingDirectory(testConfiguration->workingDirectory()); if (Utils::HostOsInfo::isWindowsHost()) environment.insert(QLatin1String("QT_LOGGING_TO_CONSOLE"), QLatin1String("1")); diff --git a/src/plugins/autotest/testtreeitem.cpp b/src/plugins/autotest/testtreeitem.cpp index a95866c180b..a692b7023a4 100644 --- a/src/plugins/autotest/testtreeitem.cpp +++ b/src/plugins/autotest/testtreeitem.cpp @@ -420,17 +420,19 @@ TestConfiguration *AutoTestTreeItem::testConfiguration() const ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); QTC_ASSERT(project, return 0); - TestConfiguration *config = 0; + QtTestConfiguration *config = 0; switch (type()) { case TestCase: - config = new TestConfiguration(name(), QStringList(), childCount()); + config = new QtTestConfiguration; + config->setTestCaseCount(childCount()); config->setProFile(proFile()); config->setProject(project); config->setDisplayName(TestUtils::getCMakeDisplayNameIfNecessary(filePath(), proFile())); break; case TestFunctionOrSet: { TestTreeItem *parent = parentItem(); - config = new TestConfiguration(parent->name(), QStringList() << name()); + config = new QtTestConfiguration(); + config->setTestCases(QStringList(name())); config->setProFile(parent->proFile()); config->setProject(project); config->setDisplayName( @@ -443,7 +445,8 @@ TestConfiguration *AutoTestTreeItem::testConfiguration() const if (!parent) return 0; const QString functionWithTag = function->name() + QLatin1Char(':') + name(); - config = new TestConfiguration(parent->name(), QStringList() << functionWithTag); + config = new QtTestConfiguration(); + config->setTestCases(QStringList(functionWithTag)); config->setProFile(parent->proFile()); config->setProject(project); config->setDisplayName(TestUtils::getCMakeDisplayNameIfNecessary(filePath(), @@ -467,8 +470,8 @@ QList AutoTestTreeItem::getAllTestConfigurations() const for (int row = 0, count = childCount(); row < count; ++row) { const TestTreeItem *child = childItem(row); - TestConfiguration *tc = new TestConfiguration(child->name(), QStringList(), - child->childCount()); + TestConfiguration *tc = new QtTestConfiguration(); + tc->setTestCaseCount(child->childCount()); tc->setProFile(child->proFile()); tc->setProject(project); tc->setDisplayName(TestUtils::getCMakeDisplayNameIfNecessary(child->filePath(), @@ -485,7 +488,7 @@ QList AutoTestTreeItem::getSelectedTestConfigurations() con if (!project || type() != Root) return result; - TestConfiguration *testConfiguration = 0; + QtTestConfiguration *testConfiguration = 0; for (int row = 0, count = childCount(); row < count; ++row) { const TestTreeItem *child = childItem(row); @@ -494,7 +497,8 @@ QList AutoTestTreeItem::getSelectedTestConfigurations() con case Qt::Unchecked: continue; case Qt::Checked: - testConfiguration = new TestConfiguration(child->name(), QStringList(), child->childCount()); + testConfiguration = new QtTestConfiguration(); + testConfiguration->setTestCaseCount(child->childCount()); testConfiguration->setProFile(child->proFile()); testConfiguration->setProject(project); testConfiguration->setDisplayName( @@ -503,7 +507,6 @@ QList AutoTestTreeItem::getSelectedTestConfigurations() con continue; case Qt::PartiallyChecked: default: - const QString childName = child->name(); int grandChildCount = child->childCount(); QStringList testCases; for (int grandChildRow = 0; grandChildRow < grandChildCount; ++grandChildRow) { @@ -512,7 +515,8 @@ QList AutoTestTreeItem::getSelectedTestConfigurations() con testCases << grandChild->name(); } - testConfiguration = new TestConfiguration(childName, testCases); + testConfiguration = new QtTestConfiguration(); + testConfiguration->setTestCases(testCases); testConfiguration->setProFile(child->proFile()); testConfiguration->setProject(project); testConfiguration->setDisplayName( @@ -646,13 +650,14 @@ TestConfiguration *QuickTestTreeItem::testConfiguration() const ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); QTC_ASSERT(project, return 0); - TestConfiguration *config = 0; + QuickTestConfiguration *config = 0; switch (type()) { case TestCase: { QStringList testFunctions; for (int row = 0, count = childCount(); row < count; ++row) testFunctions << name() + QLatin1String("::") + childItem(row)->name(); - config = new TestConfiguration(QString(), testFunctions); + config = new QuickTestConfiguration; + config->setTestCases(testFunctions); config->setProFile(proFile()); config->setProject(project); break; @@ -660,7 +665,8 @@ TestConfiguration *QuickTestTreeItem::testConfiguration() const case TestFunctionOrSet: { TestTreeItem *parent = parentItem(); QStringList testFunction(parent->name() + QLatin1String("::") + name()); - config = new TestConfiguration(QString(), testFunction); + config = new QuickTestConfiguration; + config->setTestCases(testFunction); config->setProFile(parent->proFile()); config->setProject(project); break; @@ -699,7 +705,8 @@ QList QuickTestTreeItem::getAllTestConfigurations() const QHash::ConstIterator it = foundProFiles.begin(); QHash::ConstIterator end = foundProFiles.end(); for ( ; it != end; ++it) { - TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value()); + QuickTestConfiguration *tc = new QuickTestConfiguration; + tc->setTestCaseCount(it.value()); tc->setProFile(it.key()); tc->setProject(project); result << tc; @@ -714,8 +721,8 @@ QList QuickTestTreeItem::getSelectedTestConfigurations() co if (!project || type() != Root) return result; - TestConfiguration *tc = 0; - QHash foundProFiles; + QuickTestConfiguration *tc = 0; + QHash foundProFiles; // unnamed Quick Tests must be handled first if (TestTreeItem *unnamed = unnamedQuickTests()) { for (int childRow = 0, ccount = unnamed->childCount(); childRow < ccount; ++ childRow) { @@ -727,7 +734,7 @@ QList QuickTestTreeItem::getSelectedTestConfigurations() co return QList()); foundProFiles[proFile]->setTestCaseCount(tc->testCaseCount() + 1); } else { - tc = new TestConfiguration(QString(), QStringList()); + tc = new QuickTestConfiguration; tc->setTestCaseCount(1); tc->setUnnamedOnly(true); tc->setProFile(proFile); @@ -771,7 +778,8 @@ QList QuickTestTreeItem::getSelectedTestConfigurations() co tc->setTestCases(oldFunctions); } } else { - tc = new TestConfiguration(QString(), testFunctions); + tc = new QuickTestConfiguration; + tc->setTestCases(testFunctions); tc->setProFile(child->proFile()); tc->setProject(project); foundProFiles.insert(child->proFile(), tc); @@ -779,10 +787,10 @@ QList QuickTestTreeItem::getSelectedTestConfigurations() co break; } } - QHash::ConstIterator it = foundProFiles.begin(); - QHash::ConstIterator end = foundProFiles.end(); + QHash::ConstIterator it = foundProFiles.begin(); + QHash::ConstIterator end = foundProFiles.end(); for ( ; it != end; ++it) { - TestConfiguration *config = it.value(); + QuickTestConfiguration *config = it.value(); if (!config->unnamedOnly()) result << config; else @@ -888,19 +896,19 @@ TestConfiguration *GoogleTestTreeItem::testConfiguration() const ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject(); QTC_ASSERT(project, return 0); - TestConfiguration *config = 0; + GoogleTestConfiguration *config = 0; switch (type()) { case TestCase: { const QString &testSpecifier = gtestFilter(state()).arg(name()).arg(QLatin1Char('*')); if (int count = childCount()) { - config = new TestConfiguration(QString(), QStringList(testSpecifier)); + config = new GoogleTestConfiguration; + config->setTestCases(QStringList(testSpecifier)); config->setTestCaseCount(count); config->setProFile(proFile()); config->setProject(project); // item has no filePath set - so take it of the first children config->setDisplayName( TestUtils::getCMakeDisplayNameIfNecessary(childItem(0)->filePath(), proFile())); - config->setTestType(TestTypeGTest); } break; } @@ -909,12 +917,12 @@ TestConfiguration *GoogleTestTreeItem::testConfiguration() const if (parent) return 0; const QString &testSpecifier = gtestFilter(parent->state()).arg(parent->name()).arg(name()); - config = new TestConfiguration(QString(), QStringList(testSpecifier)); + config = new GoogleTestConfiguration; + config->setTestCases(QStringList(testSpecifier)); config->setProFile(proFile()); config->setProject(project); config->setDisplayName( TestUtils::getCMakeDisplayNameIfNecessary(filePath(), parent->proFile())); - config->setTestType(TestTypeGTest); break; } default: @@ -980,8 +988,8 @@ QList GoogleTestTreeItem::getAllTestConfigurations() const QHash::ConstIterator end = proFilesWithTestSets.end(); for ( ; it != end; ++it) { const ProFileWithDisplayName &key = it.key(); - TestConfiguration *tc = new TestConfiguration(QString(), QStringList(), it.value()); - tc->setTestType(TestTypeGTest); + GoogleTestConfiguration *tc = new GoogleTestConfiguration; + tc->setTestCaseCount(it.value()); tc->setProFile(key.proFile); tc->setDisplayName(key.displayName); tc->setProject(project); @@ -1022,8 +1030,8 @@ QList GoogleTestTreeItem::getSelectedTestConfigurations() c QHash::ConstIterator end = proFilesWithCheckedTestSets.end(); for ( ; it != end; ++it) { const ProFileWithDisplayName &key = it.key(); - TestConfiguration *tc = new TestConfiguration(QString(), it.value()); - tc->setTestType(TestTypeGTest); + GoogleTestConfiguration *tc = new GoogleTestConfiguration; + tc->setTestCases(it.value()); tc->setProFile(key.proFile); tc->setDisplayName(key.displayName); tc->setProject(project);