summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-31 18:25:42 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-04 19:31:51 +0200
commitbef57b317f2efc0e73f2275d594be9d69f5a75d0 (patch)
treefc277768e0812c65c5a860a2971b859a833c5088 /src
parentfe9c705e9aa0e25760646695820bd876de590893 (diff)
testlib: Deprecate QWARN() in favor of qWarning()
The QtTest best practices documentations recommends using output mechanisms such as qDebug() and qWarning() for diagnostic messages, and this is also what most of our own tests do. The QWARN() macro and corresponding internal QTest::qWarn() function was added when QtTest was first implemented, but was likely meant as an internal implementation detail, like its cousin QTestLog::info(), which does not have any corresponding macro. This theory is backed by our own QtTest self-test (tst_silent) describing the output from QWARN() as "an internal testlib warning". The only difference between QWARN() and qWarning(), besides the much richer feature set of the latter, is that qWarning() will not pass on file and line number information in release mode, but QWARN() will. This is an acceptable loss of functionality, considering that the user can override this behavior by defining QT_MESSAGELOGCONTEXT. [ChangeLog][QtTest] QWARN() has been deprecated in favor of qWarning() Pick-to: 6.2 Change-Id: I5a2431ce48c47392244560dd520953b9fc735c85 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/qtestcase.h16
-rw-r--r--src/testlib/qtestcase.qdoc1
2 files changed, 14 insertions, 3 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 158fce4e3d..55419551fa 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -208,9 +208,6 @@ do {\
return;\
} while (false)
-#define QWARN(msg)\
- QTest::qWarn(static_cast<const char *>(msg), __FILE__, __LINE__)
-
#ifdef QT_TESTCASE_BUILDDIR
#ifndef QT_TESTCASE_SOURCEDIR
@@ -576,6 +573,19 @@ namespace QTest
#undef QTEST_COMPARE_DECL
+#if QT_DEPRECATED_SINCE(6, 2)
+namespace QTestPrivate {
+QT_DEPRECATED_VERSION_X_6_2("Use qWarning() instead")
+Q_DECL_UNUSED static inline void qWarnMacro(const char *message, const char *file = nullptr, int line = 0)
+{
+ QTest::qWarn(message, file, line);
+}
+}
+#endif
+
+#define QWARN(msg) \
+ QTestPrivate::qWarnMacro(static_cast<const char *>(msg), __FILE__, __LINE__)
+
QT_END_NAMESPACE
#endif
diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc
index 2a480fb349..9950418a5c 100644
--- a/src/testlib/qtestcase.qdoc
+++ b/src/testlib/qtestcase.qdoc
@@ -336,6 +336,7 @@
\relates QTest
\threadsafe
+ \deprecated Use qWarning() instead.
Appends \a message as a warning to the test log. This macro can be used anywhere
in your tests.