summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-07-28 11:44:01 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-08-04 17:31:51 +0000
commitfa8cffa4c97d2e46de9af6f5e91af9212e372204 (patch)
tree1affb73d7b113acec05f4d92375b3be3aaca6d17 /src
parentbef57b317f2efc0e73f2275d594be9d69f5a75d0 (diff)
testlib: Pass on file location on failure, but don't assume we have one
We try our best to pass on the file location of a failure, including for fatal errors, but the reporting or logging machinery should not assume there is one. By passing on nullptr for the file location we allow the logging backends to decide how to handle the situation, e.g. by not emitting extra fields for failure location. This effectively reverts c25687fa0b6e4be043e1f8c92c093d8b06ca06c4, in favor of relying on the backends to cope with null filename, which they already did. As qFatal uses QMessageLogger, which by default disables file/line information in release builds, we need to explicitly enable this in our self-tests, to get uniform test results. Similarly, we disable file/line info from testlib itself, as reporting Qt internal file and line information for user diagnostics is less useful. The odd one out there is qtestdata.cpp, which still ends up in test output due to using QTEST_ASSERT instead of qFatal for its diagnostics. Cleaning up that, and unifying how we report testlib issues to the user, is left for another day. Pick-to: 6.2 Change-Id: Ib9451b8eed86fe3ade4a4dcaf0037e1a3450321c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/testlib/CMakeLists.txt2
-rw-r--r--src/testlib/qtestlog.cpp8
-rw-r--r--src/testlib/qtestresult.cpp9
-rw-r--r--src/testlib/qtestresult_p.h2
4 files changed, 8 insertions, 13 deletions
diff --git a/src/testlib/CMakeLists.txt b/src/testlib/CMakeLists.txt
index 18fd9d2cee..c1c4270e12 100644
--- a/src/testlib/CMakeLists.txt
+++ b/src/testlib/CMakeLists.txt
@@ -62,6 +62,8 @@ qt_internal_add_module(Test
QT_NO_CAST_TO_ASCII
QT_NO_DATASTREAM
QT_NO_FOREACH
+ # Ensure uniform location info between release and debug builds
+ QT_NO_MESSAGELOGCONTEXT
LIBRARIES
Qt::CorePrivate
PUBLIC_LIBRARIES
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index 7fbb3155fa..134df48f0f 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -239,7 +239,7 @@ namespace QTest {
* this function, it will proceed with calling exit() and abort()
* and hence crash. Therefore, we call these logging functions such
* that we wrap up nicely, and in particular produce well-formed XML. */
- QTestResult::addFailure("Received a fatal error.", "Unknown file", 0);
+ QTestResult::addFailure("Received a fatal error.", context.file, context.line);
QTestLog::leaveTestFunction();
QTestLog::stopLogging();
}
@@ -336,7 +336,6 @@ void QTestLog::addFail(const char *msg, const char *file, int line)
void QTestLog::addXFail(const char *msg, const char *file, int line)
{
QTEST_ASSERT(msg);
- QTEST_ASSERT(file);
FOREACH_TEST_LOGGER
logger->addIncident(QAbstractTestLogger::XFail, msg, file, line);
@@ -345,7 +344,6 @@ void QTestLog::addXFail(const char *msg, const char *file, int line)
void QTestLog::addXPass(const char *msg, const char *file, int line)
{
QTEST_ASSERT(msg);
- QTEST_ASSERT(file);
++QTest::fails;
@@ -366,7 +364,6 @@ void QTestLog::addBPass(const char *msg)
void QTestLog::addBFail(const char *msg, const char *file, int line)
{
QTEST_ASSERT(msg);
- QTEST_ASSERT(file);
++QTest::blacklists;
@@ -377,7 +374,6 @@ void QTestLog::addBFail(const char *msg, const char *file, int line)
void QTestLog::addBXPass(const char *msg, const char *file, int line)
{
QTEST_ASSERT(msg);
- QTEST_ASSERT(file);
++QTest::blacklists;
@@ -388,7 +384,6 @@ void QTestLog::addBXPass(const char *msg, const char *file, int line)
void QTestLog::addBXFail(const char *msg, const char *file, int line)
{
QTEST_ASSERT(msg);
- QTEST_ASSERT(file);
++QTest::blacklists;
@@ -399,7 +394,6 @@ void QTestLog::addBXFail(const char *msg, const char *file, int line)
void QTestLog::addSkip(const char *msg, const char *file, int line)
{
QTEST_ASSERT(msg);
- QTEST_ASSERT(file);
++QTest::skips;
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp
index 96c7af29d5..7498b92024 100644
--- a/src/testlib/qtestresult.cpp
+++ b/src/testlib/qtestresult.cpp
@@ -164,15 +164,14 @@ static void clearExpectFail()
void QTestResult::finishedCurrentTestData()
{
- if (QTest::expectFailMode) {
- addFailure("QEXPECT_FAIL was called without any subsequent verification statements",
- "Unknown File", 0);
- }
+ if (QTest::expectFailMode)
+ addFailure("QEXPECT_FAIL was called without any subsequent verification statements");
+
clearExpectFail();
if (!QTest::hasFailed() && QTestLog::unhandledIgnoreMessages()) {
QTestLog::printUnhandledIgnoreMessages();
- addFailure("Not all expected messages were received", "Unknown File", 0);
+ addFailure("Not all expected messages were received");
}
QTestLog::clearIgnoreMessages();
}
diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h
index 05ae764722..ba2237afec 100644
--- a/src/testlib/qtestresult_p.h
+++ b/src/testlib/qtestresult_p.h
@@ -77,7 +77,7 @@ public:
static void reset();
static void setBlacklistCurrentTest(bool b);
- static void addFailure(const char *message, const char *file, int line);
+ static void addFailure(const char *message, const char *file = nullptr, int line = 0);
static bool compare(bool success, const char *failureMsg,
char *val1, char *val2,
const char *actual, const char *expected,