summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-01-10 10:32:33 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-01-25 11:35:52 +0100
commit557275301edfc23a6d2f97a44e6b142790d9059c (patch)
tree9d27d55a85ad39d16b92c8081812d97d888c1b82 /src/testlib
parent711def1290439d19e7ed9068704bb2160edab968 (diff)
QTest: replace naked returns with QTEST_{FAIL,SKIP}_ACTION macros
... defaulting to "return". This allows customizing these actions, incl. to eventually make them throwing exceptions instead (but that won't work for QVERIFY_THROWS_EXCEPTION, yet). Change-Id: I078a4ce48135bda2cf98fce78318a12d757d7aa5 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtestcase.cpp8
-rw-r--r--src/testlib/qtestcase.h32
2 files changed, 24 insertions, 16 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index fd47db3f55..9a5c088a6e 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -2627,11 +2627,11 @@ void QTest::qCaught(const char *expected, const char *what, const char *file, in
If the exception inherits std::exception, its what() message is logged and
this function returns normally. The caller of this function must then
- execute a \c{return} to exit from the test function.
+ execute a \c{QTEST_FAIL_ACTION} to exit from the test function.
Otherwise, a message saying an unknown exception was caught is logged and
- this function rethrows the exception, skipping the \c{return} that follows
- this function call in the caller.
+ this function rethrows the exception, skipping the \c{QTEST_FAIL_ACTION}
+ that follows this function call in the caller.
*/
void QTest::qCaught(const char *expected, const char *file, int line)
{
@@ -2644,7 +2644,7 @@ void QTest::qCaught(const char *expected, const char *file, int line)
qCaught(expected, nullptr, file, line);
throw;
}
- // caller shall invoke `return` if control reached here
+ // caller shall invoke `QTEST_FAIL_ACTION` if control reached here
}
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index fcd9ad8cfc..47ffaca95a 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -23,36 +23,44 @@
QT_BEGIN_NAMESPACE
+#ifndef QTEST_FAIL_ACTION
+# define QTEST_FAIL_ACTION return
+#endif
+
+#ifndef QTEST_SKIP_ACTION
+# define QTEST_SKIP_ACTION return
+#endif
+
class qfloat16;
class QRegularExpression;
#define QVERIFY(statement) \
do {\
if (!QTest::qVerify(static_cast<bool>(statement), #statement, "", __FILE__, __LINE__))\
- return;\
+ QTEST_FAIL_ACTION; \
} while (false)
#define QFAIL(message) \
do {\
QTest::qFail(static_cast<const char *>(message), __FILE__, __LINE__);\
- return;\
+ QTEST_FAIL_ACTION; \
} while (false)
#define QVERIFY2(statement, description) \
do {\
if (statement) {\
if (!QTest::qVerify(true, #statement, static_cast<const char *>(description), __FILE__, __LINE__))\
- return;\
+ QTEST_FAIL_ACTION; \
} else {\
if (!QTest::qVerify(false, #statement, static_cast<const char *>(description), __FILE__, __LINE__))\
- return;\
+ QTEST_FAIL_ACTION; \
}\
} while (false)
#define QCOMPARE(actual, expected) \
do {\
if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
- return;\
+ QTEST_FAIL_ACTION; \
} while (false)
// A wrapper lambda is introduced to extend the lifetime of lhs and rhs in
@@ -71,7 +79,7 @@ do { \
#lhs, #rhs, QTest::ComparisonOperation::opId, \
__FILE__, __LINE__); \
}(lhs, rhs)) { \
- return; \
+ QTEST_FAIL_ACTION; \
} \
} while (false)
@@ -91,7 +99,7 @@ do { \
/* success */ \
} QT_CATCH (...) { \
QTest::qCaught(nullptr, __FILE__, __LINE__); \
- return; \
+ QTEST_FAIL_ACTION; \
} \
} while (false) \
/* end */
@@ -112,12 +120,12 @@ inline void useVerifyThrowsException() {}
__VA_ARGS__; \
QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \
" but no exception caught", __FILE__, __LINE__); \
- return; \
+ QTEST_FAIL_ACTION; \
} QT_CATCH (const exceptiontype &) { \
/* success */ \
} QT_CATCH (...) {\
QTest::qCaught(#exceptiontype, __FILE__, __LINE__); \
- return; \
+ QTEST_FAIL_ACTION; \
}\
} while (false)
@@ -240,7 +248,7 @@ do { \
#define QSKIP_INTERNAL(statement) \
do {\
QTest::qSkip(static_cast<const char *>(statement), __FILE__, __LINE__);\
- return;\
+ QTEST_SKIP_ACTION; \
} while (false)
#define QSKIP(statement, ...) QSKIP_INTERNAL(statement)
@@ -248,7 +256,7 @@ do {\
#define QEXPECT_FAIL(dataIndex, comment, mode)\
do {\
if (!QTest::qExpectFail(dataIndex, static_cast<const char *>(comment), QTest::mode, __FILE__, __LINE__))\
- return;\
+ QTEST_FAIL_ACTION; \
} while (false)
#define QFETCH(Type, name)\
@@ -260,7 +268,7 @@ do {\
#define QTEST(actual, testElement)\
do {\
if (!QTest::qTest(actual, testElement, #actual, #testElement, __FILE__, __LINE__))\
- return;\
+ QTEST_FAIL_ACTION; \
} while (false)
#ifdef QT_TESTCASE_BUILDDIR