AutoTest: Provide catch settings

Users can now modify some settings of Catch tests.

Task-number: QTCREATORBUG-19740
Change-Id: I47e64a43f22fbf783cbf7b256e498d9037533e9a
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2020-04-17 13:45:38 +02:00
parent 82a7adf624
commit 3b36dcc4c6
9 changed files with 659 additions and 1 deletions

View File

@@ -26,6 +26,8 @@ add_qtc_plugin(AutoTest
catch/catchframework.h catch/catchframework.cpp catch/catchoutputreader.h
catch/catchoutputreader.cpp catch/catchresult.h catch/catchresult.cpp catch/catchtestparser.h
catch/catchtestparser.cpp catch/catchtreeitem.h catch/catchtreeitem.cpp
catch/catchtestsettings.cpp catch/catchtestsettings.h
catch/catchtestsettingspage.cpp catch/catchtestsettingspage.h catch/catchtestsettingspage.ui
gtest/gtest_utils.cpp gtest/gtest_utils.h
gtest/gtestconfiguration.cpp gtest/gtestconfiguration.h
gtest/gtestconstants.h

View File

@@ -33,6 +33,8 @@ SOURCES += \
catch/catchoutputreader.cpp \
catch/catchresult.cpp \
catch/catchtestparser.cpp \
catch/catchtestsettings.cpp \
catch/catchtestsettingspage.cpp \
catch/catchtreeitem.cpp \
gtest/gtestconfiguration.cpp \
gtest/gtestparser.cpp \
@@ -104,6 +106,8 @@ HEADERS += \
catch/catchoutputreader.h \
catch/catchresult.h \
catch/catchtestparser.h \
catch/catchtestsettings.h \
catch/catchtestsettingspage.h \
catch/catchtreeitem.h \
gtest/gtestconfiguration.h \
gtest/gtestparser.h \
@@ -150,6 +154,7 @@ RESOURCES += \
FORMS += \
testsettingspage.ui \
boost/boosttestsettingspage.ui \
catch/catchtestsettingspage.ui \
qtest/qttestsettingspage.ui \
gtest/gtestsettingspage.ui

View File

@@ -24,8 +24,10 @@
#include "catchconfiguration.h"
#include "catchoutputreader.h"
#include "catchtestsettings.h"
#include "../autotestplugin.h"
#include "../itestframework.h"
#include "../testsettings.h"
namespace Autotest {
@@ -100,6 +102,33 @@ QStringList CatchConfiguration::argumentsForTestRunner(QStringList *omitted) con
' ', QString::SkipEmptyParts), omitted);
}
auto settings = dynamic_cast<CatchTestSettings *>(framework()->frameworkSettings());
if (!settings)
return arguments;
if (settings->abortAfterChecked)
arguments << "-x" << QString::number(settings->abortAfter);
if (settings->samplesChecked)
arguments << "--benchmark-samples" << QString::number(settings->benchmarkSamples);
if (settings->resamplesChecked)
arguments << "--benchmark-resamples" << QString::number(settings->benchmarkResamples);
if (settings->warmupChecked)
arguments << "--benchmark-warmup-time" << QString::number(settings->benchmarkWarmupTime);
if (settings->confidenceIntervalChecked)
arguments << "--benchmark-confidence-interval" << QString::number(settings->confidenceInterval);
if (settings->noAnalysis)
arguments << "--benchmark-no-analysis";
if (settings->showSuccess)
arguments << "-s";
if (settings->noThrow)
arguments << "-e";
if (settings->visibleWhitespace)
arguments << "-i";
if (settings->warnOnEmpty)
arguments << "-w" << "NoAssertions";
if (isDebugRunMode() && settings->breakOnFailure)
arguments << "-b";
return arguments;
}

View File

@@ -26,6 +26,9 @@
#include "../itestframework.h"
#include "catchtestsettings.h"
#include "catchtestsettingspage.h"
namespace Autotest {
namespace Internal {
@@ -40,7 +43,12 @@ public:
protected:
ITestParser *createTestParser() override;
TestTreeItem *createRootNode() override;
private:
IFrameworkSettings * frameworkSettings() override { return &m_settings; }
CatchTestSettings m_settings;
CatchTestSettingsPage m_settingsPage{&m_settings, settingsId()};
};
} // namepsace Internal
} // namespace Internal
} // namespace Autotest

