2016-05-11 13:02:42 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "gtestoutputreader.h"
|
|
|
|
|
#include "gtestresult.h"
|
2017-08-04 18:33:50 +02:00
|
|
|
#include "../testtreemodel.h"
|
|
|
|
|
#include "../testtreeitem.h"
|
2019-01-08 16:05:57 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
2019-05-24 10:12:43 +02:00
|
|
|
#include <QRegularExpression>
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
static QString constructSourceFilePath(const QString &path, const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
return QFileInfo(path, filePath).canonicalFilePath();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GTestOutputReader::GTestOutputReader(const QFutureInterface<TestResultPtr> &futureInterface,
|
2017-08-04 18:33:50 +02:00
|
|
|
QProcess *testApplication, const QString &buildDirectory,
|
|
|
|
|
const QString &projectFile)
|
2016-05-11 13:02:42 +02:00
|
|
|
: TestOutputReader(futureInterface, testApplication, buildDirectory)
|
2017-08-04 18:33:50 +02:00
|
|
|
, m_projectFile(projectFile)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
2018-05-04 14:07:42 +02:00
|
|
|
if (m_testApplication) {
|
2019-02-26 09:40:49 +01:00
|
|
|
connect(m_testApplication, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
2018-01-08 11:21:34 +01:00
|
|
|
this, [this] (int exitCode, QProcess::ExitStatus /*exitStatus*/) {
|
2018-04-16 09:45:01 +02:00
|
|
|
if (exitCode == 1 && !m_description.isEmpty()) {
|
2018-04-18 08:13:35 +02:00
|
|
|
createAndReportResult(tr("Running tests failed.\n %1\nExecutable: %2")
|
2019-02-06 14:11:19 +01:00
|
|
|
.arg(m_description).arg(id()), ResultType::MessageFatal);
|
2018-04-16 09:45:01 +02:00
|
|
|
}
|
|
|
|
|
// on Windows abort() will result in normal termination, but exit code will be set to 3
|
|
|
|
|
if (Utils::HostOsInfo::isWindowsHost() && exitCode == 3)
|
2018-01-08 11:21:34 +01:00
|
|
|
reportCrash();
|
|
|
|
|
});
|
2018-05-04 14:07:42 +02:00
|
|
|
}
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
|
2019-11-11 08:03:16 +01:00
|
|
|
void GTestOutputReader::processOutputLine(const QByteArray &outputLine)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
2019-05-24 10:12:43 +02:00
|
|
|
static const QRegularExpression newTestStarts("^\\[-{10}\\] \\d+ tests? from (.*)$");
|
|
|
|
|
static const QRegularExpression testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$");
|
|
|
|
|
static const QRegularExpression newTestSetStarts("^\\[ RUN \\] (.*)$");
|
|
|
|
|
static const QRegularExpression testSetSuccess("^\\[ OK \\] (.*) \\((.*)\\)$");
|
|
|
|
|
static const QRegularExpression testSetFail("^\\[ FAILED \\] (.*) \\((\\d+ ms)\\)$");
|
2020-03-20 11:48:37 +01:00
|
|
|
static const QRegularExpression testSetSkipped("^\\[ SKIPPED \\] (.*) \\((\\d+ ms)\\)$");
|
2019-05-24 10:12:43 +02:00
|
|
|
static const QRegularExpression disabledTests("^ YOU HAVE (\\d+) DISABLED TESTS?$");
|
|
|
|
|
static const QRegularExpression iterations("^Repeating all tests "
|
|
|
|
|
"\\(iteration (\\d+)\\) \\. \\. \\.$");
|
2019-12-11 11:29:15 +01:00
|
|
|
static const QRegularExpression logging("^\\[( FATAL | ERROR |WARNING| INFO )\\] "
|
|
|
|
|
"(.*):(\\d+):: (.*)$");
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2019-11-06 14:26:40 +01:00
|
|
|
const QString line = removeCommandlineColors(QString::fromLatin1(outputLine));
|
2016-07-21 10:08:11 +02:00
|
|
|
if (line.trimmed().isEmpty())
|
|
|
|
|
return;
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2019-05-24 10:12:43 +02:00
|
|
|
struct ExactMatch : public QRegularExpressionMatch
|
|
|
|
|
{
|
|
|
|
|
ExactMatch(const QRegularExpressionMatch &other) : QRegularExpressionMatch(other) {}
|
|
|
|
|
operator bool() const { return hasMatch(); }
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-29 12:15:43 +02:00
|
|
|
if (!line.startsWith('[')) {
|
|
|
|
|
m_description.append(line).append('\n');
|
2019-05-24 10:12:43 +02:00
|
|
|
if (ExactMatch match = iterations.match(line)) {
|
|
|
|
|
m_iteration = match.captured(1).toInt();
|
2016-07-21 10:08:11 +02:00
|
|
|
m_description.clear();
|
|
|
|
|
} else if (line.startsWith(QStringLiteral("Note:"))) {
|
2016-12-14 13:30:33 +01:00
|
|
|
m_description = line;
|
|
|
|
|
if (m_iteration > 1)
|
|
|
|
|
m_description.append(' ' + tr("(iteration %1)").arg(m_iteration));
|
2019-04-04 13:31:06 +02:00
|
|
|
TestResultPtr testResult = TestResultPtr(new GTestResult(id(), m_projectFile, QString()));
|
2019-02-06 14:11:19 +01:00
|
|
|
testResult->setResult(ResultType::MessageInternal);
|
2016-12-14 13:30:33 +01:00
|
|
|
testResult->setDescription(m_description);
|
2017-09-20 11:20:25 +02:00
|
|
|
reportResult(testResult);
|
2016-05-11 13:02:42 +02:00
|
|
|
m_description.clear();
|
2019-05-24 10:12:43 +02:00
|
|
|
} else if (ExactMatch match = disabledTests.match(line)) {
|
|
|
|
|
m_disabled = match.captured(1).toInt();
|
2016-05-11 13:02:42 +02:00
|
|
|
m_description.clear();
|
2016-07-21 10:08:11 +02:00
|
|
|
}
|
2016-12-14 13:30:33 +01:00
|
|
|
return;
|
2016-07-21 10:08:11 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-24 10:12:43 +02:00
|
|
|
if (ExactMatch match = testEnds.match(line)) {
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2019-02-06 14:11:19 +01:00
|
|
|
testResult->setResult(ResultType::TestEnd);
|
2019-05-24 10:12:43 +02:00
|
|
|
testResult->setDescription(tr("Test execution took %1").arg(match.captured(2)));
|
2018-01-16 08:41:18 +01:00
|
|
|
reportResult(testResult);
|
2019-05-24 07:17:50 +02:00
|
|
|
m_currentTestSuite.clear();
|
|
|
|
|
m_currentTestCase.clear();
|
2019-05-24 10:12:43 +02:00
|
|
|
} else if (ExactMatch match = newTestStarts.match(line)) {
|
|
|
|
|
setCurrentTestSuite(match.captured(1));
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2019-02-06 14:11:19 +01:00
|
|
|
testResult->setResult(ResultType::TestStart);
|
2016-07-21 10:08:11 +02:00
|
|
|
if (m_iteration > 1) {
|
2019-05-24 07:17:50 +02:00
|
|
|
testResult->setDescription(tr("Repeating test suite %1 (iteration %2)")
|
|
|
|
|
.arg(m_currentTestSuite).arg(m_iteration));
|
2016-07-21 10:08:11 +02:00
|
|
|
} else {
|
2019-05-24 07:17:50 +02:00
|
|
|
testResult->setDescription(tr("Executing test suite %1").arg(m_currentTestSuite));
|
2016-07-21 10:08:11 +02:00
|
|
|
}
|
2017-09-20 11:20:25 +02:00
|
|
|
reportResult(testResult);
|
2019-05-24 10:12:43 +02:00
|
|
|
} else if (ExactMatch match = newTestSetStarts.match(line)) {
|
2020-03-20 11:48:37 +01:00
|
|
|
m_testSetStarted = true;
|
2019-05-24 10:12:43 +02:00
|
|
|
setCurrentTestCase(match.captured(1));
|
2019-02-06 14:11:19 +01:00
|
|
|
TestResultPtr testResult = TestResultPtr(new GTestResult(QString(), m_projectFile,
|
|
|
|
|
QString()));
|
|
|
|
|
testResult->setResult(ResultType::MessageCurrentTest);
|
2019-05-24 07:17:50 +02:00
|
|
|
testResult->setDescription(tr("Entering test case %1").arg(m_currentTestCase));
|
2017-09-20 11:20:25 +02:00
|
|
|
reportResult(testResult);
|
2016-07-21 10:08:11 +02:00
|
|
|
m_description.clear();
|
2019-05-24 10:12:43 +02:00
|
|
|
} else if (ExactMatch match = testSetSuccess.match(line)) {
|
2020-03-20 11:48:37 +01:00
|
|
|
m_testSetStarted = false;
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2019-02-06 14:11:19 +01:00
|
|
|
testResult->setResult(ResultType::Pass);
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setDescription(m_description);
|
2018-01-16 08:41:18 +01:00
|
|
|
reportResult(testResult);
|
2016-07-21 10:08:11 +02:00
|
|
|
m_description.clear();
|
2016-12-14 13:30:33 +01:00
|
|
|
testResult = createDefaultResult();
|
2019-02-06 14:11:19 +01:00
|
|
|
testResult->setResult(ResultType::MessageInternal);
|
2019-05-24 10:12:43 +02:00
|
|
|
testResult->setDescription(tr("Execution took %1.").arg(match.captured(2)));
|
2018-01-16 08:41:18 +01:00
|
|
|
reportResult(testResult);
|
2016-07-21 10:08:11 +02:00
|
|
|
m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1);
|
2019-05-24 10:12:43 +02:00
|
|
|
} else if (ExactMatch match = testSetFail.match(line)) {
|
2020-03-20 11:48:37 +01:00
|
|
|
m_testSetStarted = false;
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2019-02-06 14:11:19 +01:00
|
|
|
testResult->setResult(ResultType::Fail);
|
2016-07-21 10:08:11 +02:00
|
|
|
m_description.chop(1);
|
2020-03-20 11:48:37 +01:00
|
|
|
handleDescriptionAndReportResult(testResult);
|
2016-12-14 13:30:33 +01:00
|
|
|
testResult = createDefaultResult();
|
2019-02-06 14:11:19 +01:00
|
|
|
testResult->setResult(ResultType::MessageInternal);
|
2019-05-24 10:12:43 +02:00
|
|
|
testResult->setDescription(tr("Execution took %1.").arg(match.captured(2)));
|
2018-01-16 08:41:18 +01:00
|
|
|
reportResult(testResult);
|
2016-07-21 10:08:11 +02:00
|
|
|
m_futureInterface.setProgressValue(m_futureInterface.progressValue() + 1);
|
2020-03-20 11:48:37 +01:00
|
|
|
} else if (ExactMatch match = testSetSkipped.match(line)) {
|
|
|
|
|
if (!m_testSetStarted) // ignore SKIPPED at summary
|
|
|
|
|
return;
|
|
|
|
|
m_testSetStarted = false;
|
|
|
|
|
TestResultPtr testResult = createDefaultResult();
|
|
|
|
|
testResult->setResult(ResultType::Skip);
|
|
|
|
|
m_description.chop(1);
|
|
|
|
|
m_description.prepend(match.captured(1) + '\n');
|
|
|
|
|
handleDescriptionAndReportResult(testResult);
|
|
|
|
|
testResult = createDefaultResult();
|
|
|
|
|
testResult->setResult(ResultType::MessageInternal);
|
|
|
|
|
testResult->setDescription(tr("Execution took %1.").arg(match.captured(2)));
|
|
|
|
|
reportResult(testResult);
|
2019-12-11 11:29:15 +01:00
|
|
|
} else if (ExactMatch match = logging.match(line)) {
|
|
|
|
|
const QString severity = match.captured(1).trimmed();
|
|
|
|
|
ResultType type = ResultType::Invalid;
|
|
|
|
|
switch (severity.at(0).toLatin1()) {
|
|
|
|
|
case 'I': type = ResultType::MessageInfo; break; // INFO
|
|
|
|
|
case 'W': type = ResultType::MessageWarn; break; // WARNING
|
|
|
|
|
case 'E': type = ResultType::MessageError; break; // ERROR
|
|
|
|
|
case 'F': type = ResultType::MessageFatal; break; // FATAL
|
|
|
|
|
}
|
|
|
|
|
TestResultPtr testResult = createDefaultResult();
|
|
|
|
|
testResult->setResult(type);
|
|
|
|
|
testResult->setLine(match.captured(3).toInt());
|
|
|
|
|
const QString file = constructSourceFilePath(m_buildDir, match.captured(2));
|
|
|
|
|
if (!file.isEmpty())
|
|
|
|
|
testResult->setFileName(file);
|
|
|
|
|
testResult->setDescription(match.captured(4));
|
|
|
|
|
reportResult(testResult);
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 11:29:15 +01:00
|
|
|
void GTestOutputReader::processStdError(const QByteArray &outputLine)
|
|
|
|
|
{
|
|
|
|
|
// we need to process the output, GTest may uses both out streams
|
|
|
|
|
processOutputLine(outputLine);
|
|
|
|
|
emit newOutputLineAvailable(outputLine, OutputChannel::StdErr);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr GTestOutputReader::createDefaultResult() const
|
2016-12-14 13:30:33 +01:00
|
|
|
{
|
2019-05-24 07:17:50 +02:00
|
|
|
GTestResult *result = new GTestResult(id(), m_projectFile, m_currentTestSuite);
|
|
|
|
|
result->setTestCaseName(m_currentTestCase);
|
2016-12-14 13:30:33 +01:00
|
|
|
result->setIteration(m_iteration);
|
2017-08-04 18:33:50 +02:00
|
|
|
|
2020-10-13 11:37:37 +02:00
|
|
|
const ITestTreeItem *testItem = result->findTestTreeItem();
|
2017-09-09 16:46:43 +02:00
|
|
|
|
2017-08-04 18:33:50 +02:00
|
|
|
if (testItem && testItem->line()) {
|
|
|
|
|
result->setFileName(testItem->filePath());
|
2020-10-13 11:37:37 +02:00
|
|
|
result->setLine(testItem->line());
|
2017-08-04 18:33:50 +02:00
|
|
|
}
|
|
|
|
|
|
2018-01-16 08:41:18 +01:00
|
|
|
return TestResultPtr(result);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 07:17:50 +02:00
|
|
|
void GTestOutputReader::setCurrentTestCase(const QString &testCase)
|
2018-01-16 08:41:18 +01:00
|
|
|
{
|
2019-05-24 07:17:50 +02:00
|
|
|
m_currentTestCase = testCase;
|
2018-01-16 08:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-24 07:17:50 +02:00
|
|
|
void GTestOutputReader::setCurrentTestSuite(const QString &testSuite)
|
2018-01-16 08:41:18 +01:00
|
|
|
{
|
2019-05-24 07:17:50 +02:00
|
|
|
m_currentTestSuite = testSuite;
|
2016-12-14 13:30:33 +01:00
|
|
|
}
|
|
|
|
|
|
2020-03-20 11:48:37 +01:00
|
|
|
void GTestOutputReader::handleDescriptionAndReportResult(TestResultPtr testResult)
|
|
|
|
|
{
|
|
|
|
|
static const QRegularExpression failureLocation("^(.*):(\\d+): Failure$");
|
|
|
|
|
static const QRegularExpression skipOrErrorLocation("^(.*)\\((\\d+)\\): (Skipped|error:.*)$");
|
|
|
|
|
|
|
|
|
|
QStringList resultDescription;
|
|
|
|
|
|
|
|
|
|
for (const QString &output : m_description.split('\n')) {
|
|
|
|
|
QRegularExpressionMatch innerMatch = failureLocation.match(output);
|
|
|
|
|
if (!innerMatch.hasMatch()) {
|
|
|
|
|
innerMatch = skipOrErrorLocation.match(output);
|
|
|
|
|
if (!innerMatch.hasMatch()) {
|
|
|
|
|
resultDescription << output;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
testResult->setDescription(resultDescription.join('\n'));
|
|
|
|
|
reportResult(testResult);
|
|
|
|
|
resultDescription.clear();
|
|
|
|
|
|
|
|
|
|
testResult = createDefaultResult();
|
|
|
|
|
testResult->setResult(ResultType::MessageLocation);
|
|
|
|
|
testResult->setLine(innerMatch.captured(2).toInt());
|
|
|
|
|
QString file = constructSourceFilePath(m_buildDir, innerMatch.captured(1));
|
|
|
|
|
if (!file.isEmpty())
|
|
|
|
|
testResult->setFileName(file);
|
|
|
|
|
resultDescription << output;
|
|
|
|
|
}
|
|
|
|
|
testResult->setDescription(resultDescription.join('\n'));
|
|
|
|
|
reportResult(testResult);
|
|
|
|
|
m_description.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|