summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-02-14 14:49:02 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-25 20:56:32 +0100
commit356838cd7d4dc9732d97aa56e0656f46826b0ade (patch)
treecf32962442ea2a2571df3fa6ac4e354658c344cb /tests
parentf6d8afd26dfd59377fce1de1e488ae121bf47345 (diff)
Improve error reporting in selftests of testlib.
Output the file name and fix line number to be 1..n. Change-Id: I3ba7f84b99ce3664bc3e403b230307511b15fe1f Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/testlib/selftests/tst_selftests.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp
index 8167a96eaa..b9601b409e 100644
--- a/tests/auto/testlib/selftests/tst_selftests.cpp
+++ b/tests/auto/testlib/selftests/tst_selftests.cpp
@@ -169,12 +169,17 @@ QString tst_Selftests::logName(const QString &logger) const
return (logger.startsWith("stdout") ? "" : QString(tempDir.path() + "/test_output." + logger));
}
+static QString expectedFileNameFromTest(const QString &subdir, const QString &logger)
+{
+ return QStringLiteral("expected_") + subdir + QLatin1Char('.') + logFormat(logger);
+}
+
// Load the expected test output for the nominated test (subdir) and logger
// as an array of lines. If there is no expected output file, return an
// empty array.
-static QList<QByteArray> expectedResult(const QString &subdir, const QString &logger)
+static QList<QByteArray> expectedResult(const QString &fileName)
{
- QFile file(":/expected_" + subdir + "." + logFormat(logger));
+ QFile file(QStringLiteral(":/") + fileName);
if (!file.open(QIODevice::ReadOnly))
return QList<QByteArray>();
return splitLines(file.readAll());
@@ -619,7 +624,8 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge
for (int n = 0; n < loggers.count(); ++n) {
QString logger = loggers[n];
QList<QByteArray> res = splitLines(actualOutputs[n]);
- QList<QByteArray> exp = expectedResult(subdir, logger);
+ const QString expectedFileName = expectedFileNameFromTest(subdir, logger);
+ QList<QByteArray> exp = expectedResult(expectedFileName);
#if defined (Q_CC_MSVC) || defined(Q_CC_MINGW)
// MSVC, MinGW format double numbers differently
if (n == 0 && subdir == QStringLiteral("float")) {
@@ -638,7 +644,7 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge
QList<QByteArray> tmp;
int i = 1;
do {
- tmp = expectedResult(subdir + QString("_%1").arg(i++), logger);
+ tmp = expectedResult(expectedFileNameFromTest(subdir + QLatin1Char('_') + QString::number(i++), logger));
if (tmp.count())
expArr += tmp;
} while (tmp.count());
@@ -667,8 +673,8 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge
qDebug() << ">>>>>>";
QVERIFY2(res.count() == exp.count(),
- qPrintable(QString::fromLatin1("Mismatch in line count: %1 != %2 (%3).")
- .arg(res.count()).arg(exp.count()).arg(loggers.at(n))));
+ qPrintable(QString::fromLatin1("Mismatch in line count: %1 != %2 (%3, %4).")
+ .arg(res.count()).arg(exp.count()).arg(loggers.at(n), expectedFileName)));
}
}
@@ -740,8 +746,8 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge
.arg(i).arg(loggers.at(n), output)));
} else {
QVERIFY2(output == expected,
- qPrintable(QString::fromLatin1("Mismatch at line %1 (%2): '%3' != '%4'")
- .arg(i).arg(loggers.at(n), output, expected)));
+ qPrintable(QString::fromLatin1("Mismatch at line %1 (%2, %3): '%4' != '%5'")
+ .arg(i + 1).arg(loggers.at(n), expectedFileName, output, expected)));
}
benchmark = line.startsWith("RESULT : ");