summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-08-27 16:53:35 +0200
committerMarc Mutz <marc.mutz@qt.io>2021-11-25 13:00:55 +0100
commitf4e89d58dade4113362b0341035ed742eeca6314 (patch)
tree501adfee73fbb2ee07146f43f7c3e5323fadef68 /src/testlib/qtestcase.h
parent8761208aefe86b4e07c66bfedbd1a282ee15e7d3 (diff)
QVERIFY_EXCEPTION_THROWN: re-throw unknown exceptions
Swallowing unknown exceptions is dangerous business, as the exception might be a pthread cancellation token, the swallowing of which would terminate the program. Instead of returning from the catch-all-clause, therefore, re-throw the unknown exception. Fix tst_verifyexceptionthrown failure cases that use non-std::exception-derived true negative exceptions to not let the exception escape from the test function. As a drive-by, pretty up the macro's docs. [ChangeLog][QtTest][QVERIFY_EXCEPTION_THROWN] Now re-throws unknown exceptions (= not derived from std::exception) (was: swallowed them and returned from the test function), in order to play nice with pthread cancellation. Pick-to: 6.2 5.15 Change-Id: Ic036d4a9ed4b7683fa67e27af8bcbae0eefdd0da 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.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 03667a72a1..fbb756fe23 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -102,6 +102,7 @@ do {\
" but no exception caught", __FILE__, __LINE__);\
return;\
} QT_CATCH (const exceptiontype &) {\
+ /* success */\
}\
} QT_CATCH (const std::exception &e) {\
QByteArray msg = QByteArray() + "Expected exception of type " #exceptiontype \
@@ -111,7 +112,7 @@ do {\
} QT_CATCH (...) {\
QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \
" but unknown exception caught", __FILE__, __LINE__);\
- return;\
+ QT_RETHROW;\
}\
} while (false)