1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qttestparser.h"
#include "qtoutputformatter.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/hostosinfo.h>
#include <utils/qtcassert.h>
#include <QDir>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#ifdef WITH_TESTS
#include "qtsupportplugin.h"
#include <projectexplorer/outputparser_test.h>
#include <QTest>
#endif // WITH_TESTS
using namespace ProjectExplorer;
using namespace Utils;
namespace QtSupport {
namespace Internal {
OutputLineParser::Result QtTestParser::handleLine(const QString &line, OutputFormat type)
{
if (type != StdOutFormat && type != DebugFormat)
return Status::NotHandled;
const QString theLine = rightTrimmed(line);
static const QRegularExpression triggerPattern("^(?:XPASS|FAIL!) : .+$");
QTC_CHECK(triggerPattern.isValid());
if (triggerPattern.match(theLine).hasMatch()) {
emitCurrentTask();
m_currentTask = Task(Task::Error, theLine, FilePath(), -1,
Constants::TASK_CATEGORY_AUTOTEST);
return {Status::InProgress, {}, {}, StdErrFormat};
}
if (m_currentTask.isNull())
return Status::NotHandled;
static const QRegularExpression locationPattern(HostOsInfo::isWindowsHost()
? QString(QT_TEST_FAIL_WIN_REGEXP)
: QString(QT_TEST_FAIL_UNIX_REGEXP));
QTC_CHECK(locationPattern.isValid());
const QRegularExpressionMatch match = locationPattern.match(theLine);
if (match.hasMatch()) {
LinkSpecs linkSpecs;
m_currentTask.file = absoluteFilePath(FilePath::fromString(
QDir::fromNativeSeparators(match.captured("file"))));
m_currentTask.line = match.captured("line").toInt();
addLinkSpecForAbsoluteFilePath(linkSpecs, m_currentTask.file, m_currentTask.line, match,
"file");
emitCurrentTask();
return {Status::Done, linkSpecs};
}
if (line.startsWith(" Actual") || line.startsWith(" Expected")) {
m_currentTask.details.append(theLine);
return Status::InProgress;
}
return Status::NotHandled;
}
void QtTestParser::emitCurrentTask()
{
if (!m_currentTask.isNull()) {
scheduleTask(m_currentTask, 1);
m_currentTask.clear();
}
}
#ifdef WITH_TESTS
void QtSupportPlugin::testQtTestOutputParser()
{
OutputParserTester testbench;
testbench.addLineParser(new QtTestParser);
const QString input = "random output\n"
"PASS : MyTest::someTest()\n"
"XPASS : MyTest::someTest()\n"
#ifdef Q_OS_WIN
"C:\\dev\\tests\\tst_mytest.cpp(154) : failure location\n"
#else
" Loc: [/home/me/tests/tst_mytest.cpp(154)]\n"
#endif
"FAIL! : MyTest::someOtherTest(init) Compared values are not the same\n"
" Actual (exceptionCaught): 0\n"
" Expected (true) : 1\n"
#ifdef Q_OS_WIN
"C:\\dev\\tests\\tst_mytest.cpp(220) : failure location\n"
#else
" Loc: [/home/me/tests/tst_mytest.cpp(220)]\n"
#endif
"XPASS: irrelevant\n"
"PASS : MyTest::anotherTest()";
const QString expectedChildOutput =
"random output\n"
"PASS : MyTest::someTest()\n"
"XPASS: irrelevant\n"
"PASS : MyTest::anotherTest()\n";
const FilePath theFile = FilePath::fromString(HostOsInfo::isWindowsHost()
? QString("C:/dev/tests/tst_mytest.cpp") : QString("/home/me/tests/tst_mytest.cpp"));
const Tasks expectedTasks{
Task(Task::Error, "XPASS : MyTest::someTest()", theFile, 154,
Constants::TASK_CATEGORY_AUTOTEST),
Task(Task::Error, "FAIL! : MyTest::someOtherTest(init) "
"Compared values are not the same\n"
" Actual (exceptionCaught): 0\n"
" Expected (true) : 1",
theFile, 220, Constants::TASK_CATEGORY_AUTOTEST)};
testbench.testParsing(input, OutputParserTester::STDOUT, expectedTasks, expectedChildOutput,
QString(), QString());
}
#endif // WITH_TESTS
} // namespace Internal
} // namespace QtSupport
|