forked from qt-creator/qt-creator
AutoTest: Test execution from result output pane
Enable test execution via context menu in the result output pane. At the moment only gtest is supported. Task-number: QTCREATORBUG-16695 Change-Id: Ib39164c3cb44d249647b11e25dc51c9ac5db89c5 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -24,17 +24,20 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "gtestresult.h"
|
||||
#include "../testtreemodel.h"
|
||||
#include "../testtreeitem.h"
|
||||
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
|
||||
GTestResult::GTestResult(const QString &name)
|
||||
: TestResult(name)
|
||||
GTestResult::GTestResult(const QString &projectFile, const QString &name)
|
||||
: TestResult(name), m_projectFile(projectFile)
|
||||
{
|
||||
}
|
||||
|
||||
GTestResult::GTestResult(const QString &executable, const QString &name)
|
||||
: TestResult(executable, name)
|
||||
GTestResult::GTestResult(const QString &executable, const QString &projectFile,
|
||||
const QString &name)
|
||||
: TestResult(executable, name), m_projectFile(projectFile)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -68,5 +71,60 @@ bool GTestResult::isDirectParentOf(const TestResult *other, bool *needsIntermedi
|
||||
return isTest() && gtOther->isTestSet();
|
||||
}
|
||||
|
||||
static QString normalizeName(const QString &name)
|
||||
{
|
||||
static QRegExp parameterIndex("/\\d+");
|
||||
|
||||
QString nameWithoutParameterIndices = name;
|
||||
nameWithoutParameterIndices.remove(parameterIndex);
|
||||
|
||||
return nameWithoutParameterIndices.split('/').last();
|
||||
}
|
||||
|
||||
static QString normalizeTestName(const QString &testname)
|
||||
{
|
||||
QString nameWithoutTypeParam = testname.split(',').first();
|
||||
|
||||
return normalizeName(nameWithoutTypeParam);
|
||||
}
|
||||
|
||||
const TestTreeItem *GTestResult::findTestTreeItem() const
|
||||
{
|
||||
const auto item = TestTreeModel::instance()->findNonRootItem([this](const Utils::TreeItem *item) {
|
||||
const TestTreeItem &treeItem = static_cast<const TestTreeItem &>(*item);
|
||||
return matches(treeItem);
|
||||
});
|
||||
|
||||
return static_cast<const TestTreeItem *>(item);
|
||||
}
|
||||
|
||||
bool GTestResult::matches(const TestTreeItem &treeItem) const
|
||||
{
|
||||
if (treeItem.proFile() != m_projectFile)
|
||||
return false;
|
||||
|
||||
if (isTest())
|
||||
return matchesTestCase(treeItem);
|
||||
|
||||
return matchesTestFunctionOrSet(treeItem);
|
||||
}
|
||||
|
||||
bool GTestResult::matchesTestFunctionOrSet(const TestTreeItem &treeItem) const
|
||||
{
|
||||
if (treeItem.type() != TestTreeItem::TestFunctionOrSet)
|
||||
return false;
|
||||
|
||||
const QString testItemTestSet = treeItem.parentItem()->name() + '.' + treeItem.name();
|
||||
return testItemTestSet == normalizeName(m_testSetName);
|
||||
}
|
||||
|
||||
bool GTestResult::matchesTestCase(const TestTreeItem &treeItem) const
|
||||
{
|
||||
if (treeItem.type() != TestTreeItem::TestCase)
|
||||
return false;
|
||||
|
||||
return treeItem.name() == normalizeTestName(name());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Autotest
|
||||
|
||||
Reference in New Issue
Block a user