Commit 18dc7a5d authored by Christian Stenger's avatar Christian Stenger
Browse files

AutoTest: Move framework settings into framework manager



Change-Id: I9914291adb102de5136802eb3b6d12afb6276538
Reviewed-by: David Schulz's avatarDavid Schulz <david.schulz@qt.io>
parent a6032652
......@@ -80,6 +80,7 @@ HEADERS += \
gtest/gtestvisitors.h \
gtest/gtestframework.h \
gtest/gtestsettings.h \
gtest/gtestconstants.h \
qtest/qttesttreeitem.h \
qtest/qttest_utils.h \
qtest/qttestresult.h \
......@@ -89,6 +90,7 @@ HEADERS += \
qtest/qttestparser.h \
qtest/qttestframework.h \
qtest/qttestsettings.h \
qtest/qttestconstants.h \
quick/quicktestconfiguration.h \
quick/quicktestparser.h \
quick/quicktesttreeitem.h \
......
......@@ -41,5 +41,7 @@ const char TASK_PARSE[] = "AutoTest.Task.Parse";
const char AUTOTEST_SETTINGS_CATEGORY[] = "ZY.Tests";
const char FRAMEWORK_PREFIX[] = "AutoTest.Framework.";
const char SETTINGSGROUP[] = "Autotest";
} // namespace Constants
} // namespace Autotest
......@@ -135,7 +135,7 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
m_frameworkManager->registerTestFramework(new QuickTestFramework);
m_frameworkManager->registerTestFramework(new GTestFramework);
m_settings->fromSettings(ICore::settings());
m_frameworkManager->synchronizeSettings(ICore::settings());
addAutoReleasedObject(new TestSettingsPage(m_settings));
addAutoReleasedObject(new TestNavigationWidgetFactory);
addAutoReleasedObject(TestResultsPane::instance());
......
......@@ -24,8 +24,10 @@
****************************************************************************/
#include "gtestconfiguration.h"
#include "gtestconstants.h"
#include "gtestoutputreader.h"
#include "../testsettings.h"
#include "gtestsettings.h"
#include "../testframeworkmanager.h"
namespace Autotest {
namespace Internal {
......@@ -36,25 +38,32 @@ TestOutputReader *GTestConfiguration::outputReader(const QFutureInterface<TestRe
return new GTestOutputReader(fi, app, buildDirectory());
}
QStringList GTestConfiguration::argumentsForTestRunner(const TestSettings &settings) const
QStringList GTestConfiguration::argumentsForTestRunner() const
{
static const Core::Id id
= Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(GTest::Constants::FRAMEWORK_NAME);
QStringList arguments;
const QStringList &testSets = testCases();
if (testSets.size())
arguments << "--gtest_filter=" + testSets.join(':');
if (settings.gTestSettings.runDisabled)
TestFrameworkManager *manager = TestFrameworkManager::instance();
auto gSettings = qSharedPointerCast<GTestSettings>(manager->settingsForTestFramework(id));
if (gSettings.isNull())
return arguments;
if (gSettings->runDisabled)
arguments << "--gtest_also_run_disabled_tests";
if (settings.gTestSettings.repeat)
arguments << QString("--gtest_repeat=%1").arg(settings.gTestSettings.iterations);
if (settings.gTestSettings.shuffle) {
arguments << "--gtest_shuffle"
<< QString("--gtest_random_seed=%1").arg(settings.gTestSettings.seed);
}
if (settings.gTestSettings.throwOnFailure)
if (gSettings->repeat)
arguments << QString("--gtest_repeat=%1").arg(gSettings->iterations);
if (gSettings->shuffle)
arguments << "--gtest_shuffle" << QString("--gtest_random_seed=%1").arg(gSettings->seed);
if (gSettings->throwOnFailure)
arguments << "--gtest_throw_on_failure";
if (runMode() == DebuggableTestConfiguration::Debug) {
if (settings.gTestSettings.breakOnFailure)
if (gSettings->breakOnFailure)
arguments << "--gtest_break_on_failure";
}
return arguments;
......
......@@ -36,7 +36,7 @@ public:
explicit GTestConfiguration() {}
TestOutputReader *outputReader(const QFutureInterface<TestResultPtr> &fi,
QProcess *app) const override;
QStringList argumentsForTestRunner(const TestSettings &settings) const override;
QStringList argumentsForTestRunner() const override;
};
} // namespace Internal
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QtGlobal>
namespace Autotest {
namespace GTest {
namespace Constants {
const char FRAMEWORK_NAME[] = "GTest";
const char FRAMEWORK_SETTINGS_CATEGORY[] = QT_TRANSLATE_NOOP("GTestFramework", "Google Test");
const unsigned FRAMEWORK_PRIORITY = 10;
} // namespace Constants
} // namespace GTest
} // namespace AutoTest
......@@ -24,6 +24,8 @@
****************************************************************************/
#include "gtestframework.h"
#include "gtestconstants.h"
#include "gtestsettings.h"
#include "gtesttreeitem.h"
#include "gtestparser.h"
......@@ -37,18 +39,30 @@ ITestParser *GTestFramework::createTestParser() const
TestTreeItem *GTestFramework::createRootNode() const
{
return new GTestTreeItem(QCoreApplication::translate("GTestFramework", "Google Tests"),
return new GTestTreeItem(
QCoreApplication::translate("GTestFramework",
GTest::Constants::FRAMEWORK_SETTINGS_CATEGORY),
QString(), TestTreeItem::Root);
}
const char *GTestFramework::name() const
{
return "GTest";
return GTest::Constants::FRAMEWORK_NAME;
}
unsigned GTestFramework::priority() const
{
return 10;
return GTest::Constants::FRAMEWORK_PRIORITY;
}
IFrameworkSettings *GTestFramework::createFrameworkSettings() const
{
return new GTestSettings;
}
bool GTestFramework::hasFrameworkSettings() const
{
return true;
}
} // namespace Internal
......
......@@ -36,6 +36,8 @@ public:
GTestFramework() : ITestFramework(true) {}
const char *name() const override;
unsigned priority() const override;
IFrameworkSettings *createFrameworkSettings() const override;
bool hasFrameworkSettings() const override;
protected:
ITestParser *createTestParser() const override;
......
......@@ -31,6 +31,8 @@
namespace Autotest {
namespace Internal {
class IFrameworkSettings;
class ITestFramework
{
public:
......@@ -43,6 +45,8 @@ public:
virtual const char *name() const = 0;
virtual unsigned priority() const = 0; // should this be modifyable?
virtual bool hasFrameworkSettings() const { return false; }
virtual IFrameworkSettings *createFrameworkSettings() const { return 0; }
TestTreeItem *rootNode()
{ if (!m_rootNode)
......
......@@ -24,8 +24,10 @@
****************************************************************************/
#include "qttestconfiguration.h"
#include "qttestconstants.h"
#include "qttestoutputreader.h"
#include "../testsettings.h"
#include "qttestsettings.h"
#include "../testframeworkmanager.h"
namespace Autotest {
namespace Internal {
......@@ -36,19 +38,26 @@ TestOutputReader *QtTestConfiguration::outputReader(const QFutureInterface<TestR
return new QtTestOutputReader(fi, app, buildDirectory());
}
QStringList QtTestConfiguration::argumentsForTestRunner(const TestSettings &settings) const
QStringList QtTestConfiguration::argumentsForTestRunner() const
{
static const Core::Id id
= Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QtTest::Constants::FRAMEWORK_NAME);
QStringList arguments("-xml");
if (testCases().count())
arguments << testCases();
const QString &metricsOption
= QtTestSettings::metricsTypeToOption(settings.qtTestSettings.metrics);
TestFrameworkManager *manager = TestFrameworkManager::instance();
auto qtSettings = qSharedPointerCast<QtTestSettings>(manager->settingsForTestFramework(id));
if (qtSettings.isNull())
return arguments;
const QString &metricsOption = QtTestSettings::metricsTypeToOption(qtSettings->metrics);
if (!metricsOption.isEmpty())
arguments << metricsOption;
if (testCases().count())
arguments << testCases();
if (runMode() == DebuggableTestConfiguration::Debug) {
if (settings.qtTestSettings.noCrashHandler)
if (qtSettings->noCrashHandler)
arguments << "-nocrashhandler";
}
......
......@@ -36,7 +36,7 @@ public:
explicit QtTestConfiguration() {}
TestOutputReader *outputReader(const QFutureInterface<TestResultPtr> &fi,
QProcess *app) const override;
QStringList argumentsForTestRunner(const TestSettings &settings) const override;
QStringList argumentsForTestRunner() const override;
};
} // namespace Internal
......
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QtGlobal>
namespace Autotest {
namespace QtTest {
namespace Constants {
const char FRAMEWORK_NAME[] = "QtTest";
const char FRAMEWORK_SETTINGS_CATEGORY[] = QT_TRANSLATE_NOOP("QtTestFramework", "Qt Test");
const unsigned FRAMEWORK_PRIORITY = 1;
} // namespace Constants
} // namespace QtTest
} // namespace Autotest
......@@ -24,7 +24,9 @@
****************************************************************************/
#include "qttestframework.h"
#include "qttestconstants.h"
#include "qttestparser.h"
#include "qttestsettings.h"
#include "qttesttreeitem.h"
namespace Autotest {
......@@ -37,18 +39,30 @@ ITestParser *QtTestFramework::createTestParser() const
TestTreeItem *QtTestFramework::createRootNode() const
{
return new QtTestTreeItem(QCoreApplication::translate("QtTestFramework", "Qt Tests"),
return new QtTestTreeItem(
QCoreApplication::translate("QtTestFramework",
QtTest::Constants::FRAMEWORK_SETTINGS_CATEGORY),
QString(), TestTreeItem::Root);
}
IFrameworkSettings *QtTestFramework::createFrameworkSettings() const
{
return new QtTestSettings;
}
bool QtTestFramework::hasFrameworkSettings() const
{
return true;
}
const char *QtTestFramework::name() const
{
return "QtTest";
return QtTest::Constants::FRAMEWORK_NAME;
}
unsigned QtTestFramework::priority() const
{
return 1;
return QtTest::Constants::FRAMEWORK_PRIORITY;
}
} // namespace Internal
......
......@@ -36,6 +36,8 @@ public:
QtTestFramework() : ITestFramework(true) {}
const char *name() const override;
unsigned priority() const override;
IFrameworkSettings *createFrameworkSettings() const override;
bool hasFrameworkSettings() const override;
protected:
ITestParser *createTestParser() const override;
......
......@@ -24,8 +24,10 @@
****************************************************************************/
#include "quicktestconfiguration.h"
#include "../qtest/qttestconstants.h"
#include "../qtest/qttestoutputreader.h"
#include "../testsettings.h"
#include "../qtest/qttestsettings.h"
#include "../testframeworkmanager.h"
namespace Autotest {
namespace Internal {
......@@ -36,16 +38,23 @@ TestOutputReader *QuickTestConfiguration::outputReader(const QFutureInterface<Te
return new QtTestOutputReader(fi, app, buildDirectory());
}
QStringList QuickTestConfiguration::argumentsForTestRunner(const TestSettings &settings) const
QStringList QuickTestConfiguration::argumentsForTestRunner() const
{
QStringList arguments({"-xml"});
static const Core::Id id
= Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QtTest::Constants::FRAMEWORK_NAME);
const QString &metricsOption
= QtTestSettings::metricsTypeToOption(settings.qtTestSettings.metrics);
if (!metricsOption.isEmpty())
arguments << metricsOption;
QStringList arguments("-xml");
if (testCases().count())
arguments << testCases();
TestFrameworkManager *manager = TestFrameworkManager::instance();
auto qtSettings = qSharedPointerCast<QtTestSettings>(manager->settingsForTestFramework(id));
if (qtSettings.isNull())
return arguments;
const QString &metricsOption = QtTestSettings::metricsTypeToOption(qtSettings->metrics);
if (!metricsOption.isEmpty())
arguments << metricsOption;
return arguments;
}
......
......@@ -36,7 +36,7 @@ public:
explicit QuickTestConfiguration() {}
TestOutputReader *outputReader(const QFutureInterface<TestResultPtr> &fi,
QProcess *app) const override;
QStringList argumentsForTestRunner(const TestSettings &settings) const override;
QStringList argumentsForTestRunner() const override;
void setUnnamedOnly(bool unnamedOnly);
bool unnamedOnly() const { return m_unnamedOnly; }
......
......@@ -27,7 +27,6 @@
#include "testoutputreader.h"
#include "testrunconfiguration.h"
#include "testrunner.h"
#include "testsettings.h"
#include <cpptools/cppmodelmanager.h>
#include <cpptools/projectinfo.h>
......
......@@ -45,7 +45,6 @@ namespace Internal {
class TestOutputReader;
class TestResult;
class TestRunConfiguration;
struct TestSettings;
using TestResultPtr = QSharedPointer<TestResult>;
......@@ -86,7 +85,7 @@ public:
virtual TestOutputReader *outputReader(const QFutureInterface<TestResultPtr> &fi,
QProcess *app) const = 0;
virtual QStringList argumentsForTestRunner(const TestSettings &settings) const = 0;
virtual QStringList argumentsForTestRunner() const = 0;
private:
QStringList m_testCases;
......
......@@ -25,6 +25,8 @@
#include "testframeworkmanager.h"
#include "autotestconstants.h"
#include "autotestplugin.h"
#include "iframeworksettings.h"
#include "itestframework.h"
#include "itestparser.h"
#include "testrunner.h"
......@@ -74,6 +76,11 @@ bool TestFrameworkManager::registerTestFramework(ITestFramework *framework)
// TODO check for unique priority before registering
qCDebug(LOG) << "Registering" << id;
m_registeredFrameworks.insert(id, framework);
if (framework->hasFrameworkSettings()) {
QSharedPointer<IFrameworkSettings> frameworkSettings(framework->createFrameworkSettings());
m_frameworkSettings.insert(id, frameworkSettings);
}
return true;
}
......@@ -145,6 +152,23 @@ ITestParser *TestFrameworkManager::testParserForTestFramework(const Core::Id &fr
return testParser;
}
QSharedPointer<IFrameworkSettings> TestFrameworkManager::settingsForTestFramework(
const Core::Id &frameworkId) const
{
return m_frameworkSettings.contains(frameworkId) ? m_frameworkSettings.value(frameworkId)
: QSharedPointer<IFrameworkSettings>();
}
void TestFrameworkManager::synchronizeSettings(QSettings *s)
{
AutotestPlugin::instance()->settings()->fromSettings(s);
for (const Core::Id &id : m_frameworkSettings.keys()) {
QSharedPointer<IFrameworkSettings> fSettings = settingsForTestFramework(id);
if (!fSettings.isNull())
fSettings->fromSettings(s);
}
}
bool TestFrameworkManager::isActive(const Core::Id &frameworkId) const
{
ITestFramework *framework = m_registeredFrameworks.value(frameworkId);
......
......@@ -28,11 +28,16 @@
#include <QHash>
#include <QSharedPointer>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace Core { class Id; }
namespace Autotest {
namespace Internal {
class IFrameworkSettings;
class ITestFramework;
class ITestParser;
class TestRunner;
......@@ -55,6 +60,8 @@ public:
TestTreeItem *rootNodeForTestFramework(const Core::Id &frameworkId) const;
ITestParser *testParserForTestFramework(const Core::Id &frameworkId) const;
QSharedPointer<IFrameworkSettings> settingsForTestFramework(const Core::Id &frameworkId) const;
void synchronizeSettings(QSettings *s);
bool isActive(const Core::Id &frameworkId) const;
bool hasActiveFrameworks() const;
......@@ -62,6 +69,7 @@ private:
QVector<Core::Id> activeFrameworkIds() const;
explicit TestFrameworkManager();
QHash<Core::Id, ITestFramework *> m_registeredFrameworks;
QHash<Core::Id, QSharedPointer<IFrameworkSettings> > m_frameworkSettings;
TestTreeModel *m_testTreeModel;
TestRunner *m_testRunner;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment