QPlainTestLogger: do not print "failure location" if there's no failure
When running a test under increased verbosity levels, QTestLib would print "failure location" for every QTest function (QVERIFY, QCOMPARE, ...), even if there's no failure at all. Keep the code centralized, but split the formatting of failures and non-failures (other messages). Task-number: QTBUG-96844 Change-Id: I3c508653176b68579dc0eb0cffcc153a52da2e2c Pick-to: 5.15 6.2 6.3 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
63f79d7ffb
commit
a605b9297d
@ -227,7 +227,8 @@ void QPlainTestLogger::outputMessage(const char *str)
|
||||
outputString(str);
|
||||
}
|
||||
|
||||
void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line)
|
||||
void QPlainTestLogger::printMessage(MessageSource source, const char *type, const char *msg,
|
||||
const char *file, int line)
|
||||
{
|
||||
QTEST_ASSERT(type);
|
||||
QTEST_ASSERT(msg);
|
||||
@ -235,13 +236,23 @@ void QPlainTestLogger::printMessage(const char *type, const char *msg, const cha
|
||||
QTestCharBuffer messagePrefix;
|
||||
|
||||
QTestCharBuffer failureLocation;
|
||||
if (file) {
|
||||
#ifdef Q_OS_WIN
|
||||
#define FAILURE_LOCATION_STR "\n%s(%d) : failure location"
|
||||
constexpr const char *INCIDENT_LOCATION_STR = "\n%s(%d) : failure location";
|
||||
constexpr const char *OTHER_LOCATION_STR = "\n%s(%d) : message location";
|
||||
#else
|
||||
#define FAILURE_LOCATION_STR "\n Loc: [%s(%d)]"
|
||||
constexpr const char *INCIDENT_LOCATION_STR = "\n Loc: [%s(%d)]";
|
||||
constexpr const char *OTHER_LOCATION_STR = INCIDENT_LOCATION_STR;
|
||||
#endif
|
||||
QTest::qt_asprintf(&failureLocation, FAILURE_LOCATION_STR, file, line);
|
||||
|
||||
if (file) {
|
||||
switch (source) {
|
||||
case MessageSource::Incident:
|
||||
QTest::qt_asprintf(&failureLocation, INCIDENT_LOCATION_STR, file, line);
|
||||
break;
|
||||
case MessageSource::Other:
|
||||
QTest::qt_asprintf(&failureLocation, OTHER_LOCATION_STR, file, line);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char *msgFiller = msg[0] ? " " : "";
|
||||
@ -362,7 +373,7 @@ void QPlainTestLogger::stopLogging()
|
||||
void QPlainTestLogger::enterTestFunction(const char * /*function*/)
|
||||
{
|
||||
if (QTestLog::verboseLevel() >= 1)
|
||||
printMessage(QTest::messageType2String(Info), "entering");
|
||||
printMessage(MessageSource::Other, QTest::messageType2String(Info), "entering");
|
||||
}
|
||||
|
||||
void QPlainTestLogger::leaveTestFunction()
|
||||
@ -377,7 +388,7 @@ void QPlainTestLogger::addIncident(IncidentTypes type, const char *description,
|
||||
&& QTestLog::verboseLevel() < 0)
|
||||
return;
|
||||
|
||||
printMessage(QTest::incidentType2String(type), description, file, line);
|
||||
printMessage(MessageSource::Incident, QTest::incidentType2String(type), description, file, line);
|
||||
}
|
||||
|
||||
void QPlainTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
|
||||
@ -401,7 +412,7 @@ void QPlainTestLogger::addMessage(MessageTypes type, const QString &message,
|
||||
if (type != QFatal && QTestLog::verboseLevel() < 0)
|
||||
return;
|
||||
|
||||
printMessage(QTest::messageType2String(type), qPrintable(message), file, line);
|
||||
printMessage(MessageSource::Other, QTest::messageType2String(type), qPrintable(message), file, line);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -78,7 +78,12 @@ public:
|
||||
const char *file = nullptr, int line = 0) override;
|
||||
|
||||
private:
|
||||
void printMessage(const char *type, const char *msg, const char *file = nullptr, int line = 0);
|
||||
enum class MessageSource {
|
||||
Incident,
|
||||
Other,
|
||||
};
|
||||
void printMessage(MessageSource source, const char *type, const char *msg,
|
||||
const char *file = nullptr, int line = 0);
|
||||
void outputMessage(const char *str);
|
||||
void printBenchmarkResult(const QBenchmarkResult &result);
|
||||
};
|
||||
|
@ -220,6 +220,8 @@ bool compareOutput(const QString &logger, const QString &subdir,
|
||||
continue;
|
||||
if (actualLineBA.endsWith(" : failure location"))
|
||||
continue;
|
||||
if (actualLineBA.endsWith(" : message location"))
|
||||
continue;
|
||||
|
||||
if (actualLineBA.startsWith("Config: Using QtTest library") // Text build string
|
||||
|| actualLineBA.startsWith(" <QtBuild") // XML, Light XML build string
|
||||
|
Loading…
x
Reference in New Issue
Block a user