diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-05-24 13:26:36 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-06-15 20:23:06 +0200 |
commit | 37bad1f43b33a460f402f16280719d3b49dd7b24 (patch) | |
tree | a2fd8d97d60d2e88fd77b78bcb02895f7e1ca90d /src/testlib/qtestcase.cpp | |
parent | edd983071e0a90ee8665d2f45916fb575fc25857 (diff) |
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>
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); |