diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-11-23 08:52:22 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-11-26 04:44:26 +0100 |
commit | 1edf153a6bc28e127531e852a0856025ca5d91b0 (patch) | |
tree | cbec5b76b81776db30a572578d812baff7576064 /src/testlib/qtestcase.h | |
parent | b9be035c6268ed5359213de8baacbd5e9f4c5f37 (diff) |
Long live QVERIFY_THROWS_EXCEPTION!
Use variable args macros to swallow any extra commas in the
expression. To use this, the type of the exception has to be first.
Use Eddy's suggestion for a new name to avoid breaking the old macro.
[ChangeLog][QtTest] Added QVERIFY_THROWS_EXCEPTION, replacing
QVERIFY_EXCEPTION_THROWN, which has therefore been deprecated.
Change-Id: I16825c35bae0631c5fad5a9a3ace4d6edc067f83
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.h')
-rw-r--r-- | src/testlib/qtestcase.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index fbb756fe23..c5a90c8e1b 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -93,11 +93,21 @@ do {\ #ifndef QT_NO_EXCEPTIONS +#if QT_DEPRECATED_SINCE(6, 3) +namespace QTest { +QT_DEPRECATED_VERSION_X_6_3("Don't use QVERIFY_EXCEPTION_THROWN(expr, type) anymore, " + "use QVERIFY_THROWS_EXCEPTION(type, expr...) instead") +inline void useVerifyThrowsException() {} +} // namespace QTest # define QVERIFY_EXCEPTION_THROWN(expression, exceptiontype) \ + QVERIFY_THROWS_EXCEPTION(exceptiontype, QTest::useVerifyThrowsException(); expression) +#endif + +# define QVERIFY_THROWS_EXCEPTION(exceptiontype, ...) \ do {\ QT_TRY {\ QT_TRY {\ - expression;\ + __VA_ARGS__;\ QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \ " but no exception caught", __FILE__, __LINE__);\ return;\ @@ -125,7 +135,7 @@ do {\ * So, users must use Qt with exception support enabled if they use exceptions * in their code. */ -# define QVERIFY_EXCEPTION_THROWN(expression, exceptiontype) \ +# define QVERIFY_THROWS_EXCEPTION(...) \ static_assert(false, "Support of exceptions is disabled") #endif // !QT_NO_EXCEPTIONS |