mirror of https://github.com/qt/qtbase.git
testlib: Don't filter unprintable characters when targeting TTY
QAbstractTestLogger::outputString() helpfully tries to filter out unprintable characters, but if the QT_MESSAGE_PATTERN includes escaped ANSI sequences this just results in removing the escape code and outputting the ANSI sequence vebose, e.g ?[34 Change-Id: I1983cfde3670513ba1593388a97d933e684e655a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
a7f3558dd6
commit
8fd8dd0492
|
@ -19,6 +19,10 @@
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
@ -190,22 +194,35 @@ void QAbstractTestLogger::filterUnprintable(char *str) const
|
|||
Convenience method to write \a msg to the output stream.
|
||||
|
||||
The output \a msg must be a \c{'\0'}-terminated string (and not \nullptr).
|
||||
A copy of it is passed to \l filterUnprintable() and the result written to
|
||||
the output \c stream, which is then flushed.
|
||||
|
||||
If the output \c stream is TTY the message is printed as is. If not, the
|
||||
message is filtered via filterUnprintable() first. In both cases the output
|
||||
\c stream is flushed after printing.
|
||||
*/
|
||||
void QAbstractTestLogger::outputString(const char *msg)
|
||||
{
|
||||
QTEST_ASSERT(stream);
|
||||
QTEST_ASSERT(msg);
|
||||
|
||||
char *filtered = new char[strlen(msg) + 1];
|
||||
strcpy(filtered, msg);
|
||||
filterUnprintable(filtered);
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
#define isatty _isatty
|
||||
#endif
|
||||
|
||||
::fputs(filtered, stream);
|
||||
::fflush(stream);
|
||||
if (isatty(fileno(stream))) {
|
||||
::fputs(msg, stream);
|
||||
::fflush(stream);
|
||||
} else {
|
||||
char *filtered = new char[strlen(msg) + 1];
|
||||
strcpy(filtered, msg);
|
||||
filterUnprintable(filtered);
|
||||
::fputs(filtered, stream);
|
||||
::fflush(stream);
|
||||
delete [] filtered;
|
||||
}
|
||||
|
||||
delete [] filtered;
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
#undef isatty
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Reference in New Issue