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
Show 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 @@
...
@@ -16,9 +16,6 @@
"param"
:
{
"param"
:
{
"uuid"
:
"A667E644-7F1B-4F8C-A939-24C596E4847C"
,
"uuid"
:
"A667E644-7F1B-4F8C-A939-24C596E4847C"
,
"active"
:
true
"active"
:
true
},
"expect"
:
{
"response"
:
{}
}
}
},
},
{
{
...
...
include/test/Expectation.h
View file @
59377c67
#ifndef XS_TEST_EXPECTATION_H_INCLUDED
#ifndef XS_TEST_EXPECTATION_H_INCLUDED
#define XS_TEST_EXPECTATION_H_INCLUDED
#define XS_TEST_EXPECTATION_H_INCLUDED
#include <boost/optional.hpp>
#include <nlohmann/json.hpp>
#include <nlohmann/json.hpp>
#include <string>
#include <string>
...
@@ -26,7 +27,7 @@ namespace xs { namespace test
...
@@ -26,7 +27,7 @@ namespace xs { namespace test
public
:
public
:
std
::
string
name_
;
std
::
string
name_
;
nlohmann
::
json
request_
;
nlohmann
::
json
request_
;
nlohmann
::
json
response_
;
boost
::
optional
<
nlohmann
::
json
>
response_
;
std
::
unordered_set
<
std
::
string
>
runs_
;
std
::
unordered_set
<
std
::
string
>
runs_
;
std
::
unordered_set
<
std
::
string
>
posts_
;
std
::
unordered_set
<
std
::
string
>
posts_
;
};
};
...
...
src/test/Expectation.cc
View file @
59377c67
...
@@ -11,6 +11,10 @@ namespace xs { namespace test
...
@@ -11,6 +11,10 @@ namespace xs { namespace test
{
{
request_
=
object
[
"param"
];
request_
=
object
[
"param"
];
if
(
!
object
.
count
(
"expect"
))
{
return
;
}
const
auto
&
expect
=
object
[
"expect"
];
const
auto
&
expect
=
object
[
"expect"
];
response_
=
expect
[
"response"
];
response_
=
expect
[
"response"
];
...
@@ -51,7 +55,11 @@ namespace xs { namespace test
...
@@ -51,7 +55,11 @@ namespace xs { namespace test
return
false
;
return
false
;
}
}
if
(
!
(
object
.
count
(
"expect"
)
&&
object
[
"expect"
].
is_object
()))
{
if
(
!
object
.
count
(
"expect"
))
{
return
true
;
}
if
(
!
object
[
"expect"
].
is_object
())
{
return
false
;
return
false
;
}
}
...
...
src/test/Tester.cc
View file @
59377c67
...
@@ -56,12 +56,17 @@ void Tester::resetCounters() noexcept
...
@@ -56,12 +56,17 @@ void Tester::resetCounters() noexcept
Tester
::
Report
Tester
::
createReport
(
const
std
::
string
&
response
,
const
Expectation
&
expectation
)
noexcept
Tester
::
Report
Tester
::
createReport
(
const
std
::
string
&
response
,
const
Expectation
&
expectation
)
noexcept
{
{
Report
report
;
Report
report
{
true
};
if
(
expectation
.
response_
.
is_string
())
{
// execute withou expected response
report
.
pass
=
(
response
==
expectation
.
response_
.
get
<
std
::
string
>
());
if
(
!
expectation
.
response_
)
{
return
report
;
}
if
(
expectation
.
response_
->
is_string
())
{
report
.
pass
=
(
response
==
expectation
.
response_
->
get
<
std
::
string
>
());
}
else
{
}
else
{
try
{
try
{
report
.
pass
=
(
nlohmann
::
json
::
parse
(
response
)
==
expectation
.
response_
);
report
.
pass
=
(
nlohmann
::
json
::
parse
(
response
)
==
*
expectation
.
response_
);
}
catch
(...)
{
}
catch
(...)
{
}
}
...
@@ -150,7 +155,7 @@ void Tester::run() noexcept
...
@@ -150,7 +155,7 @@ void Tester::run() noexcept
std
::
cout
<<
"[FAILED] run command: "
<<
expectation
.
name_
<<
std
::
endl
;
std
::
cout
<<
"[FAILED] run command: "
<<
expectation
.
name_
<<
std
::
endl
;
if
(
report
.
missedCommands
.
empty
()
&&
report
.
missedEvents
.
empty
())
{
if
(
report
.
missedCommands
.
empty
()
&&
report
.
missedEvents
.
empty
())
{
std
::
cout
<<
boost
::
format
(
R"([REASON] unexpected response: "%1%"(real) vs %2%(expect))"
)
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
;
<<
std
::
endl
;
}
else
if
(
!
report
.
missedCommands
.
empty
())
{
}
else
if
(
!
report
.
missedCommands
.
empty
())
{
std
::
cout
<<
boost
::
format
(
"[REASON] missed commands: [%1%]"
)
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