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). Change-Id: I14a515fcfacb6ca49e0470b236c05475b25db4f2 Reviewed-by: Dimitrios Apostolou <jimis@qt.io> (cherry picked from commit 37bad1f43b33a460f402f16280719d3b49dd7b24) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b44efd693c
commit
f3e7d0fb30
@ -2265,19 +2265,33 @@ int QTest::qRun()
|
|||||||
if (!noCrashHandler)
|
if (!noCrashHandler)
|
||||||
handler.emplace();
|
handler.emplace();
|
||||||
|
|
||||||
|
bool seenBad = false;
|
||||||
TestMethods::MetaMethods commandLineMethods;
|
TestMethods::MetaMethods commandLineMethods;
|
||||||
commandLineMethods.reserve(static_cast<size_t>(QTest::testFunctions.size()));
|
commandLineMethods.reserve(static_cast<size_t>(QTest::testFunctions.size()));
|
||||||
for (const QString &tf : qAsConst(QTest::testFunctions)) {
|
for (const QString &tf : qAsConst(QTest::testFunctions)) {
|
||||||
const QByteArray tfB = tf.toLatin1();
|
const QByteArray tfB = tf.toLatin1();
|
||||||
const QByteArray signature = tfB + QByteArrayLiteral("()");
|
const QByteArray signature = tfB + QByteArrayLiteral("()");
|
||||||
QMetaMethod m = TestMethods::findMethod(currentTestObject, signature.constData());
|
QMetaMethod m = TestMethods::findMethod(currentTestObject, signature.constData());
|
||||||
if (!m.isValid() || !isValidSlot(m)) {
|
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);
|
|
||||||
}
|
|
||||||
commandLineMethods.push_back(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));
|
TestMethods test(currentTestObject, std::move(commandLineMethods));
|
||||||
test.invokeTests(currentTestObject);
|
test.invokeTests(currentTestObject);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user