Commit 9dca7e55 authored by Volker Krause's avatar Volker Krause
Browse files

Improve diagnostics in case of an OTP journey parser test failure

parent 4eb10601
......@@ -16,6 +16,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QProcess>
#include <QTest>
#include <QTimeZone>
......@@ -31,11 +32,30 @@ class OtpParserTest : public QObject
private:
QByteArray readFile(const QString &fn)
{
if (fn.isEmpty()) {
return {};
}
QFile f(fn);
f.open(QFile::ReadOnly);
return f.readAll();
}
template <typename T>
inline void diffJson(const QString &refFile, const T &output, const T &ref)
{
if (output != ref) {
QFile failFile(refFile + QLatin1String(".fail"));
QVERIFY(failFile.open(QFile::WriteOnly));
failFile.write(QJsonDocument(output).toJson());
failFile.close();
QProcess proc;
proc.setProcessChannelMode(QProcess::ForwardedChannels);
proc.start(QStringLiteral("diff"), {QStringLiteral("-u"), refFile, failFile.fileName()});
QVERIFY(proc.waitForFinished());
}
}
private Q_SLOTS:
void initTestCase()
{
......@@ -193,9 +213,7 @@ private Q_SLOTS:
const auto ref = QJsonDocument::fromJson(readFile(refFileName)).array();
if (jsonRes != ref) {
qDebug().noquote() << QJsonDocument(jsonRes).toJson();
}
diffJson(refFileName, jsonRes, ref);
QVERIFY(!jsonRes.empty());
QCOMPARE(jsonRes, ref);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment