Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xs-test
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patrick Chen
xs-test
Commits
59377c67
Commit
59377c67
authored
Aug 29, 2018
by
Patrick Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow run command without expectation
parent
a587a988
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
10 deletions
+21
-10
imx6-gui.json
example/imx6-gui.json
+0
-3
Expectation.h
include/test/Expectation.h
+2
-1
Expectation.cc
src/test/Expectation.cc
+9
-1
Tester.cc
src/test/Tester.cc
+10
-5
No files found.
example/imx6-gui.json
View file @
59377c67
...
...
@@ -16,9 +16,6 @@
"param"
:
{
"uuid"
:
"A667E644-7F1B-4F8C-A939-24C596E4847C"
,
"active"
:
true
},
"expect"
:
{
"response"
:
{}
}
},
{
...
...
include/test/Expectation.h
View file @
59377c67
#ifndef XS_TEST_EXPECTATION_H_INCLUDED
#define XS_TEST_EXPECTATION_H_INCLUDED
#include <boost/optional.hpp>
#include <nlohmann/json.hpp>
#include <string>
...
...
@@ -26,7 +27,7 @@ namespace xs { namespace test
public
:
std
::
string
name_
;
nlohmann
::
json
request_
;
nlohmann
::
json
response_
;
boost
::
optional
<
nlohmann
::
json
>
response_
;
std
::
unordered_set
<
std
::
string
>
runs_
;
std
::
unordered_set
<
std
::
string
>
posts_
;
};
...
...
src/test/Expectation.cc
View file @
59377c67
...
...
@@ -11,6 +11,10 @@ namespace xs { namespace test
{
request_
=
object
[
"param"
];
if
(
!
object
.
count
(
"expect"
))
{
return
;
}
const
auto
&
expect
=
object
[
"expect"
];
response_
=
expect
[
"response"
];
...
...
@@ -51,7 +55,11 @@ namespace xs { namespace test
return
false
;
}
if
(
!
(
object
.
count
(
"expect"
)
&&
object
[
"expect"
].
is_object
()))
{
if
(
!
object
.
count
(
"expect"
))
{
return
true
;
}
if
(
!
object
[
"expect"
].
is_object
())
{
return
false
;
}
...
...
src/test/Tester.cc
View file @
59377c67
...
...
@@ -56,12 +56,17 @@ void Tester::resetCounters() noexcept
Tester
::
Report
Tester
::
createReport
(
const
std
::
string
&
response
,
const
Expectation
&
expectation
)
noexcept
{
Report
report
;
if
(
expectation
.
response_
.
is_string
())
{
report
.
pass
=
(
response
==
expectation
.
response_
.
get
<
std
::
string
>
());
Report
report
{
true
};
// execute withou expected response
if
(
!
expectation
.
response_
)
{
return
report
;
}
if
(
expectation
.
response_
->
is_string
())
{
report
.
pass
=
(
response
==
expectation
.
response_
->
get
<
std
::
string
>
());
}
else
{
try
{
report
.
pass
=
(
nlohmann
::
json
::
parse
(
response
)
==
expectation
.
response_
);
report
.
pass
=
(
nlohmann
::
json
::
parse
(
response
)
==
*
expectation
.
response_
);
}
catch
(...)
{
}
...
...
@@ -150,7 +155,7 @@ void Tester::run() noexcept
std
::
cout
<<
"[FAILED] run command: "
<<
expectation
.
name_
<<
std
::
endl
;
if
(
report
.
missedCommands
.
empty
()
&&
report
.
missedEvents
.
empty
())
{
std
::
cout
<<
boost
::
format
(
R"([REASON] unexpected response: "%1%"(real) vs %2%(expect))"
)
%
response
%
detail
::
toString
(
expectation
.
response_
)
%
response
%
detail
::
toString
(
*
expectation
.
response_
)
<<
std
::
endl
;
}
else
if
(
!
report
.
missedCommands
.
empty
())
{
std
::
cout
<<
boost
::
format
(
"[REASON] missed commands: [%1%]"
)
...
...
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