Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libraries
KPublicTransport
Commits
9dca7e55
Commit
9dca7e55
authored
Oct 06, 2021
by
Volker Krause
Browse files
Improve diagnostics in case of an OTP journey parser test failure
parent
4eb10601
Changes
1
Hide whitespace changes
Inline
Side-by-side
autotests/otpparsertest.cpp
View file @
9dca7e55
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment