AutoTest: Handle durations for CTest

Task-number: QTCREATORBUG-31242
Change-Id: Id3a1cf44de926bb7bf53d30d4c80bb5c35100249
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Stenger
2024-07-24 09:20:14 +02:00
parent 46ab9f6aad
commit 66ec8fec1a
2 changed files with 12 additions and 1 deletions

View File

@@ -65,7 +65,7 @@ void CTestOutputReader::processOutputLine(const QByteArray &outputLine)
static const QRegularExpression testResult("^\\s*(?<first>\\d+/\\d+)? " static const QRegularExpression testResult("^\\s*(?<first>\\d+/\\d+)? "
"Test\\s+#(?<current>\\d+): (.*) (\\.+)\\s*" "Test\\s+#(?<current>\\d+): (.*) (\\.+)\\s*"
"(Passed|\\*\\*\\*Failed|\\*\\*\\*Not Run|" "(Passed|\\*\\*\\*Failed|\\*\\*\\*Not Run|"
".*\\*\\*\\*Exception:.*)\\s+(.*) sec$"); ".*\\*\\*\\*Exception:.*)\\s+(.*)(\\d+\\.\\d+) sec$");
static const QRegularExpression testCrash("^\\s*\\d+/\\d+ Test\\s+#\\d+: (.*) (\\.+)\\s*" static const QRegularExpression testCrash("^\\s*\\d+/\\d+ Test\\s+#\\d+: (.*) (\\.+)\\s*"
"Exit code .*$"); "Exit code .*$");
static const QRegularExpression summary("^\\d+% tests passed, (\\d+) tests failed " static const QRegularExpression summary("^\\d+% tests passed, (\\d+) tests failed "
@@ -119,6 +119,8 @@ void CTestOutputReader::processOutputLine(const QByteArray &outputLine)
m_result = ResultType::Fail; m_result = ResultType::Fail;
else else
m_result = ResultType::MessageFatal; m_result = ResultType::MessageFatal;
if (match.hasCaptured(7))
m_duration = match.captured(7);
} else if (ExactMatch match = summary.match(line)) { } else if (ExactMatch match = summary.match(line)) {
if (!m_testName.isEmpty()) if (!m_testName.isEmpty())
sendCompleteInformation(); sendCompleteInformation();
@@ -136,6 +138,7 @@ void CTestOutputReader::processOutputLine(const QByteArray &outputLine)
TestResult testResult = createDefaultResult(); TestResult testResult = createDefaultResult();
testResult.setResult(ResultType::TestEnd); testResult.setResult(ResultType::TestEnd);
testResult.setDescription(match.captured()); testResult.setDescription(match.captured());
m_executionDuration = qRound(match.captured(1).toDouble() * 1000.);
reportResult(testResult); reportResult(testResult);
} else if (ExactMatch match = testCrash.match(line)) { } else if (ExactMatch match = testCrash.match(line)) {
m_description = match.captured(); m_description = match.captured();
@@ -169,8 +172,15 @@ void CTestOutputReader::sendCompleteInformation()
testResult.setResult(m_result); testResult.setResult(m_result);
testResult.setDescription(m_description); testResult.setDescription(m_description);
reportResult(testResult); reportResult(testResult);
if (!m_duration.isEmpty() && testResult.result() != ResultType::TestEnd) {
testResult.setDescription(Tr::tr("Test execution took %1.").arg(m_duration + " sec"));
testResult.setDuration(QString::number(m_duration.toDouble() * 1000., 'f', 3));
testResult.setResult(ResultType::TestEnd);
reportResult(testResult);
}
m_testName.clear(); m_testName.clear();
m_description.clear(); m_description.clear();
m_duration.clear();
m_currentTestNo = -1; m_currentTestNo = -1;
m_result = ResultType::Invalid; m_result = ResultType::Invalid;
} }

View File

@@ -24,6 +24,7 @@ private:
QString m_project; QString m_project;
QString m_testName; QString m_testName;
QString m_description; QString m_description;
QString m_duration; // sec
ResultType m_result = ResultType::Invalid; ResultType m_result = ResultType::Invalid;
bool m_expectExceptionFromCrash = false; bool m_expectExceptionFromCrash = false;
}; };