forked from qt-creator/qt-creator
AutoTest: Limit search for test tree items to respective root
If searching for a test tree item matching a QtTestResult we can safely limit searching to the subtree holding QtTests or QuickTests. Additionally store information whether it is a Quick or pure Qt test into the result to limit it to a single root. Change-Id: I240e778448d99434d188d90a110dfa4f1934c950 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -45,10 +45,13 @@ TestOutputReader *QtTestConfiguration::outputReader(const QFutureInterface<TestR
|
||||
if (qtSettings.isNull())
|
||||
return nullptr;
|
||||
|
||||
if (qtSettings->useXMLOutput)
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::XML);
|
||||
else
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::PlainText);
|
||||
if (qtSettings->useXMLOutput) {
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
|
||||
QtTestOutputReader::XML, TestType::QtTest);
|
||||
} else {
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
|
||||
QtTestOutputReader::PlainText, TestType::QtTest);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList QtTestConfiguration::argumentsForTestRunner(QStringList *omitted) const
|
||||
|
@@ -37,4 +37,13 @@ const unsigned FRAMEWORK_PRIORITY = 1;
|
||||
|
||||
} // namespace Constants
|
||||
} // namespace QtTest
|
||||
|
||||
namespace Internal {
|
||||
enum class TestType
|
||||
{
|
||||
QtTest,
|
||||
QuickTest
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Autotest
|
||||
|
@@ -131,11 +131,12 @@ static QString constructSourceFilePath(const QString &path, const QString &fileP
|
||||
|
||||
QtTestOutputReader::QtTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
||||
QProcess *testApplication, const QString &buildDirectory,
|
||||
const QString &projectFile, OutputMode mode)
|
||||
const QString &projectFile, OutputMode mode, TestType type)
|
||||
: TestOutputReader(futureInterface, testApplication, buildDirectory)
|
||||
, m_executable(testApplication ? testApplication->program() : QString())
|
||||
, m_projectFile(projectFile)
|
||||
, m_mode(mode)
|
||||
, m_testType(type)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -417,7 +418,7 @@ void QtTestOutputReader::processSummaryFinishOutput()
|
||||
|
||||
QtTestResult *QtTestOutputReader::createDefaultResult() const
|
||||
{
|
||||
QtTestResult *result = new QtTestResult(m_executable, m_projectFile, m_className);
|
||||
QtTestResult *result = new QtTestResult(m_executable, m_projectFile, m_testType, m_className);
|
||||
result->setFunctionName(m_testCase);
|
||||
result->setDataTag(m_dataTag);
|
||||
return result;
|
||||
@@ -444,7 +445,7 @@ void QtTestOutputReader::sendCompleteInformation()
|
||||
|
||||
void QtTestOutputReader::sendMessageCurrentTest()
|
||||
{
|
||||
TestResultPtr testResult = TestResultPtr(new QtTestResult(m_projectFile));
|
||||
TestResultPtr testResult = TestResultPtr(new QtTestResult(m_projectFile, m_testType));
|
||||
testResult->setResult(Result::MessageCurrentTest);
|
||||
testResult->setDescription(tr("Entering test function %1::%2").arg(m_className, m_testCase));
|
||||
reportResult(testResult);
|
||||
|
@@ -25,6 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "qttestconstants.h"
|
||||
#include "../testoutputreader.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -48,7 +49,7 @@ public:
|
||||
|
||||
QtTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
||||
QProcess *testApplication, const QString &buildDirectory,
|
||||
const QString &projectFile, OutputMode mode);
|
||||
const QString &projectFile, OutputMode mode, TestType type);
|
||||
|
||||
protected:
|
||||
void processOutput(const QByteArray &outputLine) override;
|
||||
@@ -91,6 +92,7 @@ private:
|
||||
QString m_duration;
|
||||
QXmlStreamReader m_xmlReader;
|
||||
OutputMode m_mode = XML;
|
||||
TestType m_testType = TestType::QtTest;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -24,21 +24,24 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "qttestresult.h"
|
||||
#include "../testtreemodel.h"
|
||||
#include "../testframeworkmanager.h"
|
||||
#include "../testtreeitem.h"
|
||||
#include "../quick/quicktestframework.h" // FIXME BAD! - but avoids declaring QuickTestResult
|
||||
|
||||
#include <coreplugin/id.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
|
||||
QtTestResult::QtTestResult(const QString &projectFile, const QString &className)
|
||||
: TestResult(className), m_projectFile(projectFile)
|
||||
QtTestResult::QtTestResult(const QString &projectFile, TestType type, const QString &className)
|
||||
: TestResult(className), m_projectFile(projectFile), m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
QtTestResult::QtTestResult(const QString &executable, const QString &projectFile,
|
||||
QtTestResult::QtTestResult(const QString &executable, const QString &projectFile, TestType type,
|
||||
const QString &className)
|
||||
: TestResult(executable, className), m_projectFile(projectFile)
|
||||
: TestResult(executable, className), m_projectFile(projectFile), m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -116,7 +119,8 @@ TestResult *QtTestResult::createIntermediateResultFor(const TestResult *other)
|
||||
{
|
||||
QTC_ASSERT(other, return nullptr);
|
||||
const QtTestResult *qtOther = static_cast<const QtTestResult *>(other);
|
||||
QtTestResult *intermediate = new QtTestResult(qtOther->executable(), qtOther->m_projectFile, qtOther->name());
|
||||
QtTestResult *intermediate = new QtTestResult(qtOther->executable(), qtOther->m_projectFile,
|
||||
m_type, qtOther->name());
|
||||
intermediate->m_function = qtOther->m_function;
|
||||
intermediate->m_dataTag = qtOther->m_dataTag;
|
||||
// intermediates will be needed only for data tags
|
||||
@@ -131,9 +135,17 @@ TestResult *QtTestResult::createIntermediateResultFor(const TestResult *other)
|
||||
|
||||
const TestTreeItem *QtTestResult::findTestTreeItem() const
|
||||
{
|
||||
const auto item = TestTreeModel::instance()->findNonRootItem([this](const Utils::TreeItem *item) {
|
||||
Core::Id id;
|
||||
if (m_type == TestType::QtTest)
|
||||
id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QtTest::Constants::FRAMEWORK_NAME);
|
||||
else
|
||||
id = Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix(QuickTest::Constants::FRAMEWORK_NAME);
|
||||
const TestTreeItem *rootNode = TestFrameworkManager::instance()->rootNodeForTestFramework(id);
|
||||
QTC_ASSERT(rootNode, return nullptr);
|
||||
|
||||
const auto item = rootNode->findAnyChild([this](const Utils::TreeItem *item) {
|
||||
const TestTreeItem *treeItem = static_cast<const TestTreeItem *>(item);
|
||||
return matches(treeItem);
|
||||
return treeItem && matches(treeItem);
|
||||
});
|
||||
return static_cast<const TestTreeItem *>(item);
|
||||
}
|
||||
@@ -187,10 +199,9 @@ bool QtTestResult::matchesTestFunction(const TestTreeItem *item) const
|
||||
{
|
||||
TestTreeItem *parentItem = item->parentItem();
|
||||
TestTreeItem::Type type = item->type();
|
||||
if (m_function.contains("::")) { // Quick tests have slightly different layout // BAD/WRONG!
|
||||
if (m_type == TestType::QuickTest) { // Quick tests have slightly different layout // BAD/WRONG!
|
||||
const QStringList tmp = m_function.split("::");
|
||||
QTC_ASSERT(tmp.size() == 2, return false);
|
||||
return item->name() == tmp.last() && parentItem->name() == tmp.first();
|
||||
return tmp.size() == 2 && item->name() == tmp.last() && parentItem->name() == tmp.first();
|
||||
}
|
||||
if (type == TestTreeItem::TestDataTag) {
|
||||
TestTreeItem *grandParentItem = parentItem->parentItem();
|
||||
|
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../testresult.h"
|
||||
#include "qttestconstants.h"
|
||||
|
||||
namespace Autotest {
|
||||
namespace Internal {
|
||||
@@ -33,8 +34,9 @@ namespace Internal {
|
||||
class QtTestResult : public TestResult
|
||||
{
|
||||
public:
|
||||
explicit QtTestResult(const QString &projectFile, const QString &className = QString());
|
||||
QtTestResult(const QString &executable, const QString &projectFile, const QString &className);
|
||||
QtTestResult(const QString &projectFile, TestType type, const QString &className = QString());
|
||||
QtTestResult(const QString &executable, const QString &projectFile, TestType type,
|
||||
const QString &className);
|
||||
const QString outputString(bool selected) const override;
|
||||
|
||||
void setFunctionName(const QString &functionName) { m_function = functionName; }
|
||||
@@ -56,6 +58,7 @@ private:
|
||||
QString m_function;
|
||||
QString m_dataTag;
|
||||
QString m_projectFile;
|
||||
TestType m_type;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -49,10 +49,13 @@ TestOutputReader *QuickTestConfiguration::outputReader(const QFutureInterface<Te
|
||||
auto qtSettings = qSharedPointerCast<QtTestSettings>(manager->settingsForTestFramework(id));
|
||||
if (qtSettings.isNull())
|
||||
return nullptr;
|
||||
if (qtSettings->useXMLOutput)
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::XML);
|
||||
else
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::PlainText);
|
||||
if (qtSettings->useXMLOutput) {
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
|
||||
QtTestOutputReader::XML, TestType::QuickTest);
|
||||
} else {
|
||||
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
|
||||
QtTestOutputReader::PlainText, TestType::QuickTest);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList QuickTestConfiguration::argumentsForTestRunner(QStringList *omitted) const
|
||||
|
@@ -43,7 +43,7 @@ TestTreeItem *QuickTestFramework::createRootNode() const
|
||||
|
||||
const char *QuickTestFramework::name() const
|
||||
{
|
||||
return "QtQuickTest";
|
||||
return QuickTest::Constants::FRAMEWORK_NAME;
|
||||
}
|
||||
|
||||
unsigned QuickTestFramework::priority() const
|
||||
|
@@ -28,6 +28,14 @@
|
||||
#include "../itestframework.h"
|
||||
|
||||
namespace Autotest {
|
||||
namespace QuickTest {
|
||||
namespace Constants {
|
||||
|
||||
const char FRAMEWORK_NAME[] = "QtQuickTest";
|
||||
|
||||
} // namespace Constants
|
||||
} // namespace QuickTest
|
||||
|
||||
namespace Internal {
|
||||
|
||||
class QuickTestFramework : public ITestFramework
|
||||
|
Reference in New Issue
Block a user