From 37bad1f43b33a460f402f16280719d3b49dd7b24 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 24 May 2022 13:26:36 +0200 Subject: 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 --- src/testlib/qtestcase.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/testlib/qtestcase.cpp') 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(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); -- cgit v1.2.3