View File

@@ -0,0 +1,94 @@
/****************************************************************************
**
** Copyright (C) 2020 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.
**
****************************************************************************/
#include "catchtestsettings.h"
namespace Autotest {
namespace Internal {
static const char abortAfterKey[] = "AbortAfter";
static const char abortAfterCheckedKey[] = "AbortChecked";
static const char benchmarkSamplesKey[] = "BenchSamples";
static const char samplesCheckedKey[] = "SamplesChecked";
static const char benchmarkResamplesKey[] = "BenchResamples";
static const char resamplesCheckedKey[] = "ResamplesChecked";
static const char benchmarConfidenceIntervalKey[] = "BenchConfInt";
static const char confIntCheckedKey[] = "ConfIntChecked";
static const char benchmarWarmupTimeKey[] = "BenchWarmup";
static const char warmupCheckedKey[] = "WarmupChecked";
static const char noAnalysisKey[] = "NoAnalysis";
static const char showSuccessKey[] = "ShowSuccess";
static const char breakOnFailureKey[] = "BreakOnFailure";
static const char noThrowKey[] = "NoThrow";
static const char visibleWhitespaceKey[] = "VisibleWS";
static const char warnOnEmptyKey[] = "WarnEmpty";
QString CatchTestSettings::name() const
{
return QString("Catch2");
}
void CatchTestSettings::toFrameworkSettings(QSettings *s) const
{
s->setValue(abortAfterCheckedKey, abortAfterChecked);
s->setValue(abortAfterKey, abortAfter);
s->setValue(samplesCheckedKey, samplesChecked);
s->setValue(benchmarkSamplesKey, benchmarkSamples);
s->setValue(resamplesCheckedKey, resamplesChecked);
s->setValue(benchmarkResamplesKey, benchmarkResamples);
s->setValue(confIntCheckedKey, confidenceIntervalChecked);
s->setValue(benchmarConfidenceIntervalKey, confidenceInterval);
s->setValue(warmupCheckedKey, warmupChecked);
s->setValue(benchmarWarmupTimeKey, benchmarkWarmupTime);
s->setValue(noAnalysisKey, noAnalysis);
s->setValue(showSuccessKey, showSuccess);
s->setValue(breakOnFailureKey, breakOnFailure);
s->setValue(noThrowKey, noThrow);
s->setValue(visibleWhitespaceKey, visibleWhitespace);
s->setValue(warnOnEmptyKey, warnOnEmpty);
}
void CatchTestSettings::fromFrameworkSettings(const QSettings *s)
{
abortAfterChecked = s->value(abortAfterCheckedKey, false).toBool();
abortAfter = s->value(abortAfterKey, 0).toInt();
samplesChecked = s->value(samplesCheckedKey, false).toBool();
benchmarkSamples = s->value(benchmarkSamplesKey, 100).toInt();
resamplesChecked = s->value(resamplesCheckedKey, false).toBool();
benchmarkResamples = s->value(benchmarkResamplesKey, 100000).toInt();
confidenceIntervalChecked = s->value(confIntCheckedKey, false).toBool();
confidenceInterval = s->value(benchmarConfidenceIntervalKey, 0.95).toDouble();
warmupChecked = s->value(warmupCheckedKey, false).toBool();
benchmarkWarmupTime = s->value(benchmarWarmupTimeKey, 0).toInt();
noAnalysis = s->value(noAnalysisKey, false).toBool();
showSuccess = s->value(showSuccessKey, false).toBool();
breakOnFailure = s->value(breakOnFailureKey, true).toBool();
noThrow = s->value(noThrowKey, false).toBool();
visibleWhitespace = s->value(visibleWhitespaceKey, false).toBool();
warnOnEmpty = s->value(warnOnEmptyKey, false).toBool();
}
} // namespace Internal
} // namespace Autotest

View File

