10#if QT_CONFIG(regularexpression)
11# include <QtCore/qregularexpression.h>
133 m_firstExpectedFail.
clear();
137 m_gatherMessages =
function !=
nullptr;
142 m_firstExpectedFail.
clear();
145 m_gatherMessages =
data !=
nullptr;
150void QTapTestLogger::outputTestLine(
bool ok,
int testNumber,
const QTestCharBuffer &directive)
157 testNumber, testIdentifier.
data(), directive.constData());
164#define YAML_INDENT " "
168 auto isComment = [&
buffer]() {
171 if (!m_gatherMessages)
177void QTapTestLogger::beginYamlish()
182void QTapTestLogger::endYamlish()
194void QTapTestLogger::flushComments()
202void QTapTestLogger::flushMessages()
220 const bool ok = (m_firstExpectedFail.
isEmpty()
224 const char *
const incident = [
type](
const char *priorXFail) {
229 if (priorXFail[0] !=
'\0')
239 if (priorXFail[0] !=
'\0')
245 return static_cast<const char *
>(
nullptr);
251 isExpectedFail ?
"" :
" # ", incident,
252 description && description[0] ?
" " :
"", description);
255 if (!isExpectedFail) {
256 m_gatherMessages =
false;
258 }
else if (m_gatherMessages && m_firstExpectedFail.
isEmpty()) {
266 if (isExpectedFail) {
268 if (m_gatherMessages) {
280 if (!isExpectedFail || m_gatherMessages) {
283#if QT_CONFIG(regularexpression)
284 enum class OperationType {
294 u
"^'(?<actualexpression>.*)' returned "
295 "(?<actual>\\w+)\\. \\((?<message>.*)\\)$"_s);
299 "\\s*Actual\\s+\\((?<actualexpression>.*)\\)\\s*: (?<actual>.*)\n"
300 "\\s*Expected\\s+\\((?<expectedexpresssion>.*)\\)\\s*: "
301 "(?<expected>.*)$"_s);
305 "\\s*Computed\\s+\\((?<actualexpression>.*)\\)\\s*: (?<actual>.*)\n"
306 "\\s*Baseline\\s+\\((?<expectedexpresssion>.*)\\)\\s*: "
307 "(?<expected>.*)$"_s);
312 OperationType opType = OperationType::Unknown;
313 if (
match.hasMatch())
314 opType = OperationType::Verify;
316 if (opType == OperationType::Unknown) {
317 match = compareRegex.
match(descriptionString);
318 if (
match.hasMatch())
319 opType = OperationType::Compare;
322 if (opType == OperationType::Unknown) {
323 match = compareOpRegex.
match(descriptionString);
324 if (
match.hasMatch())
325 opType = OperationType::CompareOp;
328 if (opType != OperationType::Unknown) {
334 return " ("_L1 %
match.captured(
key) % u
')';
336 const QString actualExpression = parenthesize(
"actualexpression"_L1);
338 if (opType == OperationType::Verify) {
339 comparisonType =
"QVERIFY"_L1;
340 actual =
match.captured(u
"actual").toLower() % actualExpression;
344 message = u
"Verification failed"_s;
345 }
else if (opType == OperationType::Compare) {
346 comparisonType =
"QCOMPARE"_L1;
348 % parenthesize(
"expectedexpresssion"_L1);
349 actual =
match.captured(u
"actual") % actualExpression;
351 struct ComparisonInfo {
352 const char *comparisonType;
353 const char *comparisonStringOp;
356 const auto info = [](
const QString &err) -> ComparisonInfo {
357 if (err.contains(
"different"_L1))
358 return {
"QCOMPARE_NE",
"!= " };
359 else if (err.contains(
"less than or equal to"_L1))
360 return {
"QCOMPARE_LE",
"<= " };
361 else if (err.contains(
"greater than or equal to"_L1))
362 return {
"QCOMPARE_GE",
">= " };
363 else if (err.contains(
"less than"_L1))
364 return {
"QCOMPARE_LT",
"< " };
365 else if (err.contains(
"greater than"_L1))
366 return {
"QCOMPARE_GT",
"> " };
367 else if (err.contains(
"to be equal to"_L1))
368 return {
"QCOMPARE_EQ",
"== " };
370 return {
"Unknown",
"" };
374 %
match.captured(u
"expected")
375 % parenthesize(
"expectedexpresssion"_L1);
376 actual =
match.captured(u
"actual") % actualExpression;
389 indent, comparisonType.
latin1(),
395 outputBuffer(diagnosticsYamlish);
398 if (description && !incident) {
401 outputBuffer(unparsableDescription);
409 "%sat: %s::%s() (%s:%d)\n"
434 const char *
const flavor = [
type]() {
436 case QDebug:
return "debug";
437 case QInfo:
return "info";
440 case QFatal:
return "fatal";
442 case Info:
return "# inform";
443 case Warn:
return "# warn";
445 return "unrecognised message";
449 if (!m_gatherMessages) {
451 flavor[0] ==
'#' ?
"" :
"# ",
454 }
else if (flavor[0] ==
'#') {
Base class for test loggers.
void outputString(const char *msg)
Convenience method to write msg to the output stream.
IncidentTypes
\value Pass The test ran to completion successfully.
virtual void startLogging()
Called before the start of a test run.
MessageTypes
The members whose names begin with Q describe messages that originate in calls, by the test or code u...
virtual void stopLogging()
Called after the end of a test run.
constexpr const char * latin1() const noexcept
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
QRegularExpressionMatch match(const QString &subject, qsizetype offset=0, MatchType matchType=NormalMatch, MatchOptions matchOptions=NoMatchOption) const
Attempts to match the regular expression against the given subject string, starting at the position o...
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void enterTestFunction(const char *) override
This virtual method is called before each test function is invoked.
void addMessage(MessageTypes type, const QString &message, const char *file=nullptr, int line=0) override
This is an overloaded member function, provided for convenience. It differs from the above function o...
void enterTestData(QTestData *data) override
This virtual method is called before and after each call to a test function.
void stopLogging() override
Called after the end of a test run.
QTapTestLogger(const char *filename)
void addIncident(IncidentTypes type, const char *description, const char *file=nullptr, int line=0) override
This virtual method is called when an event occurs that relates to the resolution of the test.
void startLogging() override
Called before the start of a test run.
static const char * currentTestObjectName()
static const char * currentTestFunction()
Combined button and popup list for selecting options.
void generateTestIdentifier(QTestCharBuffer *identifier, int parts)
bool appendCharBuffer(QTestCharBuffer *accumulator, const QTestCharBuffer &more)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
GLuint GLsizei const GLchar * message
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define qPrintable(string)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
QFileInfo info(fileName)
[8]
const char * constData() const
virtual HRESULT STDMETHODCALLTYPE Compare(__RPC__in_opt ITextRangeProvider *range, __RPC__out BOOL *pRetVal)=0