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)) {
m_testSetStarted = true;
setCurrentTestCase(match.captured(1));
GTestResult testResult("internal", {}, m_projectFile);
GTestResult testResult({}, {}, m_projectFile);
testResult.setResult(ResultType::MessageCurrentTest);
testResult.setDescription(Tr::tr("Entering test case %1").arg(m_currentTestCase));
reportResult(testResult);

View File

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

View File

@@ -19,7 +19,7 @@ TestResult::TestResult(const QString &id, const QString &name, const ResultHooks
bool TestResult::isValid() const
{
return !m_id.isEmpty();
return m_id.has_value();
}
const QString TestResult::outputString(bool selected) const
@@ -28,7 +28,7 @@ const QString TestResult::outputString(bool selected) const
return m_hooks.outputString(*this, selected);
if (m_result == ResultType::Application)
return m_id;
return id();
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
{
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)
return false;
if (m_hooks.directParent)
@@ -179,14 +179,14 @@ bool TestResult::isIntermediateFor(const TestResult &other) const
QTC_ASSERT(other.isValid(), return false);
if (m_hooks.intermediate)
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
{
if (m_hooks.createResult)
return m_hooks.createResult(*this);
return {m_id, m_name};
return {id(), m_name};
}
} // namespace Autotest

View File

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

View File

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