summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-11-23 08:58:58 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-11-26 09:57:59 +0100
commit59600a514ba99ed62b46237d8f160dea84474190 (patch)
tree99daa7bda9085b6a540eb55891658a5fdd7315e1 /src/testlib/qtestcase.h
parent405adf3348b6d5ffb87f02550743050e4f0da4a6 (diff)
QTest: de-inline QVERIFY_THROWS_EXCEPTION message formatting
Extract Method QTest::qCaught() to take the string handling out of the header. This should help a bit in speeding up compilation of large unit test files (provided they use QVERIFY_THROWS_EXCEPTION), although I have no data to support that. Since we changed the error message, update the selftest accordingly. Change-Id: Id4a3c8c34d5df8d0c7a861106d269097f4a6de5c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.h')
-rw-r--r--src/testlib/qtestcase.h9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index eea99e26e4..be852bca94 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -115,13 +115,10 @@ inline void useVerifyThrowsException() {}
/* success */\
}\
} QT_CATCH (const std::exception &e) {\
- QByteArray msg = QByteArray() + "Expected exception of type " #exceptiontype \
- " to be thrown but std::exception caught with message: " + e.what(); \
- QTest::qFail(msg.constData(), __FILE__, __LINE__);\
+ QTest::qCaught(#exceptiontype, e.what(), __FILE__, __LINE__);\
return;\
} QT_CATCH (...) {\
- QTest::qFail("Expected exception of type " #exceptiontype " to be thrown" \
- " but unknown exception caught", __FILE__, __LINE__);\
+ QTest::qCaught(#exceptiontype, nullptr, __FILE__, __LINE__);\
QT_RETHROW;\
}\
} while (false)
@@ -323,6 +320,8 @@ namespace QTest
Q_TESTLIB_EXPORT void qSkip(const char *message, const char *file, int line);
Q_TESTLIB_EXPORT bool qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode,
const char *file, int line);
+ Q_DECL_COLD_FUNCTION
+ Q_TESTLIB_EXPORT void qCaught(const char *expected, const char *what, const char *file, int line);
#if QT_DEPRECATED_SINCE(6, 3)
QT_DEPRECATED_VERSION_X_6_3("Use qWarning() instead")
Q_TESTLIB_EXPORT void qWarn(const char *message, const char *file = nullptr, int line = 0);