From ed343669f7c219b89449762cce086cb036a9a8f2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 23 Nov 2021 09:01:13 +0100 Subject: Long live QVERIFY_THROWS_NO_EXCEPTION! Counter-part to QVERIFY_THROWS_EXCEPTION. [ChangeLog][QTest] Added QVERIFY_THROWS_NO_EXCEPTION macro. Change-Id: Ib6a80c8e810d5e2298ff00d608dae04e7a0c3e8f Reviewed-by: Edward Welbourne --- src/testlib/qtestcase.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/testlib/qtestcase.h') diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index be852bca94..0416413420 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -93,6 +93,21 @@ do {\ #ifndef QT_NO_EXCEPTIONS +# define QVERIFY_THROWS_NO_EXCEPTION(...) \ + do { \ + QT_TRY { \ + __VA_ARGS__; \ + /* success */ \ + } QT_CATCH (const std::exception &e) { \ + QTest::qCaught(nullptr, e.what(), __FILE__, __LINE__); \ + return; \ + } QT_CATCH (...) { \ + QTest::qCaught(nullptr, nullptr, __FILE__, __LINE__); \ + QT_RETHROW; \ + } \ + } while (false) \ + /* end */ + #if QT_DEPRECATED_SINCE(6, 3) namespace QTest { QT_DEPRECATED_VERSION_X_6_3("Don't use QVERIFY_EXCEPTION_THROWN(expr, type) anymore, " @@ -126,14 +141,16 @@ inline void useVerifyThrowsException() {} #else // QT_NO_EXCEPTIONS /* - * The expression passed to the macro should throw an exception and we can't - * catch it because Qt has been compiled without exception support. We can't + * These macros check whether the expression passed throws exceptions, but we can't + * catch them to check because Qt has been compiled without exception support. We can't * skip the expression because it may have side effects and must be executed. * So, users must use Qt with exception support enabled if they use exceptions * in their code. */ # define QVERIFY_THROWS_EXCEPTION(...) \ static_assert(false, "Support of exceptions is disabled") +# define QVERIFY_THROWS_NO_EXCEPTION(...) \ + static_assert(false, "Support of exceptions is disabled") #endif // !QT_NO_EXCEPTIONS -- cgit v1.2.3