Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
0bcf78f8
Commit
0bcf78f8
authored
Apr 29, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for reproducing #942
parent
cc7e8d5a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
0 deletions
+79
-0
libcaf_core/caf/config_option_set.hpp
libcaf_core/caf/config_option_set.hpp
+5
-0
libcaf_core/src/config_option_set.cpp
libcaf_core/src/config_option_set.cpp
+1
-0
libcaf_core/test/config_option_set.cpp
libcaf_core/test/config_option_set.cpp
+73
-0
No files found.
libcaf_core/caf/config_option_set.hpp
View file @
0bcf78f8
...
...
@@ -165,6 +165,11 @@ public:
/// Generates human-readable help text for all options.
std
::
string
help_text
(
bool
global_only
=
true
)
const
;
/// Drops all options.
void
clear
()
{
opts_
.
clear
();
}
// -- parsing ----------------------------------------------------------------
/// Parses a given range as CLI arguments into `config`.
...
...
libcaf_core/src/config_option_set.cpp
View file @
0bcf78f8
...
...
@@ -161,6 +161,7 @@ auto config_option_set::parse(settings& config, argument_iterator first,
return
static_cast
<
pec
>
(
err
.
code
());
return
pec
::
illegal_argument
;
}
opt
.
store
(
*
val
);
entry
[
opt_name
]
=
std
::
move
(
*
val
);
}
return
pec
::
success
;
...
...
libcaf_core/test/config_option_set.cpp
View file @
0bcf78f8
...
...
@@ -38,6 +38,14 @@ namespace {
struct
fixture
{
config_option_set
opts
;
template
<
class
T
>
error
read
(
settings
&
cfg
,
std
::
vector
<
std
::
string
>
args
)
{
auto
res
=
opts
.
parse
(
cfg
,
std
::
move
(
args
));
if
(
res
.
first
!=
pec
::
success
)
return
res
.
first
;
return
none
;
}
template
<
class
T
>
expected
<
T
>
read
(
std
::
vector
<
std
::
string
>
args
)
{
settings
cfg
;
...
...
@@ -160,4 +168,69 @@ CAF_TEST(flat CLI parsing with nested categories) {
CAF_CHECK_EQUAL
(
read
<
std
::
string
>
({
"--foo.goo.bar=foobar"
}),
"foobar"
);
}
CAF_TEST
(
square
brackets
are
optional
on
the
command
line
)
{
using
int_list
=
std
::
vector
<
int
>
;
opts
.
add
<
int_list
>
(
"global"
,
"bar,b"
,
"some list"
);
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=[1])"
}),
int_list
({
1
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=[1,])"
}),
int_list
({
1
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=[ 1 , ])"
}),
int_list
({
1
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=[1,2])"
}),
int_list
({
1
,
2
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=[1, 2, 3])"
}),
int_list
({
1
,
2
,
3
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=[1, 2, 3, ])"
}),
int_list
({
1
,
2
,
3
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=1)"
}),
int_list
({
1
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=1,2,3)"
}),
int_list
({
1
,
2
,
3
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
({
"--bar=1, 2 , 3 , )"
}),
int_list
({
1
,
2
,
3
}));
}
#define SUBTEST(msg) \
opts.clear(); \
if (true)
CAF_TEST
(
CLI
arguments
override
defaults
)
{
using
int_list
=
std
::
vector
<
int
>
;
using
string_list
=
std
::
vector
<
std
::
string
>
;
SUBTEST
(
"with ref syncing"
)
{
settings
cfg
;
int_list
ints
;
string_list
strings
;
CAF_MESSAGE
(
"add --foo and --bar options"
);
opts
.
add
(
strings
,
"global"
,
"foo,f"
,
"some list"
);
opts
.
add
(
ints
,
"global"
,
"bar,b"
,
"some list"
);
CAF_MESSAGE
(
"test integer lists"
);
ints
=
int_list
{
1
,
2
,
3
};
cfg
[
"bar"
]
=
config_value
{
ints
};
CAF_CHECK_EQUAL
(
get
<
int_list
>
(
cfg
,
"bar"
),
int_list
({
1
,
2
,
3
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
(
cfg
,
{
"--bar=[10, 20, 30])"
}),
none
);
CAF_CHECK_EQUAL
(
ints
,
int_list
({
10
,
20
,
30
}));
CAF_CHECK_EQUAL
(
get
<
int_list
>
(
cfg
,
"bar"
),
int_list
({
10
,
20
,
30
}));
CAF_MESSAGE
(
"test string lists"
);
strings
=
string_list
{
"one"
,
"two"
,
"three"
};
cfg
[
"foo"
]
=
config_value
{
strings
};
CAF_CHECK_EQUAL
(
get
<
string_list
>
(
cfg
,
"foo"
),
string_list
({
"one"
,
"two"
,
"three"
}));
CAF_CHECK_EQUAL
(
read
<
string_list
>
(
cfg
,
{
"--foo=[hello, world])"
}),
none
);
CAF_CHECK_EQUAL
(
strings
,
string_list
({
"hello"
,
"world"
}));
CAF_CHECK_EQUAL
(
get
<
string_list
>
(
cfg
,
"foo"
),
string_list
({
"hello"
,
"world"
}));
}
SUBTEST
(
"without ref syncing"
)
{
settings
cfg
;
CAF_MESSAGE
(
"add --foo and --bar options"
);
opts
.
add
<
string_list
>
(
"global"
,
"foo,f"
,
"some list"
);
opts
.
add
<
int_list
>
(
"global"
,
"bar,b"
,
"some list"
);
CAF_MESSAGE
(
"test integer lists"
);
cfg
[
"bar"
]
=
config_value
{
int_list
{
1
,
2
,
3
}};
CAF_CHECK_EQUAL
(
get
<
int_list
>
(
cfg
,
"bar"
),
int_list
({
1
,
2
,
3
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
(
cfg
,
{
"--bar=[10, 20, 30])"
}),
none
);
CAF_CHECK_EQUAL
(
get
<
int_list
>
(
cfg
,
"bar"
),
int_list
({
10
,
20
,
30
}));
CAF_MESSAGE
(
"test string lists"
);
cfg
[
"foo"
]
=
config_value
{
string_list
{
"one"
,
"two"
,
"three"
}};
CAF_CHECK_EQUAL
(
get
<
string_list
>
(
cfg
,
"foo"
),
string_list
({
"one"
,
"two"
,
"three"
}));
CAF_CHECK_EQUAL
(
read
<
string_list
>
(
cfg
,
{
"--foo=[hello, world])"
}),
none
);
CAF_CHECK_EQUAL
(
get
<
string_list
>
(
cfg
,
"foo"
),
string_list
({
"hello"
,
"world"
}));
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
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