diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-11-23 09:01:13 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-11-26 18:28:50 +0100 |
commit | ed343669f7c219b89449762cce086cb036a9a8f2 (patch) | |
tree | c9d888772ef5418900dd20117798f4505cd39317 /src/testlib/qtestcase.h | |
parent | 6a1a9365371f6e456bafe5120467c100cf7ca105 (diff) |
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 <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.h')
-rw-r--r-- | src/testlib/qtestcase.h | 21 |
1 files changed, 19 insertions, 2 deletions
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 |