summaryrefslogtreecommitdiffstats
path: root/src/testlib/qabstracttestlogger.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-03-14 19:16:51 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2022-03-29 00:05:12 +0100
commitae37fa0464694c9770bd35472e2afac83a74564c (patch)
tree28a4b3ff158b4829d8dcddae850eacf74976c321 /src/testlib/qabstracttestlogger.cpp
parentd329a98fa9fade95537a6ff35b5898611cfadd0b (diff)
TAP test logger: move messages into the diagnostics block
Our TAP output was delivering messages as comments before the test line, where TAP clearly expects the details of a test to follow its test line. Version 13 provides a YAML block to deliver diagnostics and encourages use of this, so accumulate our messages in a QTestCharBuffer instead of emitting them one by one. However, messages produced after a test has produced its test line belong to that test, but are too late to be included in its diagnostics block, so should be emitted immediately as before, albeit now with a type prefix. This at least separates such messages, from the end of one test, from messages produced early in the next. In the process, add a type-prefix to each, to make clear what type of message it was. Since the Yamlish supported by TAP consumers doesn't support a way to have many messages, use the extensions: top-level hash tag with a messages: sub-tag to gather our messages as a list. (This expands at least one expected output file significantly and substantially rewrites some others.) Add methods to QTestCharBuffer, and a helper function, to support this. Task-number: QTBUG-96844 Change-Id: If44a33da5879ed1670ef0980042599afd516f9d2 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/testlib/qabstracttestlogger.cpp')
-rw-r--r--src/testlib/qabstracttestlogger.cpp30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp
index cb9a049357..1a0596ec98 100644
--- a/src/testlib/qabstracttestlogger.cpp
+++ b/src/testlib/qabstracttestlogger.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2021 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtTest module of the Qt Toolkit.
@@ -399,6 +399,11 @@ void QAbstractTestLogger::addMessage(QtMsgType type, const QMessageLogContext &c
addMessage(messageType, formattedMessage);
}
+namespace
+{
+ constexpr int MAXSIZE = 1024 * 1024 * 2;
+}
+
namespace QTest
{
@@ -408,7 +413,6 @@ namespace QTest
*/
int qt_asprintf(QTestCharBuffer *str, const char *format, ...)
{
- constexpr int MAXSIZE = 1024 * 1024 * 2;
Q_ASSERT(str);
int size = str->size();
Q_ASSERT(size > 0);
@@ -456,6 +460,28 @@ void generateTestIdentifier(QTestCharBuffer *identifier, int parts)
globalDataTag, tagFiller, dataTag, testFuctionEnd);
}
+// strcat() for QTestCharBuffer objects:
+bool appendCharBuffer(QTestCharBuffer *accumulator, const QTestCharBuffer &more)
+{
+ const auto bufsize = [](const QTestCharBuffer &buf) -> int {
+ const int max = buf.size();
+ return max > 0 ? int(qstrnlen(buf.constData(), max)) : 0;
+ };
+ const int extra = bufsize(more);
+ if (extra <= 0)
+ return true; // Nothing to do, fatuous success
+
+ const int oldsize = bufsize(*accumulator);
+ const int newsize = oldsize + extra + 1; // 1 for final '\0'
+ if (newsize > MAXSIZE || !accumulator->resize(newsize))
+ return false; // too big or unable to grow
+
+ char *tail = accumulator->data() + oldsize;
+ memcpy(tail, more.constData(), extra);
+ tail[extra] = '\0';
+ return true;
+}
+
}
QT_END_NAMESPACE