QTest: add opt-in changing QCOMPARE etc to exit with throw, not return

Add exception classes and use them to change the control flow for
QTEST_{FAIL,SKIP}_ACTION from return'ing from just the immediate
function to the full way to the QTestLib infrastructure, here we
filter them out.

There are three modes:
- If QT_NO_EXCEPTION, then we return
  - If QTEST_THROW_ON_... is also defined, #error out
- Otherwise, if QTEST_THROW_ON_... is defined, always throw
- Otherwise, the decision is made at runtime (with defaults read from
  QTEST_THROW_ON_... environment variables).

Three selftests depend on the old behavior, as they explicitly check
that multiple FAIL SKIP etc emerge, which the new framework, of
course, prevents. Locally disable throwing at the test function level.

Add initial docs and enable exceptions in all of the selftest
subprograms to facilitate switching between the two runtime-selectable
modes.

[ChangeLog][QtTest] Added QTEST_THROW_ON_FAIL and QTEST_THROW_ON_SKIP
C++ macros and environment variables that, when defined, change how
QCOMPARE/QVERIFY/QSKIP etc exit the test function on failure. Instead
of a return, exiting only the immediately-surrounding function, they
throw a special exception instead, thereby exiting from subfunctions
of the test function, all the way to QtTestLib.

Fixes: QTBUG-66320
Change-Id: I96c38d2a1dcdd9de84942cf448a8bbf3ab6d3679
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
bb10
Marc Mutz 2024-01-10 14:28:01 +01:00
parent 3bcfd55cb3
commit e769cf026e
69 changed files with 332 additions and 2 deletions

View File

@ -415,6 +415,12 @@
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_SKIP, except affecting QSKIP().
\endlist
\section1 Creating a Benchmark

View File

