diff options
Diffstat (limited to 'src/testlib/qappletestlogger.cpp')
-rw-r--r-- | src/testlib/qappletestlogger.cpp | 74 |
1 files changed, 22 insertions, 52 deletions
diff --git a/src/testlib/qappletestlogger.cpp b/src/testlib/qappletestlogger.cpp index 95798c5361..7517a95344 100644 --- a/src/testlib/qappletestlogger.cpp +++ b/src/testlib/qappletestlogger.cpp @@ -1,52 +1,22 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qappletestlogger_p.h" -#include <QPair> - QT_BEGIN_NAMESPACE #if defined(QT_USE_APPLE_UNIFIED_LOGGING) using namespace QTestPrivate; +/*! \internal + \class QAppleTestLogger + \inmodule QtTest + + QAppleTestLogger reports test results through Apple's unified system logging. + Results can be viewed in the Console app. +*/ + bool QAppleTestLogger::debugLoggingEnabled() { // Debug-level messages are only captured in memory when debug logging is @@ -103,6 +73,8 @@ void QAppleTestLogger::addIncident(IncidentTypes type, const char *description, { MessageData messageData = [=]() { switch (type) { + case QAbstractTestLogger::Skip: + return MessageData{QtInfoMsg, "skip"}; case QAbstractTestLogger::Pass: return MessageData{QtInfoMsg, "pass"}; case QAbstractTestLogger::XFail: @@ -130,7 +102,15 @@ void QAppleTestLogger::addIncident(IncidentTypes type, const char *description, QString message = testIdentifier(); if (qstrlen(description)) - message += QLatin1Char('\n') % QString::fromLatin1(description); + message += u'\n' % QString::fromLatin1(description); + + // As long as the Apple logger doesn't propagate the context's file and + // line number we need to manually print it. + if (context.line && context.file) { + QTestCharBuffer line; + QTest::qt_asprintf(&line, "\n [Loc: %s:%d]", context.file, context.line); + message += QLatin1String(line.data()); + } AppleUnifiedLogger::messageHandler(messageData.messageType, context, message, subsystem()); } @@ -153,8 +133,6 @@ void QAppleTestLogger::addMessage(MessageTypes type, const QString &message, con return MessageData{QtWarningMsg, "critical"}; case QAbstractTestLogger::QFatal: return MessageData{QtFatalMsg, nullptr}; - case QAbstractTestLogger::Skip: - return MessageData{QtInfoMsg, "skip"}; case QAbstractTestLogger::Info: case QAbstractTestLogger::QInfo: return MessageData{QtInfoMsg, nullptr}; @@ -166,16 +144,8 @@ void QAppleTestLogger::addMessage(MessageTypes type, const QString &message, con messageData.generateCategory(&category); QMessageLogContext context(file, line, /* function = */ nullptr, category.data()); - QString msg = message; - - if (type == Skip) { - if (!message.isNull()) - msg.prepend(testIdentifier() + QLatin1Char('\n')); - else - msg = testIdentifier(); - } - AppleUnifiedLogger::messageHandler(messageData.messageType, context, msg, subsystem()); + AppleUnifiedLogger::messageHandler(messageData.messageType, context, message, subsystem()); } QString QAppleTestLogger::subsystem() const |