summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2019-01-17 16:03:03 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2019-03-05 22:29:57 +0000
commit18da1dac20c7d27342e987586a16d125e39197c9 (patch)
tree099503358097e5dfadebfbcfdeabb75cc6b26121 /src/testlib/qtestcase.cpp
parent83864b315ff48bca33c39e1bdc03e522f68214fd (diff)
testlib: Prevent Apple test logger from stomping on other loggers
We were potentially adding the Apple test logger multiple times, and we didn't consider whether the existing loggers were logging to file or not when circumventing them. We now don't use the Apple logger if it would touch stderr and some other logger is using stdout. In the case of no explicit logger being specified on the command line, we allow the Apple logger to take priority over the default plain test logger. Change-Id: I31bbec4f4b3ab84ba9a2be35e8e5db08fee071a7 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 22e8ac49bc..0c935a1f1c 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -77,6 +77,10 @@
#include <QtTest/private/qtestutil_macos_p.h>
#endif
+#if defined(Q_OS_DARWIN)
+#include <QtTest/private/qappletestlogger_p.h>
+#endif
+
#include <cmath>
#include <numeric>
#include <algorithm>
@@ -509,7 +513,7 @@ static int qToInt(char *str)
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
{
- QTestLog::LogMode logFormat = QTestLog::Plain;
+ int logFormat = -1; // Not set
const char *logFilename = 0;
QTest::testFunctions.clear();
@@ -677,7 +681,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
fprintf(stderr, "only one logger can log to stdout\n");
exit(1);
}
- QTestLog::addLogger(logFormat, filename);
+ QTestLog::addLogger(QTestLog::LogMode(logFormat), filename);
}
delete [] filename;
delete [] format;
@@ -839,10 +843,25 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
QTestLog::setInstalledTestCoverage(installedTestCoverage);
// If no loggers were created by the long version of the -o command-line
- // option, create a logger using whatever filename and format were
- // set using the old-style command-line options.
- if (QTestLog::loggerCount() == 0)
- QTestLog::addLogger(logFormat, logFilename);
+ // option, but a logger was requested via the old-style option, add it.
+ const bool explicitLoggerRequested = logFormat != -1;
+ if (QTestLog::loggerCount() == 0 && explicitLoggerRequested)
+ QTestLog::addLogger(QTestLog::LogMode(logFormat), logFilename);
+
+ bool addFallbackLogger = !explicitLoggerRequested;
+
+#if defined(QT_USE_APPLE_UNIFIED_LOGGING)
+ // Any explicitly requested loggers will be added by now, so we can check if they use stdout
+ const bool safeToAddAppleLogger = !AppleUnifiedLogger::willMirrorToStderr() || !QTestLog::loggerUsingStdout();
+ if (safeToAddAppleLogger && QAppleTestLogger::debugLoggingEnabled()) {
+ QTestLog::addLogger(QTestLog::Apple, nullptr);
+ if (AppleUnifiedLogger::willMirrorToStderr() && !logFilename)
+ addFallbackLogger = false; // Prevent plain test logger fallback below
+ }
+#endif
+
+ if (addFallbackLogger)
+ QTestLog::addLogger(QTestLog::Plain, logFilename);
}
QBenchmarkResult qMedian(const QVector<QBenchmarkResult> &container)