summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-01-10 11:36:36 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-01-25 18:37:48 +0100
commit2502e5a2cbc55adb43fc149aa40abc860d00d1b3 (patch)
tree068747d9ad4e0f3debe18aca5d5e614d1ae3bd51
parent8d88f1282bb614ba8fdc0990f733f74639a13cea (diff)
QTestLib: prepare QVERIFY_THROWS_EXCEPTION for FAILED_ACTION = throw
We can't have a QTEST_FAILED_ACTION in a try-block if we intend to allow QTEST_FAILED_ACTION to be a throw statement. We could, of course, add a whitelisting catch-block for the eventual TestFailedException, but as of now, the intent it to give users full control over the definition of QTEST_FAILED_ACTION, and they may have their own idea of what to throw. So add a bool variable to record whether no exception was thrown and use it to drag QTEST_FAILED_ACTION out of the try block. It's ok to be in catch blocks, no action needed there. Change-Id: I0b004e43b1db82cd8b5b12f900ed985e58a56807 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--src/testlib/qtestcase.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 47ffaca95a..62eb579986 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -116,17 +116,20 @@ inline void useVerifyThrowsException() {}
# define QVERIFY_THROWS_EXCEPTION(exceptiontype, ...) \
do {\
+ bool qverify_throws_exception_did_not_throw = false; \
QT_TRY {\
__VA_ARGS__; \
QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \
" but no exception caught", __FILE__, __LINE__); \
- QTEST_FAIL_ACTION; \
+ qverify_throws_exception_did_not_throw = true; \
} QT_CATCH (const exceptiontype &) { \
/* success */ \
} QT_CATCH (...) {\
QTest::qCaught(#exceptiontype, __FILE__, __LINE__); \
QTEST_FAIL_ACTION; \
}\
+ if (qverify_throws_exception_did_not_throw) \
+ QTEST_FAIL_ACTION; \
} while (false)
#else // QT_NO_EXCEPTIONS