AutoTest: Fix adding finish message into results tree

For QTest based tests we added the function finish message wrongly
to the last data tag when using data driven tests.
Not crucial, but it would become so in a follow up.
For finish messages we know that these only apply to test functions
or cases - never data tags.
This patch ensures we only add TestEnd messages to the corresponding
TestStart.

Change-Id: Idceb6e563e6f8c5f426e5604d4c533508583429c
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2024-07-17 10:06:18 +02:00
parent 700d60e9a1
commit 2c413758a6
2 changed files with 11 additions and 3 deletions

View File

@@ -279,7 +279,6 @@ void QtTestOutputReader::processXMLOutput(const QByteArray &outputLine)
if (currentTag == QStringLiteral("TestFunction")) { if (currentTag == QStringLiteral("TestFunction")) {
sendFinishMessage(true); sendFinishMessage(true);
// TODO: bump progress? // TODO: bump progress?
m_dataTag.clear();
m_formerTestCase = m_testCase; m_formerTestCase = m_testCase;
m_testCase.clear(); m_testCase.clear();
} else if (currentTag == QStringLiteral("TestCase")) { } else if (currentTag == QStringLiteral("TestCase")) {
@@ -503,6 +502,9 @@ void QtTestOutputReader::sendStartMessage(bool isFunction)
void QtTestOutputReader::sendFinishMessage(bool isFunction) void QtTestOutputReader::sendFinishMessage(bool isFunction)
{ {
m_dataTag.clear();
if (!isFunction)
m_testCase.clear();
TestResult result = createDefaultResult(); TestResult result = createDefaultResult();
result.setResult(ResultType::TestEnd); result.setResult(ResultType::TestEnd);
if (!m_duration.isEmpty()) { if (!m_duration.isEmpty()) {

View File

@@ -164,11 +164,17 @@ static ResultHooks::DirectParentHook directParentHook(const QString &functionNam
const QtTestData otherData = other.extraData().value<QtTestData>(); const QtTestData otherData = other.extraData().value<QtTestData>();
if (result.result() == ResultType::TestStart) { if (result.result() == ResultType::TestStart) {
if (other.result() == ResultType::TestEnd) {
if (!dataTag.isEmpty())
return false;
return functionName.isEmpty() ? otherData.m_function.isEmpty()
: functionName == otherData.m_function;
}
if (otherData.isDataTag()) { if (otherData.isDataTag()) {
if (otherData.m_function == functionName) { if (otherData.m_function == functionName) {
if (dataTag.isEmpty()) { if (dataTag.isEmpty()) {
// avoid adding function's TestCaseEnd to the data tag *needsIntermediate = true;
*needsIntermediate = other.result() != ResultType::TestEnd;
return true; return true;
} }
return otherData.m_dataTag == dataTag; return otherData.m_dataTag == dataTag;