Skip to content

Commit

Permalink
add config test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
phlptp committed Sep 21, 2024
1 parent 380429d commit 2be38c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
10 changes: 1 addition & 9 deletions include/CLI/impl/Config_inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,7 @@ ConfigBase::to_config(const App *app, bool default_also, bool write_description,

std::string value = detail::ini_join(
opt->reduced_results(), arraySeparator, arrayStart, arrayEnd, stringQuote, literalQuote);
/*if (value == "\"{}\"" || value == "\"[]\"") {
if(opt->get_expected_min() == 0) {
value.push_back(arraySeparator);
value.append("\"\"");
value.push_back(arrayEnd);
value.insert(value.begin(), arrayStart);
}
}
*/

if(value.empty() && default_also) {
if(!opt->get_default_str().empty()) {
value = detail::convert_arg_for_ini(opt->get_default_str(), stringQuote, literalQuote, false);
Expand Down
21 changes: 21 additions & 0 deletions tests/ConfigFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,27 @@ TEST_CASE_METHOD(TApp, "IniVector", "[config]") {
CHECK(two == std::vector<int>({2, 3}));
CHECK(three == std::vector<int>({1, 2, 3}));
}

TEST_CASE_METHOD(TApp, "IniFlagOverride", "[config]") {

TempFile tmpini{ "TestIniTmp.ini" };

app.set_config("--config", tmpini);

{
std::ofstream out{tmpini};
out << "[default]" << '\n';
out << "three=0" << '\n';
}

int flag{45};
app.add_flag("--two{2},--three{3},--four{4}", flag)->disable_flag_override()->force_callback()->default_str("0");

run();

CHECK(flag==0);
}

TEST_CASE_METHOD(TApp, "TOMLVector", "[config]") {

TempFile tmptoml{"TestTomlTmp.toml"};
Expand Down

0 comments on commit 2be38c5

Please sign in to comment.