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>
This commit is contained in:
parent
092ef06e00
commit
4d88c80fbd
@ -593,17 +593,26 @@ 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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user