diff options
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index ed9b52244a..23b1832d68 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -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); |