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:
Christian Stenger
2017-10-25 14:31:57 +02:00
parent eaf4b67461
commit e412a800b0
9 changed files with 66 additions and 26 deletions

View File

@@ -45,10 +45,13 @@ TestOutputReader *QtTestConfiguration::outputReader(const QFutureInterface<TestR
if (qtSettings.isNull()) if (qtSettings.isNull())
return nullptr; return nullptr;
if (qtSettings->useXMLOutput) if (qtSettings->useXMLOutput) {
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::XML); return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
else QtTestOutputReader::XML, TestType::QtTest);
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::PlainText); } else {
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
QtTestOutputReader::PlainText, TestType::QtTest);
}
} }
QStringList QtTestConfiguration::argumentsForTestRunner(QStringList *omitted) const QStringList QtTestConfiguration::argumentsForTestRunner(QStringList *omitted) const

View File

@@ -37,4 +37,13 @@ const unsigned FRAMEWORK_PRIORITY = 1;
} // namespace Constants } // namespace Constants
} // namespace QtTest } // namespace QtTest
namespace Internal {
enum class TestType
{
QtTest,
QuickTest
};
} // namespace Internal
} // namespace Autotest } // namespace Autotest

View File

@@ -131,11 +131,12 @@ static QString constructSourceFilePath(const QString &path, const QString &fileP
QtTestOutputReader::QtTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface, QtTestOutputReader::QtTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
QProcess *testApplication, const QString &buildDirectory, QProcess *testApplication, const QString &buildDirectory,
const QString &projectFile, OutputMode mode) const QString &projectFile, OutputMode mode, TestType type)
: TestOutputReader(futureInterface, testApplication, buildDirectory) : TestOutputReader(futureInterface, testApplication, buildDirectory)
, m_executable(testApplication ? testApplication->program() : QString()) , m_executable(testApplication ? testApplication->program() : QString())
, m_projectFile(projectFile) , m_projectFile(projectFile)
, m_mode(mode) , m_mode(mode)
, m_testType(type)
{ {
} }
@@ -417,7 +418,7 @@ void QtTestOutputReader::processSummaryFinishOutput()
QtTestResult *QtTestOutputReader::createDefaultResult() const 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->setFunctionName(m_testCase);
result->setDataTag(m_dataTag); result->setDataTag(m_dataTag);
return result; return result;
@@ -444,7 +445,7 @@ void QtTestOutputReader::sendCompleteInformation()
void QtTestOutputReader::sendMessageCurrentTest() void QtTestOutputReader::sendMessageCurrentTest()
{ {
TestResultPtr testResult = TestResultPtr(new QtTestResult(m_projectFile)); TestResultPtr testResult = TestResultPtr(new QtTestResult(m_projectFile, m_testType));
testResult->setResult(Result::MessageCurrentTest); testResult->setResult(Result::MessageCurrentTest);
testResult->setDescription(tr("Entering test function %1::%2").arg(m_className, m_testCase)); testResult->setDescription(tr("Entering test function %1::%2").arg(m_className, m_testCase));
reportResult(testResult); reportResult(testResult);

View File

@@ -25,6 +25,7 @@
#pragma once #pragma once
#include "qttestconstants.h"
#include "../testoutputreader.h" #include "../testoutputreader.h"
#include <QCoreApplication> #include <QCoreApplication>
@@ -48,7 +49,7 @@ public:
QtTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface, QtTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
QProcess *testApplication, const QString &buildDirectory, QProcess *testApplication, const QString &buildDirectory,
const QString &projectFile, OutputMode mode); const QString &projectFile, OutputMode mode, TestType type);
protected: protected:
void processOutput(const QByteArray &outputLine) override; void processOutput(const QByteArray &outputLine) override;
@@ -91,6 +92,7 @@ private:
QString m_duration; QString m_duration;
QXmlStreamReader m_xmlReader; QXmlStreamReader m_xmlReader;
OutputMode m_mode = XML; OutputMode m_mode = XML;
TestType m_testType = TestType::QtTest;
}; };

View File

