summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-05-24 17:09:40 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2022-07-11 14:42:27 +0200
commit4d88c80fbdb58dbce248815644f7cdbc2489092e (patch)
tree0c65f19cd1631c46c27d49c4fe84576108380baa /src/testlib/qtestcase.cpp
parent092ef06e00552f0b9c4eea8ebc84b3c7b1895cba (diff)
Improve formatting of QTest message on missing function
If there were no matches to the name given on the command line, the message reported included a "Possible matches:" preamble for a list of functions containing the requested function name. This looked incongruous when no actual functions matched. Turn that preamble into an optional parameter to qPrintTestSlots(), that it'll output before the first match if it finds one, rework qPrintTestSlots() to package its matching condition in a lambda and return true if it found any matches. Change this caller to output a newline in place of the preamble (which ended in a newline), if no match was found. Change-Id: I9716ffa29c3c46e3c7e7fcf25a676c0356dab91c Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Dimitrios Apostolou <jimis@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 242246d279..32206c0eaf 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -593,16 +593,25 @@ Q_TESTLIB_EXPORT bool printAvailableFunctions = false;
Q_TESTLIB_EXPORT QStringList testFunctions;
Q_TESTLIB_EXPORT QStringList testTags;
-static void qPrintTestSlots(FILE *stream, const char *filter = nullptr)
+static bool qPrintTestSlots(FILE *stream, const char *filter = nullptr, const char *preamble = "")
{
+ const auto matches = [filter](const QByteArray &s) {
+ return !filter || QLatin1StringView(s).contains(QLatin1StringView(filter),
+ Qt::CaseInsensitive);
+ };
+ bool matched = false;
for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i);
if (isValidSlot(sl)) {
const QByteArray signature = sl.methodSignature();
- if (!filter || QLatin1StringView(signature).contains(QLatin1StringView(filter), Qt::CaseInsensitive))
- fprintf(stream, "%s\n", signature.constData());
+ if (matches(signature)) {
+ fprintf(stream, "%s%s\n", preamble, signature.constData());
+ preamble = "";
+ matched = true;
+ }
}
}
+ return matched;
}
static void qPrintDataTags(FILE *stream)
@@ -2307,9 +2316,9 @@ int QTest::qRun()
if (m.isValid() && isValidSlot(m)) {
commandLineMethods.push_back(m);
} else {
- fprintf(stderr, "Unknown test function: '%s'. Possible matches:\n",
- tfB.constData());
- qPrintTestSlots(stderr, tfB.constData());
+ fprintf(stderr, "Unknown test function: '%s'.", tfB.constData());
+ if (!qPrintTestSlots(stderr, tfB.constData(), " Possible matches:\n"))
+ fputc('\n', stderr);
QTestResult::setCurrentTestFunction(tfB.constData());
QTestResult::addFailure(qPrintable("Function not found: %1"_L1.arg(tf)));
QTestResult::finishedCurrentTestFunction();