AutoTest: Fix handling of test results

Broke with d05c5b7d07. The id is
used to identify the application running a test or a global
message like some warnings or the information regarding the
current running test.
Fixes its usage and its display inside the results pane.

In the amended patch the assumption that if the m_id is empty
it corresponds to nullptr TestResultPtr was apparently wrong.
This patch fixes it so that the default c'tor of TestResult
always creates an invalid result, so that it corresponds now
to nullptr TestResultPtr.

Amends d05c5b7d07

Change-Id: I9949aec3fc2b7354de149433b7127933f2d9bf21
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Stenger
2023-02-15 16:25:16 +01:00
committed by Jarek Kobus
parent 31740f562c
commit ac2d5d761d
5 changed files with 16 additions and 14 deletions

View File

@@ -105,7 +105,7 @@ void GTestOutputReader::processOutputLine(const QByteArray &outputLine)
} else if (ExactMatch match = newTestSetStarts.match(line)) { } else if (ExactMatch match = newTestSetStarts.match(line)) {
m_testSetStarted = true; m_testSetStarted = true;
setCurrentTestCase(match.captured(1)); setCurrentTestCase(match.captured(1));
GTestResult testResult("internal", {}, m_projectFile); GTestResult testResult({}, {}, m_projectFile);
testResult.setResult(ResultType::MessageCurrentTest); testResult.setResult(ResultType::MessageCurrentTest);
testResult.setDescription(Tr::tr("Entering test case %1").arg(m_currentTestCase)); testResult.setDescription(Tr::tr("Entering test case %1").arg(m_currentTestCase));
reportResult(testResult); reportResult(testResult);

View File

@@ -474,7 +474,7 @@ void QtTestOutputReader::sendCompleteInformation()
void QtTestOutputReader::sendMessageCurrentTest() void QtTestOutputReader::sendMessageCurrentTest()
{ {
QtTestResult result("internal", {}, m_projectFile, m_testType); QtTestResult result({}, {}, m_projectFile, m_testType);
result.setResult(ResultType::MessageCurrentTest); result.setResult(ResultType::MessageCurrentTest);
result.setDescription(Tr::tr("Entering test function %1::%2").arg(m_className, m_testCase)); result.setDescription(Tr::tr("Entering test function %1::%2").arg(m_className, m_testCase));
reportResult(result); reportResult(result);

View File

@@ -19,7 +19,7 @@ TestResult::TestResult(const QString &id, const QString &name, const ResultHooks
bool TestResult::isValid() const bool TestResult::isValid() const
{ {
return !m_id.isEmpty(); return m_id.has_value();
} }
const QString TestResult::outputString(bool selected) const const QString TestResult::outputString(bool selected) const
@@ -28,7 +28,7 @@ const QString TestResult::outputString(bool selected) const
return m_hooks.outputString(*this, selected); return m_hooks.outputString(*this, selected);
if (m_result == ResultType::Application) if (m_result == ResultType::Application)
return m_id; return id();
return selected ? m_description : m_description.split('\n').first(); return selected ? m_description : m_description.split('\n').first();
} }
@@ -166,7 +166,7 @@ QColor TestResult::colorForType(const ResultType type)
bool TestResult::isDirectParentOf(const TestResult &other, bool *needsIntermediate) const bool TestResult::isDirectParentOf(const TestResult &other, bool *needsIntermediate) const
{ {
QTC_ASSERT(other.isValid(), return false); QTC_ASSERT(other.isValid(), return false);
const bool ret = !m_id.isEmpty() && m_id == other.m_id && m_name == other.m_name; const bool ret = m_id && m_id == other.m_id && m_name == other.m_name;
if (!ret) if (!ret)
return false; return false;
if (m_hooks.directParent) if (m_hooks.directParent)
@@ -179,14 +179,14 @@ bool TestResult::isIntermediateFor(const TestResult &other) const
QTC_ASSERT(other.isValid(), return false); QTC_ASSERT(other.isValid(), return false);
if (m_hooks.intermediate) if (m_hooks.intermediate)
return m_hooks.intermediate(*this, other); return m_hooks.intermediate(*this, other);
return !m_id.isEmpty() && m_id == other.m_id && m_name == other.m_name; return m_id && m_id == other.m_id && m_name == other.m_name;
} }
TestResult TestResult::intermediateResult() const TestResult TestResult::intermediateResult() const
{ {
if (m_hooks.createResult) if (m_hooks.createResult)
return m_hooks.createResult(*this); return m_hooks.createResult(*this);
return {m_id, m_name}; return {id(), m_name};
} }
} // namespace Autotest } // namespace Autotest

View File

@@ -9,6 +9,8 @@
#include <QColor> #include <QColor>
#include <optional>
namespace Autotest { namespace Autotest {
class ITestTreeItem; class ITestTreeItem;
@@ -65,9 +67,9 @@ struct ResultHooks
using IntermediateHook = std::function<bool(const TestResult &, const TestResult &)>; using IntermediateHook = std::function<bool(const TestResult &, const TestResult &)>;
using CreateResultHook = std::function<TestResult(const TestResult &)>; using CreateResultHook = std::function<TestResult(const TestResult &)>;
QVariant extraData; QVariant extraData;
OutputStringHook outputString; OutputStringHook outputString = {};
FindTestItemHook findTestItem; FindTestItemHook findTestItem = {};
DirectParentHook directParent; DirectParentHook directParent = {};
IntermediateHook intermediate = {}; IntermediateHook intermediate = {};
CreateResultHook createResult = {}; CreateResultHook createResult = {};
}; };
@@ -83,7 +85,7 @@ public:
const QString outputString(bool selected) const; const QString outputString(bool selected) const;
const ITestTreeItem *findTestTreeItem() const; const ITestTreeItem *findTestTreeItem() const;
QString id() const { return m_id; } QString id() const { return m_id.value_or(QString()); }
QString name() const { return m_name; } QString name() const { return m_name; }
ResultType result() const { return m_result; } ResultType result() const { return m_result; }
QString description() const { return m_description; } QString description() const { return m_description; }
@@ -106,13 +108,13 @@ public:
TestResult intermediateResult() const; TestResult intermediateResult() const;
private: private:
QString m_id; std::optional<QString> m_id = {};
QString m_name; QString m_name;
ResultType m_result = ResultType::Invalid; // the real result.. ResultType m_result = ResultType::Invalid; // the real result..
QString m_description; QString m_description;
Utils::FilePath m_file; Utils::FilePath m_file;
int m_line = 0; int m_line = 0;
ResultHooks m_hooks; ResultHooks m_hooks = {};
}; };
} // namespace Autotest } // namespace Autotest

View File

@@ -784,7 +784,7 @@ void TestRunner::onFinished()
void TestRunner::reportResult(ResultType type, const QString &description) void TestRunner::reportResult(ResultType type, const QString &description)
{ {
TestResult result("internal", {}); TestResult result({}, {});
result.setResult(type); result.setResult(type);
result.setDescription(description); result.setDescription(description);
emit testResultReady(result); emit testResultReady(result);