diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-08-27 16:53:35 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-11-25 13:00:55 +0100 |
commit | f4e89d58dade4113362b0341035ed742eeca6314 (patch) | |
tree | 501adfee73fbb2ee07146f43f7c3e5323fadef68 /tests/auto/testlib/selftests | |
parent | 8761208aefe86b4e07c66bfedbd1a282ee15e7d3 (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 'tests/auto/testlib/selftests')
-rw-r--r-- | tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp index c9365360de..e0e26a0a47 100644 --- a/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp +++ b/tests/auto/testlib/selftests/verifyexceptionthrown/tst_verifyexceptionthrown.cpp @@ -112,12 +112,16 @@ void tst_VerifyExceptionThrown::testCorrectMyExceptions() const void tst_VerifyExceptionThrown::testFailInt() const { - QVERIFY_EXCEPTION_THROWN(throw int(5), double); + try { + QVERIFY_EXCEPTION_THROWN(throw int(5), double); + } catch (int) {} } void tst_VerifyExceptionThrown::testFailStdString() const { - QVERIFY_EXCEPTION_THROWN(throw std::string("some string"), char*); + try { + QVERIFY_EXCEPTION_THROWN(throw std::string("some string"), char*); + } catch (const std::string &) {} } void tst_VerifyExceptionThrown::testFailStdRuntimeError() const |