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"
|
2018-01-08 11:21:34 +01:00
|
|
|
#include "utils/hostosinfo.h"
|
2016-05-11 13:02:42 +02:00
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
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) {
|
2018-01-08 11:21:34 +01:00
|
|
|
connect(m_testApplication,
|
|
|
|
|
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
|
|
|
|
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")
|
2018-05-09 10:48:23 +02:00
|
|
|
.arg(m_description).arg(id()), Result::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
|
|
|
}
|
|
|
|
|
|
2018-11-06 16:00:48 +01:00
|
|
|
void GTestOutputReader::processOutputLine(const QByteArray &outputLineWithNewLine)
|
2016-05-11 13:02:42 +02:00
|
|
|
{
|
2016-12-14 13:30:33 +01:00
|
|
|
static QRegExp newTestStarts("^\\[-{10}\\] \\d+ tests? from (.*)$");
|
|
|
|
|
static QRegExp testEnds("^\\[-{10}\\] \\d+ tests? from (.*) \\((.*)\\)$");
|
|
|
|
|
static QRegExp newTestSetStarts("^\\[ RUN \\] (.*)$");
|
|
|
|
|
static QRegExp testSetSuccess("^\\[ OK \\] (.*) \\((.*)\\)$");
|
2018-02-23 13:34:03 +01:00
|
|
|
static QRegExp testSetFail("^\\[ FAILED \\] (.*) \\((\\d+ ms)\\)$");
|
2016-12-14 13:30:33 +01:00
|
|
|
static QRegExp disabledTests("^ YOU HAVE (\\d+) DISABLED TESTS?$");
|
|
|
|
|
static QRegExp failureLocation("^(.*):(\\d+): Failure$");
|
|
|
|
|
static QRegExp errorLocation("^(.*)\\((\\d+)\\): error:.*$");
|
|
|
|
|
static QRegExp iterations("^Repeating all tests \\(iteration (\\d+)\\) \\. \\. \\.$");
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2018-11-05 15:58:27 +01:00
|
|
|
const QString line = QString::fromLatin1(chopLineBreak(outputLineWithNewLine));
|
2016-07-21 10:08:11 +02:00
|
|
|
if (line.trimmed().isEmpty())
|
|
|
|
|
return;
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2016-09-29 12:15:43 +02:00
|
|
|
if (!line.startsWith('[')) {
|
|
|
|
|
m_description.append(line).append('\n');
|
2016-07-21 10:08:11 +02:00
|
|
|
if (iterations.exactMatch(line)) {
|
|
|
|
|
m_iteration = iterations.cap(1).toInt();
|
|
|
|
|
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));
|
2017-09-09 16:46:43 +02:00
|
|
|
TestResultPtr testResult = TestResultPtr(new GTestResult(m_projectFile));
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::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();
|
2016-07-21 10:08:11 +02:00
|
|
|
} else if (disabledTests.exactMatch(line)) {
|
2017-09-09 16:46:43 +02:00
|
|
|
TestResultPtr testResult = TestResultPtr(new GTestResult(m_projectFile));
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::MessageDisabledTests);
|
|
|
|
|
int disabled = disabledTests.cap(1).toInt();
|
2018-07-11 15:44:51 +02:00
|
|
|
testResult->setDescription(tr("You have %n disabled test(s).", nullptr, disabled));
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setLine(disabled); // misuse line property to hold number of disabled
|
2017-09-20 11:20:25 +02:00
|
|
|
reportResult(testResult);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (testEnds.exactMatch(line)) {
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::MessageTestCaseEnd);
|
|
|
|
|
testResult->setDescription(tr("Test execution took %1").arg(testEnds.cap(2)));
|
2018-01-16 08:41:18 +01:00
|
|
|
reportResult(testResult);
|
2016-07-21 10:08:11 +02:00
|
|
|
m_currentTestName.clear();
|
|
|
|
|
m_currentTestSet.clear();
|
|
|
|
|
} else if (newTestStarts.exactMatch(line)) {
|
2017-08-04 18:33:50 +02:00
|
|
|
setCurrentTestName(newTestStarts.cap(1));
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2016-12-14 13:30:33 +01:00
|
|
|
testResult->setResult(Result::MessageTestCaseStart);
|
2016-07-21 10:08:11 +02:00
|
|
|
if (m_iteration > 1) {
|
|
|
|
|
testResult->setDescription(tr("Repeating test case %1 (iteration %2)")
|
|
|
|
|
.arg(m_currentTestName).arg(m_iteration));
|
|
|
|
|
} else {
|
|
|
|
|
testResult->setDescription(tr("Executing test case %1").arg(m_currentTestName));
|
|
|
|
|
}
|
2017-09-20 11:20:25 +02:00
|
|
|
reportResult(testResult);
|
2016-07-21 10:08:11 +02:00
|
|
|
} else if (newTestSetStarts.exactMatch(line)) {
|
2017-08-04 18:33:50 +02:00
|
|
|
setCurrentTestSet(newTestSetStarts.cap(1));
|
2017-09-09 16:46:43 +02:00
|
|
|
TestResultPtr testResult = TestResultPtr(new GTestResult(m_projectFile));
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::MessageCurrentTest);
|
|
|
|
|
testResult->setDescription(tr("Entering test set %1").arg(m_currentTestSet));
|
2017-09-20 11:20:25 +02:00
|
|
|
reportResult(testResult);
|
2016-07-21 10:08:11 +02:00
|
|
|
m_description.clear();
|
|
|
|
|
} else if (testSetSuccess.exactMatch(line)) {
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::Pass);
|
|
|
|
|
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();
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::MessageInternal);
|
|
|
|
|
testResult->setDescription(tr("Execution took %1.").arg(testSetSuccess.cap(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);
|
|
|
|
|
} else if (testSetFail.exactMatch(line)) {
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr testResult = createDefaultResult();
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::Fail);
|
|
|
|
|
m_description.chop(1);
|
2018-08-18 21:48:34 +03:00
|
|
|
QStringList resultDescription;
|
2016-05-11 13:02:42 +02:00
|
|
|
|
2017-02-13 10:05:06 +01:00
|
|
|
for (const QString &output : m_description.split('\n')) {
|
|
|
|
|
QRegExp *match = nullptr;
|
2016-07-21 10:08:11 +02:00
|
|
|
if (failureLocation.exactMatch(output))
|
|
|
|
|
match = &failureLocation;
|
|
|
|
|
else if (errorLocation.exactMatch(output))
|
|
|
|
|
match = &errorLocation;
|
2018-08-18 21:48:34 +03:00
|
|
|
if (!match) {
|
|
|
|
|
resultDescription << output;
|
|
|
|
|
continue;
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
2018-08-18 21:48:34 +03:00
|
|
|
testResult->setDescription(resultDescription.join('\n'));
|
|
|
|
|
reportResult(testResult);
|
|
|
|
|
resultDescription.clear();
|
|
|
|
|
|
|
|
|
|
testResult = createDefaultResult();
|
|
|
|
|
testResult->setResult(Result::MessageLocation);
|
|
|
|
|
testResult->setLine(match->cap(2).toInt());
|
|
|
|
|
QString file = constructSourceFilePath(m_buildDir, match->cap(1));
|
|
|
|
|
if (!file.isEmpty())
|
|
|
|
|
testResult->setFileName(file);
|
|
|
|
|
resultDescription << output;
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
2018-08-18 21:48:34 +03:00
|
|
|
testResult->setDescription(resultDescription.join('\n'));
|
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();
|
2016-07-21 10:08:11 +02:00
|
|
|
testResult->setResult(Result::MessageInternal);
|
|
|
|
|
testResult->setDescription(tr("Execution took %1.").arg(testSetFail.cap(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);
|
2016-05-11 13:02:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 08:41:18 +01:00
|
|
|
TestResultPtr GTestOutputReader::createDefaultResult() const
|
2016-12-14 13:30:33 +01:00
|
|
|
{
|
2018-05-09 10:48:23 +02:00
|
|
|
GTestResult *result = new GTestResult(id(), m_projectFile, m_currentTestName);
|
2016-12-14 13:30:33 +01:00
|
|
|
result->setTestSetName(m_currentTestSet);
|
|
|
|
|
result->setIteration(m_iteration);
|
2017-08-04 18:33:50 +02:00
|
|
|
|
2017-09-09 16:46:43 +02:00
|
|
|
const TestTreeItem *testItem = result->findTestTreeItem();
|
|
|
|
|
|
2017-08-04 18:33:50 +02:00
|
|
|
if (testItem && testItem->line()) {
|
|
|
|
|
result->setFileName(testItem->filePath());
|
|
|
|
|
result->setLine(static_cast<int>(testItem->line()));
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-16 08:41:18 +01:00
|
|
|
return TestResultPtr(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GTestOutputReader::setCurrentTestSet(const QString &testSet)
|
|
|
|
|
{
|
|
|
|
|
m_currentTestSet = testSet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GTestOutputReader::setCurrentTestName(const QString &testName)
|
|
|
|
|
{
|
|
|
|
|
m_currentTestName = testName;
|
2016-12-14 13:30:33 +01:00
|
|
|
}
|
|
|
|
|
|
2016-05-11 13:02:42 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|