@ -458,9 +458,193 @@ namespace QTestPrivate
Q_TESTLIB_EXPORT Qt::MouseButtons qtestMouseButtons = Qt::NoButton;
}
namespace {
class TestFailedException : public std::exception // clazy:exclude=copyable-polymorphic
{
public:
TestFailedException() = default;
~TestFailedException() override = default;
const char *what() const noexcept override { return "QtTest: test failed"; }
};
class TestSkippedException : public std::exception // clazy:exclude=copyable-polymorphic
{
public:
TestSkippedException() = default;
~TestSkippedException() override = default;
const char *what() const noexcept override { return "QtTest: test was skipped"; }
};
} // unnamed namespace
namespace QTest
{
void Internal::throwOnFail() { throw TestFailedException(); }
void Internal::throwOnSkip() { throw TestSkippedException(); }
Q_CONSTINIT static QBasicAtomicInt g_throwOnFail = Q_BASIC_ATOMIC_INITIALIZER(0);
Q_CONSTINIT static QBasicAtomicInt g_throwOnSkip = Q_BASIC_ATOMIC_INITIALIZER(0);
void Internal::maybeThrowOnFail()
{
if (g_throwOnFail.loadRelaxed() > 0)
Internal::throwOnFail();
}
void Internal::maybeThrowOnSkip()
{
if (g_throwOnSkip.loadRelaxed() > 0)
Internal::throwOnSkip();
}
/*!
\since 6.8
\macro QTEST_THROW_ON_FAIL
\relates <QTest>
When defined, QCOMPARE()/QVERIFY() etc always throw on failure.
QTest::throwOnFail() then no longer has any effect.
*/
/*!
\since 6.8
\macro QTEST_THROW_ON_SKIP
\relates <QTest>
When defined, QSKIP() always throws. QTest::throwOnSkip() then no longer
has any effect.
*/
/*!
\since 6.8
\class QTest::ThrowOnFailEnabler
\inmodule QtTestLib
RAII class around setThrowOnFail().
*/
/*!
\fn QTest::ThrowOnFailEnabler::ThrowOnFailEnabler()
Constructor. Calls \c{setThrowOnFail(true)}.
*/
/*!
\fn QTest::ThrowOnFailEnabler::~ThrowOnFailEnabler()
Destructor. Calls \c{setThrowOnFail(false)}.
*/
/*!
\since 6.8
\class QTest::ThrowOnFailDisabler
\inmodule QtTestLib
RAII class around setThrowOnFail().
*/
/*!
\fn QTest::ThrowOnFailDisabler::ThrowOnFailDisabler()
Constructor. Calls \c{setThrowOnFail(false)}.
*/
/*!
\fn QTest::ThrowOnFailDisabler::~ThrowOnFailDisabler()
Destructor. Calls \c{setThrowOnFail(true)}.
*/
/*!
\since 6.8
\class QTest::ThrowOnSkipEnabler
\inmodule QtTestLib
RAII class around setThrowOnSkip().
*/
/*!
\fn QTest::ThrowOnSkipEnabler::ThrowOnSkipEnabler()
Constructor. Calls \c{setThrowOnSkip(true)}.
*/
/*!
\fn QTest::ThrowOnSkipEnabler::~ThrowOnSkipEnabler()
Destructor. Calls \c{setThrowOnSkip(false)}.
*/
/*!
\since 6.8
\class QTest::ThrowOnSkipDisabler
\inmodule QtTestLib
RAII class around setThrowOnSkip().
*/
/*!
\fn QTest::ThrowOnSkipDisabler::ThrowOnSkipDisabler()
Constructor. Calls \c{setThrowOnSkip(false)}.
*/
/*!
\fn QTest::ThrowOnSkipDisabler::~ThrowOnSkipDisabler()
Destructor. Calls \c{setThrowOnSkip(true)}.
*/
/*!
\since 6.8
Enables (\a enable = \c true) or disables (\ enable = \c false) throwing on
QCOMPARE()/QVERIFY() failures (as opposed to just returning from the
immediately-surrounding function context).
The feature is reference-counted: If you call this function \e{N} times
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.
\note You must compile your tests with exceptions enabled to use this
feature.
\sa setThrowOnSkip(), ThrowOnFailEnabler, ThrowOnFailDisabler, QTEST_THROW_ON_FAIL
*/
void setThrowOnFail(bool enable) noexcept
{
g_throwOnFail.fetchAndAddRelaxed(enable ? 1 : -1);
}
/*!
\since 6.8
Enables (\a enable = \c true) or disables (\ enable = \c false) throwing on
QSKIP() (as opposed to just returning from the immediately-surrounding
function context).
The feature is reference-counted: If you call this function \e{N} times
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.
\note You must compile your tests with exceptions enabled to use this
feature.
\sa setThrowOnFail(), ThrowOnSkipEnabler, ThrowOnSkipDisabler, QTEST_THROW_ON_SKIP
*/
void setThrowOnSkip(bool enable) noexcept
{
g_throwOnSkip.fetchAndAddRelaxed(enable ? 1 : -1);
}
QString Internal::formatTryTimeoutDebugMessage(q_no_char8_t::QUtf8StringView expr, int timeout, int actual)
{
return "QTestLib: This test case check (\"%1\") failed because the requested timeout (%2 ms) "
@ -546,7 +730,14 @@ static bool skipBlacklisted = false;
static bool invokeTestMethodIfValid(QMetaMethod m, QObject *obj = QTest::currentTestObject)
{
return m.isValid() && m.invoke(obj, Qt::DirectConnection);
if (!m.isValid())
return false;
bool ok = true;
try { ok = m.invoke(obj, Qt ::DirectConnection); }
catch (const TestFailedException &) {} // ignore (used for control flow)
catch (const TestSkippedException &) {} // ditto
// every other exception is someone else's problem
return ok;
}
static void invokeTestMethodIfExists(const char *methodName, QObject *obj = QTest::currentTestObject)
@ -720,6 +911,11 @@ 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;

View File

@ -23,6 +23,26 @@
QT_BEGIN_NAMESPACE
#ifndef QT_NO_EXCEPTIONS
#ifdef QTEST_THROW_ON_FAILURE
# define QTEST_FAIL_ACTION QTest::Internal::throwOnFail()
#else
# define QTEST_FAIL_ACTION do { QTest::Internal::maybeThrowOnFail(); return; } while (false)
#endif
#ifdef QTEST_THROW_ON_SKIP
# define QTEST_SKIP_ACTION QTest::Internal::throwOnSkip()
#else
# define QTEST_SKIP_ACTION do { QTest::Internal::maybeThrowOnSkip(); return; } while (false)
#endif
#else
# if defined(QTEST_THROW_ON_FAILURE) || defined(QTEST_THROW_ON_SKIP)
# error QTEST_THROW_ON_FAILURE/SKIP require exception support enabled.
# endif
#endif // QT_NO_EXCEPTIONS
#ifndef QTEST_FAIL_ACTION
# define QTEST_FAIL_ACTION return
#endif
@ -300,6 +320,11 @@ namespace QTest
{
namespace Internal {
[[noreturn]] Q_TESTLIB_EXPORT void throwOnFail();
[[noreturn]] Q_TESTLIB_EXPORT void throwOnSkip();
Q_TESTLIB_EXPORT void maybeThrowOnFail();
Q_TESTLIB_EXPORT void maybeThrowOnSkip();
Q_TESTLIB_EXPORT QString formatTryTimeoutDebugMessage(q_no_char8_t::QUtf8StringView expr, int timeout, int actual);
template<typename T> // Output registered enums
@ -385,6 +410,36 @@ namespace QTest
#endif // QT_CONFIG(batch_test_support)
Q_TESTLIB_EXPORT void setMainSourcePath(const char *file, const char *builddir = nullptr);
Q_TESTLIB_EXPORT void setThrowOnFail(bool enable) noexcept;
Q_TESTLIB_EXPORT void setThrowOnSkip(bool enable) noexcept;
class ThrowOnFailEnabler {
Q_DISABLE_COPY_MOVE(ThrowOnFailEnabler)
public:
ThrowOnFailEnabler() { setThrowOnFail(true); }
~ThrowOnFailEnabler() { setThrowOnFail(false); }
};
class ThrowOnSkipEnabler {
Q_DISABLE_COPY_MOVE(ThrowOnSkipEnabler)
public:
ThrowOnSkipEnabler() { setThrowOnSkip(true); }
~ThrowOnSkipEnabler() { setThrowOnSkip(false); }
};
class ThrowOnFailDisabler {
Q_DISABLE_COPY_MOVE(ThrowOnFailDisabler)
public:
ThrowOnFailDisabler() { setThrowOnFail(false); }
~ThrowOnFailDisabler() { setThrowOnFail(true); }
};
class ThrowOnSkipDisabler {
Q_DISABLE_COPY_MOVE(ThrowOnSkipDisabler)
public:
ThrowOnSkipDisabler() { setThrowOnSkip(false); }
~ThrowOnSkipDisabler() { setThrowOnSkip(true); }
};
Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description,
const char *file, int line);

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(assert
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_assert.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(badxml
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_badxml.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(benchlibcallgrind
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_benchlibcallgrind.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(benchlibcounting
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_benchlibcounting.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(benchlibeventcounter
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_benchlibeventcounter.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(benchliboptions
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_benchliboptions.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(benchlibtickcounter
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_benchlibtickcounter.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(benchlibwalltime
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_benchlibwalltime.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(blacklisted
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_blacklisted.cpp

View File

@ -1,6 +1,9 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#undef QTEST_THROW_ON_FAILURE // fails ### investigate
#undef QTEST_THROW_ON_SKIP // fails ### investigate
#include <QtCore/QCoreApplication>
#include <QTest>
#include <private/qtestlog_p.h>
@ -65,6 +68,7 @@ void tst_Blacklisted::fail()
void tst_Blacklisted::multiFail() // cf. ../subtest/'s similar tests
{
const QTest::ThrowOnFailDisabler nothrow; // tests repeated QFAILs
++blacklisted;
for (int i = 0; i < 10; ++i)
[]() { QFAIL("This failure message should be repeated ten times"); }();
@ -73,6 +77,7 @@ void tst_Blacklisted::multiFail() // cf. ../subtest/'s similar tests
void tst_Blacklisted::multiSkip()
{
const QTest::ThrowOnSkipDisabler nothrow; // tests repeated QSKIPs
// Similar to multiFail()
++skipped;
for (int i = 0; i < 10; ++i)

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(cmptest
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_cmptest.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(commandlinedata
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_commandlinedata.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(counting
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_counting.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(crashes
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_crashes.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(datatable
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_datatable.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(datetime
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_datetime.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(deleteLater
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_deleteLater.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(deleteLater_noApp
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_deleteLater_noApp.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(differentexec
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_differentexec.cpp

View File

@ -4,6 +4,7 @@
qt_internal_add_executable(eventloop
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_eventloop.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(expectfail
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_expectfail.cpp

View File

@ -3,6 +3,7 @@
qt_internal_add_executable(extendedcompare
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_extendedcompare.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(failcleanup
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_failcleanup.cpp

View File

@ -4,6 +4,7 @@
qt_internal_add_executable(failcleanuptestcase
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_failcleanuptestcase.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(faildatatype
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_faildatatype.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(failfetchtype
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_failfetchtype.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(failinit
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_failinit.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(failinitdata
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_failinitdata.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(fetchbogus
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_fetchbogus.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(findtestdata
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
findtestdata.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(float
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_float.cpp

View File

@ -204,7 +204,7 @@ del re
# Keep in sync with tst_selftests.cpp's testEnvironment():
def baseEnv(platname=None,
keep=('PATH', 'QT_QPA_PLATFORM', 'ASAN_OPTIONS'),
keep=('PATH', 'QT_QPA_PLATFORM', 'QTEST_THROW_ON_FAIL', 'QTEST_THROW_ON_SKIP', 'ASAN_OPTIONS'),
posix=('HOME', 'USER', 'QEMU_SET_ENV', 'QEMU_LD_PREFIX'),
nonapple=('DISPLAY', 'XAUTHORITY', 'XAUTHLOCALHOSTNAME'), # and XDG_*
# Don't actually know how to test for QNX, so this is ignored:

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(globaldata
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_globaldata.cpp

View File

@ -3,6 +3,7 @@
qt_internal_add_executable(junit
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_junit.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(keyboard
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_keyboard.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(longstring
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_longstring.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(maxwarnings
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
maxwarnings.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(mouse
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_mouse.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(multiexec
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_multiexec.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(pairdiagnostics
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_pairdiagnostics.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(pass
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
SOURCES
tst_pass.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(printdatatags
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_printdatatags.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(printdatatagswithglobaltags
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_printdatatagswithglobaltags.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(qexecstringlist
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_qexecstringlist.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(signaldumper
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_signaldumper.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(silent
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_silent.cpp

View File

@ -3,6 +3,7 @@
qt_internal_add_executable(silent_fatal
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_silent_fatal.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(singleskip
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_singleskip.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(skip
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_skip.cpp

View File

@ -4,6 +4,7 @@
qt_internal_add_executable(skipblacklisted
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_skipblacklisted.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(skipcleanup
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_skipcleanup.cpp

View File

@ -4,6 +4,7 @@
qt_internal_add_executable(skipcleanuptestcase
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_skipcleanuptestcase.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(skipinit
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_skipinit.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(skipinitdata
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_skipinitdata.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(sleep
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_sleep.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(strcmp
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_strcmp.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(subtest
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_subtest.cpp

View File

@ -1,6 +1,8 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#undef QTEST_THROW_ON_FAILURE // code expects old behavior
#undef QTEST_THROW_ON_SKIP // code expects old behavior
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
@ -111,6 +113,7 @@ void tst_Subtest::test3()
void tst_Subtest::multiFail()
{
const QTest::ThrowOnFailDisabler nothrow; // tests repeated QFAILs
// Simulates tests which call a shared function that does common checks, or
// that do checks in code run asynchronously from a message loop.
for (int i = 0; i < 10; ++i)
@ -120,6 +123,7 @@ void tst_Subtest::multiFail()
void tst_Subtest::multiSkip()
{
const QTest::ThrowOnSkipDisabler nothrow; // tests repeated QSKIPs
// Similar to multiFail()
for (int i = 0; i < 10; ++i)
[]() { QSKIP("This skip should be repeated ten times"); }();

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(testlib
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_testlib.cpp

View File

@ -931,6 +931,7 @@ static QProcessEnvironment testEnvironment()
const auto envKeys = systemEnvironment.keys();
for (const QString &key : envKeys) {
const bool useVariable = key == "PATH" || key == "QT_QPA_PLATFORM"
|| key == "QTEST_THROW_ON_FAIL"_L1 || key == "QTEST_THROW_ON_SKIP"_L1
|| key == "ASAN_OPTIONS"
#if defined(Q_OS_QNX)
|| key == "GRAPHICS_ROOT" || key == "TZ"

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(tuplediagnostics
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_tuplediagnostics.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(verbose1
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
../counting/tst_counting.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(verbose2
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
../counting/tst_counting.cpp

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(warnings
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_warnings.cpp

View File

@ -1,6 +1,7 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#undef QTEST_THROW_ON_FAILURE // fails ### investigate
#include <QtCore/QCoreApplication>
#include <QtCore/QRegularExpression>
@ -183,6 +184,7 @@ void tst_Warnings::testFailOnWarningsWithData()
void tst_Warnings::testFailOnWarningsFailInHelper()
{
const QTest::ThrowOnFailDisabler nothrow; // tests repeated QFAILs
[](){ QFAIL("This failure message should be printed but not cause the test to abort"); }();
// So we've already failed, but we get more messages - that don't increment counters.
const auto warnRegex = QRegularExpression("Ran out of .*!");

View File

@ -7,6 +7,7 @@
qt_internal_add_executable(watchdog
NO_INSTALL
EXCEPTIONS
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES
tst_watchdog.cpp