@@ -0,0 +1,62 @@
/****************************************************************************
**
** Copyright (C) 2020 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 "../iframeworksettings.h"
namespace Autotest {
namespace Internal {
class CatchTestSettings : public IFrameworkSettings
{
public:
CatchTestSettings() = default;
QString name() const override;
int abortAfter = 0;
int benchmarkSamples = 0;
int benchmarkResamples = 0;
double confidenceInterval = 0;
int benchmarkWarmupTime = 0;
bool abortAfterChecked = false;
bool samplesChecked = false;
bool resamplesChecked = false;
bool confidenceIntervalChecked = false;
bool warmupChecked = false;
bool noAnalysis = false;
bool showSuccess = false;
bool breakOnFailure = true;
bool noThrow = false;
bool visibleWhitespace = false;
bool warnOnEmpty = false;
protected:
void toFrameworkSettings(QSettings *s) const override;
void fromFrameworkSettings(const QSettings *s) override;
};
} // namespace Internal
} // namespace Autotest

View File

@@ -0,0 +1,113 @@
/****************************************************************************
**
** Copyright (C) 2020 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.
**
****************************************************************************/
#include "catchtestsettingspage.h"
#include "catchtestsettings.h"
#include "ui_catchtestsettingspage.h"
#include "../autotestconstants.h"
#include <coreplugin/icore.h>
namespace Autotest {
namespace Internal {
class CatchTestSettingsWidget final : public Core::IOptionsPageWidget
{
Q_DECLARE_TR_FUNCTIONS(Autotest::Internal::CatchTestSettingsWidget)
public:
explicit CatchTestSettingsWidget(CatchTestSettings *settings);
void apply() override;
private:
Ui::CatchTestSettingsPage m_ui;
CatchTestSettings *m_settings;
};
CatchTestSettingsWidget::CatchTestSettingsWidget(CatchTestSettings *settings)
: m_settings(settings)
{
m_ui.setupUi(this);
m_ui.abortSB->setEnabled(m_settings->abortAfterChecked);
m_ui.samplesSB->setEnabled(m_settings->samplesChecked),
m_ui.resamplesSB->setEnabled(m_settings->resamplesChecked);
m_ui.confIntSB->setEnabled(m_settings->confidenceIntervalChecked);
m_ui.warmupSB->setEnabled(m_settings->warmupChecked);
connect(m_ui.abortCB, &QCheckBox::toggled, m_ui.abortSB, &QSpinBox::setEnabled);
connect(m_ui.samplesCB, &QCheckBox::toggled, m_ui.samplesSB, &QSpinBox::setEnabled);
connect(m_ui.resamplesCB, &QCheckBox::toggled, m_ui.resamplesSB, &QSpinBox::setEnabled);
connect(m_ui.confIntCB, &QCheckBox::toggled, m_ui.confIntSB, &QDoubleSpinBox::setEnabled);
connect(m_ui.warmupCB, &QCheckBox::toggled, m_ui.warmupSB, &QSpinBox::setEnabled);
m_ui.showSuccessCB->setChecked(m_settings->showSuccess);
m_ui.breakOnFailCB->setChecked(m_settings->breakOnFailure);
m_ui.noThrowCB->setChecked(m_settings->noThrow);
m_ui.visibleWhiteCB->setChecked(m_settings->visibleWhitespace);
m_ui.warnOnEmpty->setChecked(m_settings->warnOnEmpty);
m_ui.noAnalysisCB->setChecked(m_settings->noAnalysis);
m_ui.abortCB->setChecked(m_settings->abortAfterChecked);
m_ui.abortSB->setValue(m_settings->abortAfter);
m_ui.samplesCB->setChecked(m_settings->samplesChecked);
m_ui.samplesSB->setValue(m_settings->benchmarkSamples);
m_ui.resamplesCB->setChecked(m_settings->resamplesChecked);
m_ui.resamplesSB->setValue(m_settings->benchmarkResamples);
m_ui.confIntCB->setChecked(m_settings->confidenceIntervalChecked);
m_ui.confIntSB->setValue(m_settings->confidenceInterval);
m_ui.warmupCB->setChecked(m_settings->warmupChecked);
m_ui.warmupSB->setValue(m_settings->benchmarkWarmupTime);
}
void CatchTestSettingsWidget::apply()
{
m_settings->showSuccess = m_ui.showSuccessCB->isChecked();
m_settings->breakOnFailure = m_ui.breakOnFailCB->isChecked();
m_settings->noThrow = m_ui.noThrowCB->isChecked();
m_settings->visibleWhitespace = m_ui.visibleWhiteCB->isChecked();
m_settings->warnOnEmpty = m_ui.warnOnEmpty->isChecked();
m_settings->noAnalysis = m_ui.noAnalysisCB->isChecked();
m_settings->abortAfterChecked = m_ui.abortCB->isChecked();
m_settings->abortAfter = m_ui.abortSB->value();
m_settings->samplesChecked = m_ui.samplesCB->isChecked();
m_settings->benchmarkSamples = m_ui.samplesSB->value();
m_settings->resamplesChecked = m_ui.resamplesCB->isChecked();
m_settings->benchmarkResamples = m_ui.resamplesSB->value();
m_settings->confidenceIntervalChecked = m_ui.confIntCB->isChecked();
m_settings->confidenceInterval = m_ui.confIntSB->value();
m_settings->warmupChecked = m_ui.warmupCB->isChecked();
m_settings->benchmarkWarmupTime = m_ui.warmupSB->value();
m_settings->toSettings(Core::ICore::settings());
}
CatchTestSettingsPage::CatchTestSettingsPage(CatchTestSettings *settings, Core::Id settingsId)
{
setId(settingsId);
setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
setDisplayName(QCoreApplication::translate("CatchTestFramework", "Catch Test"));
setWidgetCreator([settings] { return new CatchTestSettingsWidget(settings); });
}
} // namespace Internal
} // namespace Autotest