@@ -24,21 +24,24 @@
****************************************************************************/ ****************************************************************************/
#include "qttestresult.h" #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> #include <utils/qtcassert.h>
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
QtTestResult::QtTestResult(const QString &projectFile, const QString &className) QtTestResult::QtTestResult(const QString &projectFile, TestType type, const QString &className)
: TestResult(className), m_projectFile(projectFile) : 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) 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); QTC_ASSERT(other, return nullptr);
const QtTestResult *qtOther = static_cast<const QtTestResult *>(other); 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_function = qtOther->m_function;
intermediate->m_dataTag = qtOther->m_dataTag; intermediate->m_dataTag = qtOther->m_dataTag;
// intermediates will be needed only for data tags // intermediates will be needed only for data tags
@@ -131,9 +135,17 @@ TestResult *QtTestResult::createIntermediateResultFor(const TestResult *other)
const TestTreeItem *QtTestResult::findTestTreeItem() const 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); const TestTreeItem *treeItem = static_cast<const TestTreeItem *>(item);
return matches(treeItem); return treeItem && matches(treeItem);
}); });
return static_cast<const TestTreeItem *>(item); return static_cast<const TestTreeItem *>(item);
} }
@@ -187,10 +199,9 @@ bool QtTestResult::matchesTestFunction(const TestTreeItem *item) const
{ {
TestTreeItem *parentItem = item->parentItem(); TestTreeItem *parentItem = item->parentItem();
TestTreeItem::Type type = item->type(); 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("::"); const QStringList tmp = m_function.split("::");
QTC_ASSERT(tmp.size() == 2, return false); return tmp.size() == 2 && item->name() == tmp.last() && parentItem->name() == tmp.first();
return item->name() == tmp.last() && parentItem->name() == tmp.first();
} }
if (type == TestTreeItem::TestDataTag) { if (type == TestTreeItem::TestDataTag) {
TestTreeItem *grandParentItem = parentItem->parentItem(); TestTreeItem *grandParentItem = parentItem->parentItem();

View File

@@ -26,6 +26,7 @@
#pragma once #pragma once
#include "../testresult.h" #include "../testresult.h"
#include "qttestconstants.h"
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
@@ -33,8 +34,9 @@ namespace Internal {
class QtTestResult : public TestResult class QtTestResult : public TestResult
{ {
public: public:
explicit QtTestResult(const QString &projectFile, const QString &className = QString()); QtTestResult(const QString &projectFile, TestType type, const QString &className = QString());
QtTestResult(const QString &executable, const QString &projectFile, const QString &className); QtTestResult(const QString &executable, const QString &projectFile, TestType type,
const QString &className);
const QString outputString(bool selected) const override; const QString outputString(bool selected) const override;
void setFunctionName(const QString &functionName) { m_function = functionName; } void setFunctionName(const QString &functionName) { m_function = functionName; }
@@ -56,6 +58,7 @@ private:
QString m_function; QString m_function;
QString m_dataTag; QString m_dataTag;
QString m_projectFile; QString m_projectFile;
TestType m_type;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -49,10 +49,13 @@ TestOutputReader *QuickTestConfiguration::outputReader(const QFutureInterface<Te
auto qtSettings = qSharedPointerCast<QtTestSettings>(manager->settingsForTestFramework(id)); auto qtSettings = qSharedPointerCast<QtTestSettings>(manager->settingsForTestFramework(id));
if (qtSettings.isNull()) if (qtSettings.isNull())
return nullptr; return nullptr;
if (qtSettings->useXMLOutput) if (qtSettings->useXMLOutput) {
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::XML); return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
else QtTestOutputReader::XML, TestType::QuickTest);
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(), QtTestOutputReader::PlainText); } else {
return new QtTestOutputReader(fi, app, buildDirectory(), projectFile(),
QtTestOutputReader::PlainText, TestType::QuickTest);
}
} }
QStringList QuickTestConfiguration::argumentsForTestRunner(QStringList *omitted) const QStringList QuickTestConfiguration::argumentsForTestRunner(QStringList *omitted) const

View File

@@ -43,7 +43,7 @@ TestTreeItem *QuickTestFramework::createRootNode() const
const char *QuickTestFramework::name() const const char *QuickTestFramework::name() const
{ {
return "QtQuickTest"; return QuickTest::Constants::FRAMEWORK_NAME;
} }
unsigned QuickTestFramework::priority() const unsigned QuickTestFramework::priority() const

View File

@@ -28,6 +28,14 @@
#include "../itestframework.h" #include "../itestframework.h"
namespace Autotest { namespace Autotest {
namespace QuickTest {
namespace Constants {
const char FRAMEWORK_NAME[] = "QtQuickTest";
} // namespace Constants
} // namespace QuickTest
namespace Internal { namespace Internal {
class QuickTestFramework : public ITestFramework class QuickTestFramework : public ITestFramework