Don't exit(1) on unrecognised test function name, just report a failure
This way, if you name several test functions on the command-line, you'll at least get the ones that do exist run (and you'll be told all of the ones that don't exist, rather than only the first). Pick-to: 6.4 6.3 6.2 Change-Id: I14a515fcfacb6ca49e0470b236c05475b25db4f2 Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
This commit is contained in:
parent
edd983071e
commit
37bad1f43b
@ -2265,19 +2265,33 @@ int QTest::qRun()
|
||||
if (!noCrashHandler)
|
||||
handler.emplace();
|
||||
|
||||
bool seenBad = false;
|
||||
TestMethods::MetaMethods commandLineMethods;
|
||||
commandLineMethods.reserve(static_cast<size_t>(QTest::testFunctions.size()));
|
||||
for (const QString &tf : qAsConst(QTest::testFunctions)) {
|
||||
const QByteArray tfB = tf.toLatin1();
|
||||
const QByteArray signature = tfB + QByteArrayLiteral("()");
|
||||
QMetaMethod m = TestMethods::findMethod(currentTestObject, signature.constData());
|
||||
if (!m.isValid() || !isValidSlot(m)) {
|
||||
fprintf(stderr, "Unknown test function: '%s'. Possible matches:\n", tfB.constData());
|
||||
qPrintTestSlots(stderr, tfB.constData());
|
||||
fprintf(stderr, "\n%s -functions\nlists all available test functions.\n", QTestResult::currentAppName());
|
||||
exit(1);
|
||||
}
|
||||
const QByteArray tfB = tf.toLatin1();
|
||||
const QByteArray signature = tfB + QByteArrayLiteral("()");
|
||||
QMetaMethod m = TestMethods::findMethod(currentTestObject, signature.constData());
|
||||
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());
|
||||
QTestResult::setCurrentTestFunction(tfB.constData());
|
||||
QTestResult::addFailure(qPrintable("Function not found: %1"_L1.arg(tf)));
|
||||
QTestResult::finishedCurrentTestFunction();
|
||||
// Ditch the tag that came with tf as test function:
|
||||
QTest::testTags.remove(commandLineMethods.size());
|
||||
seenBad = true;
|
||||
}
|
||||
}
|
||||
if (seenBad) {
|
||||
// Provide relevant help to do better next time:
|
||||
fprintf(stderr, "\n%s -functions\nlists all available test functions.\n\n",
|
||||
QTestResult::currentAppName());
|
||||
if (commandLineMethods.empty()) // All requested functions missing.
|
||||
return 1;
|
||||
}
|
||||
TestMethods test(currentTestObject, std::move(commandLineMethods));
|
||||
test.invokeTests(currentTestObject);
|
||||
|
Loading…
Reference in New Issue
Block a user