View File

@@ -0,0 +1,42 @@
/****************************************************************************
**
** Copyright (C) 2020 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 <coreplugin/dialogs/ioptionspage.h>
namespace Autotest {
namespace Internal {
class CatchTestSettings;
class CatchTestSettingsPage : public Core::IOptionsPage
{
public:
CatchTestSettingsPage(CatchTestSettings *settings, Core::Id settingsId);
};
} // namespace Internal
} // namespace Autotest

View File

@@ -0,0 +1,303 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CatchTestSettingsPage</class>
<widget class="QWidget" name="CatchTestSettingsPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>314</width>
<height>323</height>
</rect>
</property>
<property name="toolTip">
<string>Confidence interval used for bootstrapping.</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="showSuccessCB">
<property name="toolTip">
<string>Show success for tests.</string>
</property>
<property name="text">
<string>Show success</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="breakOnFailCB">
<property name="toolTip">
<string>Turns failures into debugger breakpoints.</string>
</property>
<property name="text">
<string>Break on failure while debugging</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="noThrowCB">
<property name="toolTip">
<string>Skips all assertions that test for thrown exceptions.</string>
</property>
<property name="text">
<string>Skip throwing assertions</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="visibleWhiteCB">
<property name="toolTip">
<string>Makes whitespace visible.</string>
</property>
<property name="text">
<string>Visualize whitespace</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="warnOnEmpty">
<property name="toolTip">
<string>Warns if a test section does not check any assertion.</string>
</property>
<property name="text">
<string>Warn on empty tests</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="abortHL">
<item>
<widget class="QCheckBox" name="abortCB">
<property name="toolTip">
<string>Aborts after the specified number of failures.</string>
</property>
<property name="text">
<string>Abort after</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="abortSB">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="samplesHL">
<item>
<widget class="QCheckBox" name="samplesCB">
<property name="toolTip">
<string>Number of samples to collect while running benchmarks.</string>
</property>
<property name="text">
<string>Benchmark samples</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="samplesSB">
<property name="maximum">
<number>999999</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="resamplesHL">
<item>
<widget class="QCheckBox" name="resamplesCB">
<property name="text">
<string>Benchmark resamples</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="resamplesSB">
<property name="toolTip">
<string>Number of resamples for bootstrapping.</string>
</property>
<property name="maximum">
<number>9999999</number>
</property>
<property name="value">
<number>100000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="confIntHL">
<item>
<widget class="QCheckBox" name="confIntCB">
<property name="text">
<string>Benchmark confidence interval</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDoubleSpinBox" name="confIntSB">
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.050000000000000</double>
</property>
<property name="value">
<double>0.950000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="warmupHL">
<item>
<widget class="QCheckBox" name="warmupCB">
<property name="toolTip">
<string>Warmup time for each test.</string>
</property>
<property name="text">
<string>Benchmark warmup time</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QSpinBox" name="warmupSB">
<property name="suffix">
<string> ms</string>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="noAnalysisCB">
<property name="toolTip">
<string>Disables statistical analysis and bootstrapping.</string>
</property>
<property name="text">
<string>Disable analysis</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>