Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KItinerary
Commits
2b3a9ce7
Commit
2b3a9ce7
authored
Sep 24, 2022
by
Volker Krause
Browse files
Factor out JSON diff test helper and make it show something on Windows
parent
3410116a
Pipeline
#236346
passed with stage
in 4 minutes and 58 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
autotests/extractorscriptenginetest.cpp
View file @
2b3a9ce7
...
...
@@ -5,6 +5,7 @@
*/
#include
"config-kitinerary.h"
#include
"testhelpers.h"
#include
<KItinerary/ExtractorDocumentNode>
#include
<KItinerary/ExtractorDocumentNodeFactory>
...
...
@@ -16,7 +17,6 @@
#include
<QDebug>
#include
<QFile>
#include
<QJsonDocument>
#include
<QProcess>
#include
<QTest>
using
namespace
KItinerary
;
...
...
@@ -87,19 +87,7 @@ private Q_SLOTS:
QFile
ref
(
refFile
);
QVERIFY
(
ref
.
open
(
QFile
::
ReadOnly
));
const
auto
refResult
=
QJsonDocument
::
fromJson
(
ref
.
readAll
()).
array
();
if
(
result
!=
refResult
)
{
QFile
failFile
(
refFile
+
QLatin1String
(
".fail"
));
QVERIFY
(
failFile
.
open
(
QFile
::
WriteOnly
));
failFile
.
write
(
QJsonDocument
(
result
).
toJson
());
failFile
.
close
();
QProcess
proc
;
proc
.
setProcessChannelMode
(
QProcess
::
ForwardedChannels
);
proc
.
start
(
QStringLiteral
(
"diff"
),
{
QStringLiteral
(
"-u"
),
refFile
,
failFile
.
fileName
()});
QVERIFY
(
proc
.
waitForFinished
());
}
QCOMPARE
(
result
,
refResult
);
QVERIFY
(
Test
::
compareJson
(
refFile
,
result
,
refResult
));
}
void
testInfiniteLoop
()
...
...
autotests/extractortest.cpp
View file @
2b3a9ce7
...
...
@@ -6,6 +6,8 @@
#include
<config-kitinerary.h>
#include
"testhelpers.h"
#include
<KItinerary/ExtractorEngine>
#include
<KItinerary/ExtractorPostprocessor>
#include
<KItinerary/ExtractorValidator>
...
...
@@ -20,7 +22,6 @@
#include
<QJsonArray>
#include
<QJsonDocument>
#include
<QObject>
#include
<QProcess>
#include
<QTest>
void
initLocale
()
...
...
@@ -154,19 +155,7 @@ private Q_SLOTS:
QFile
f
(
refFile
);
QVERIFY
(
f
.
open
(
QFile
::
ReadOnly
));
const
auto
refDoc
=
QJsonDocument
::
fromJson
(
f
.
readAll
());
if
(
refDoc
.
array
()
!=
encodedResult
)
{
QFile
failFile
(
refFile
+
QLatin1String
(
".fail"
));
QVERIFY
(
failFile
.
open
(
QFile
::
WriteOnly
));
failFile
.
write
(
QJsonDocument
(
encodedResult
).
toJson
());
failFile
.
close
();
QProcess
proc
;
proc
.
setProcessChannelMode
(
QProcess
::
ForwardedChannels
);
proc
.
start
(
QStringLiteral
(
"diff"
),
{
QStringLiteral
(
"-u"
),
refFile
,
failFile
.
fileName
()});
QVERIFY
(
proc
.
waitForFinished
());
}
QCOMPARE
(
refDoc
.
array
(),
encodedResult
);
QVERIFY
(
Test
::
compareJson
(
refFile
,
encodedResult
,
refDoc
.
array
()));
}
void
testNegative
()
...
...
autotests/testhelpers.h
0 → 100644
View file @
2b3a9ce7
/*
SPDX-FileCopyrightText: 2019-2022 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef TESTHELPERS_H
#define TESTHELPERS_H
#include
<QFile>
#include
<QJsonDocument>
#include
<QProcess>
#include
<QTest>
namespace
Test
{
template
<
typename
T
>
inline
bool
compareJson
(
const
QString
&
refFile
,
const
T
&
output
,
const
T
&
ref
)
{
if
(
output
!=
ref
)
{
#ifndef Q_OS_WIN
QFile
failFile
(
refFile
+
QLatin1String
(
".fail"
));
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
()});
proc
.
waitForFinished
();
#else
qDebug
().
noquote
()
<<
"Got:"
<<
QJsonDocument
(
output
).
toJson
();
qDebug
().
noquote
()
<<
"Expected:"
<<
QJsonDocument
(
ref
).
toJson
();
#endif
return
false
;
}
return
true
;
}
}
#endif
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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