summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <[email protected]>2024-11-04 08:14:53 -0800
committerThiago Macieira <[email protected]>2024-11-07 21:39:54 -0800
commitad568b859a6f0a16dd243f1ca2cdc19571337da3 (patch)
tree0896a79761008bde74c98cdd05ed2059517c85ee
parent519d3d36c38fb68945c2d42ba3bc5786c27aa693 (diff)
Revert "QTest: add -[no]throwon{fail,skip} command line arguments"
This reverts commit fde57300ab51c7deda168f6a4515dcf7b1340618 and a portion of commit 627f804d80d76cb729b84dc319382213cd89763c and of commit e769cf026e328ed7fff660c204ce6e55b80114e3. The command-line feature and the environment variables are a design flaw, because there are NO conditions under which a regular user who isn't the designer of the test can make the correct choice. Either the tests are designed to work with throwing or they are not. The test must be run in the mode that the test developer wrote it. [ChangeLog][QtTest] The command-line options and environment variables that changed the defaults for QTest::setThrowOn{Fail,Skip}() have been removed due to a design flaw. To set the default, either place a call to the required function in the test's initTestCase() function or define the C++ macro. Task-number: QTBUG-66320 Change-Id: I0c17899984ebfd70de97fffd51784aa42d41b743 Reviewed-by: Jason McDonald <[email protected]>
-rw-r--r--src/testlib/doc/src/qttestlib-manual.qdoc6
-rw-r--r--src/testlib/qtestcase.cpp23
-rw-r--r--tests/auto/testlib/selftests/tst_selftests.cpp29
3 files changed, 7 insertions, 51 deletions
diff --git a/src/testlib/doc/src/qttestlib-manual.qdoc b/src/testlib/doc/src/qttestlib-manual.qdoc
index fb810c17f39..2e434844560 100644
--- a/src/testlib/doc/src/qttestlib-manual.qdoc
+++ b/src/testlib/doc/src/qttestlib-manual.qdoc
@@ -415,12 +415,6 @@
to e.g. debug an unstable or intermittent failure in a test, by
launching the test in a debugger. Support for this variable was
added in Qt 6.1.
- \li \c QTEST_THROW_ON_FAIL (since 6.8) \br
- Setting this variable to a non-zero value will cause QCOMPARE()/QVERIFY()
- etc to throw on failure (as opposed to just returning from the
- immediately-surrounding function scope).
- \li \c QTEST_THROW_ON_SKIP (since 6.8) \br
- Same as \c QTEST_THROW_ON_FAIL, except affecting QSKIP().
\endlist
\section1 Creating a Benchmark
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 0b6c01e4140..3c6d1adb34e 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -305,9 +305,6 @@ void Internal::maybeThrowOnSkip()
with \c{true}, you need to call it \e{N} times with \c{false} to get back
to where you started.
- The default is \c{false}, unless the \l{Qt Test Environment Variables}
- {QTEST_THROW_ON_FAIL environment variable} is set.
-
This call has no effect when the \l{QTEST_THROW_ON_FAIL} C++ macro is
defined.
@@ -332,9 +329,6 @@ void setThrowOnFail(bool enable) noexcept
with \c{true}, you need to call it \e{N} times with \c{false} to get back
to where you started.
- The default is \c{false}, unless the \l{Qt Test Environment Variables}
- {QTEST_THROW_ON_SKIP environment variable} is set.
-
This call has no effect when the \l{QTEST_THROW_ON_SKIP} C++ macro is
defined.
@@ -616,11 +610,6 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool
QTest::testFunctions.clear();
QTest::testTags.clear();
- if (qEnvironmentVariableIsSet("QTEST_THROW_ON_FAIL"))
- QTest::setThrowOnFail(true);
- if (qEnvironmentVariableIsSet("QTEST_THROW_ON_SKIP"))
- QTest::setThrowOnSkip(true);
-
#if defined(Q_OS_DARWIN) && defined(HAVE_XCTEST)
if (QXcodeTestLogger::canLogTestProgress())
logFormat = QTestLog::XCTest;
@@ -677,10 +666,6 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool
" repeated forever. This is intended as a developer tool, and\n"
" is only supported with the plain text logger.\n"
" -skipblacklisted : Skip blacklisted tests. Useful for measuring test coverage.\n"
- " -[no]throwonfail : Enables/disables throwing on QCOMPARE()/QVERIFY()/etc.\n"
- " Default: off, unless QTEST_THROW_ON_FAIL is set.\n"
- " -[no]throwonskip : Enables/disables throwing on QSKIP().\n"
- " Default: off, unless QTEST_THROW_ON_SKIP is set.\n"
"\n"
" Benchmarking options:\n"
#if QT_CONFIG(valgrind)
@@ -841,14 +826,6 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool
QTest::Internal::noCrashHandler = true;
} else if (strcmp(argv[i], "-skipblacklisted") == 0) {
QTest::skipBlacklisted = true;
- } else if (strcmp(argv[i], "-throwonfail") == 0) {
- QTest::setThrowOnFail(true);
- } else if (strcmp(argv[i], "-nothrowonfail") == 0) {
- QTest::setThrowOnFail(false);
- } else if (strcmp(argv[i], "-throwonskip") == 0) {
- QTest::setThrowOnSkip(true);
- } else if (strcmp(argv[i], "-nothrowonskip") == 0) {
- QTest::setThrowOnSkip(false);
#if QT_CONFIG(valgrind)
} else if (strcmp(argv[i], "-callgrind") == 0) {
if (!QBenchmarkValgrindUtils::haveValgrind()) {
diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp
index 4d484f01011..d7406386c6a 100644
--- a/tests/auto/testlib/selftests/tst_selftests.cpp
+++ b/tests/auto/testlib/selftests/tst_selftests.cpp
@@ -624,7 +624,7 @@ struct TestLogger
return outputFile.readAll();
}
- bool shouldIgnoreTest(const QString &test, Throw throwing) const;
+ bool shouldIgnoreTest(const QString &test) const;
operator QTestLog::LogMode() const { return logger; }
@@ -633,19 +633,13 @@ struct TestLogger
ArgumentStyle argumentStyle = NewStyleArgument;
};
-bool TestLogger::shouldIgnoreTest(const QString &test, Throw throwing) const
+bool TestLogger::shouldIgnoreTest(const QString &test) const
{
#if defined(QT_USE_APPLE_UNIFIED_LOGGING)
if (logger == QTestLog::Apple)
return true;
#endif
- if (throwing == Throw::OnFail && test == "cmptest") {
- // This test requires continuing the same test function after failure,
- // so the output is different with this flag.
- return true;
- }
-
// These tests are affected by timing and whether the CPU tick counter
// is monotonically increasing. They won't work on some machines so
// leave them off by default. Feel free to enable them for your own
@@ -1031,11 +1025,11 @@ TestProcessResult runTestProcess(const QString &test, const QStringList &argumen
/*
Runs a single test and verifies the output against the expected results.
*/
-void runTest(const QString &test, const TestLoggers &requestedLoggers, Throw throwing = {})
+void runTest(const QString &test, const TestLoggers &requestedLoggers)
{
TestLoggers loggers;
for (auto logger : requestedLoggers) {
- if (!logger.shouldIgnoreTest(test, throwing))
+ if (!logger.shouldIgnoreTest(test))
loggers += logger;
}
@@ -1045,10 +1039,6 @@ void runTest(const QString &test, const TestLoggers &requestedLoggers, Throw thr
QStringList arguments;
for (auto logger : loggers)
arguments += logger.arguments(test);
- if (throwing == Throw::OnFail) // don't distinguish between throwonfail/throwonskip
- arguments += {"-throwonfail", "-throwonskip"};
- else
- arguments += {"-nothrowonfail", "-nothrowonskip"};
CAPTURE(test);
CAPTURE(arguments);
@@ -1075,9 +1065,9 @@ void runTest(const QString &test, const TestLoggers &requestedLoggers, Throw thr
/*
Runs a single test and verifies the output against the expected result.
*/
-void runTest(const QString &test, const TestLogger &logger, Throw t = {})
+void runTest(const QString &test, const TestLogger &logger)
{
- runTest(test, TestLoggers{logger}, t);
+ runTest(test, TestLoggers{logger});
}
// ----------------------- Catch helpers -----------------------
@@ -1220,12 +1210,7 @@ SCENARIO("Test output of the loggers is as expected")
GIVEN("The " << logger << " logger") {
for (QString test : tests) {
AND_GIVEN("The " << test << " subtest") {
- WHEN("Throwing on failure or skip") {
- runTest(test, TestLogger(logger, StdoutOutput), Throw::OnFail);
- }
- WHEN("Returning on failure or skip") {
- runTest(test, TestLogger(logger, StdoutOutput));
- }
+ runTest(test, TestLogger(logger, StdoutOutput));
}
}
}