From 0604e0f87e32314add37b657c54592be9290fac5 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 12 Jun 2025 15:56:12 +0200 Subject: Add assertions to qtestlog.cpp where it branches on variant type For ignored messages, only string and regex are possible. For messages to warn about, a null variant is also possible. Pick-to: 6.10 6.9 Change-Id: I3a1b0ebaf541fb8e26794409feb4c5ef9b61d3c3 Reviewed-by: Thiago Macieira --- src/testlib/qtestlog.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/testlib/qtestlog.cpp') diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 8a94aa0e19f..f41242f357d 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -193,6 +193,7 @@ namespace QTest { if (const auto *regex = get_if(&pattern)) return regex->match(message).hasMatch(); #endif + Q_ASSERT(pattern.metaType() == QMetaType::fromType()); return stringsMatch(pattern.toString(), message); } @@ -265,6 +266,9 @@ namespace QTest { if (!message.contains(*regex)) continue; #endif + } else { + // The no-arg clearFailOnWarnings()'s null pattern matches all messages. + Q_ASSERT(pattern.isNull()); } const size_t maxMsgLen = 1024; @@ -402,6 +406,10 @@ void QTestLog::printUnhandledIgnoreMessages() } else if (const auto *regex = get_if(&list->pattern)) { message = "Did not receive any message matching: \"%1\""_L1.arg(regex->pattern()); #endif + } else { + Q_UNREACHABLE(); + message = "Missing message of unrecognized pattern type: \"%1\""_L1.arg( + list->pattern.metaType().name()); } for (auto &logger : QTest::loggers->allLoggers()) logger->addMessage(QAbstractTestLogger::Info, message); -- cgit v1.2.3