Commit 0f9b3685 authored by Dominik Charousset's avatar Dominik Charousset

Restore ref-syncing for config file input

parent 4f8609bd
...@@ -19,6 +19,10 @@ is based on [Keep a Changelog](https://keepachangelog.com). ...@@ -19,6 +19,10 @@ is based on [Keep a Changelog](https://keepachangelog.com).
### Fixed ### Fixed
- Setting an invalid credit policy no longer results in a segfault (#1140). - Setting an invalid credit policy no longer results in a segfault (#1140).
- RC 1 of version 0.18 introduced a regression that prevented CAF from writing
parameters parsed from configuration files back to variables. The original
behavior has been restored, i.e., variables synchronize with user input from
configuration files and CLI arguments (#1145).
## [0.18.0-rc.1] - 2020-09-09 ## [0.18.0-rc.1] - 2020-09-09
......
...@@ -129,7 +129,7 @@ void config_consumer::end_map() { ...@@ -129,7 +129,7 @@ void config_consumer::end_map() {
} }
std::string config_consumer::qualified_key() { std::string config_consumer::qualified_key() {
if (category_.empty()) if (category_.empty() || category_ == "global")
return current_key_; return current_key_;
auto result = category_; auto result = category_;
result += '.'; result += '.';
......
...@@ -118,6 +118,44 @@ CAF_TEST(parsing - with CLI cfg.remainder) { ...@@ -118,6 +118,44 @@ CAF_TEST(parsing - with CLI cfg.remainder) {
CAF_MESSAGE("invalid cfg.remainder"); CAF_MESSAGE("invalid cfg.remainder");
} }
CAF_TEST(file input overrides defaults but CLI args always win) {
const char* file_input = R"__(
group1 {
arg1 = 'foobar'
}
group2 {
arg1 = 'hello world'
arg2 = 2
}
)__";
struct grp {
std::string arg1 = "default";
int arg2 = 42;
};
grp grp1;
grp grp2;
config_option_adder{cfg.custom_options(), "group1"}
.add(grp1.arg1, "arg1", "")
.add(grp1.arg2, "arg2", "");
config_option_adder{cfg.custom_options(), "group2"}
.add(grp2.arg1, "arg1", "")
.add(grp2.arg2, "arg2", "");
string_list args{"--group1.arg2=123", "--group2.arg1=bye"};
std::istringstream input{file_input};
auto err = cfg.parse(std::move(args), input);
CAF_CHECK_EQUAL(err, error{});
CAF_CHECK_EQUAL(grp1.arg1, "foobar");
CAF_CHECK_EQUAL(grp1.arg2, 123);
CAF_CHECK_EQUAL(grp2.arg1, "bye");
CAF_CHECK_EQUAL(grp2.arg2, 2);
settings res;
put(res, "group1.arg1", "foobar");
put(res, "group1.arg2", 123);
put(res, "group2.arg1", "bye");
put(res, "group2.arg2", 2);
CAF_CHECK_EQUAL(content(cfg), res);
}
// Checks whether both a synced variable and the corresponding entry in // Checks whether both a synced variable and the corresponding entry in
// content(cfg) are equal to `value`. // content(cfg) are equal to `value`.
#define CHECK_SYNCED(var, value) \ #define CHECK_SYNCED(var, value) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment