From 2be38c5f9c90cd006ec3ca6cef1119bbaf43e0ec Mon Sep 17 00:00:00 2001 From: Philip Top Date: Sat, 21 Sep 2024 05:26:12 -0700 Subject: [PATCH] add config test for coverage --- include/CLI/impl/Config_inl.hpp | 10 +--------- tests/ConfigFileTest.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/CLI/impl/Config_inl.hpp b/include/CLI/impl/Config_inl.hpp index e81167913..34aeb1929 100644 --- a/include/CLI/impl/Config_inl.hpp +++ b/include/CLI/impl/Config_inl.hpp @@ -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); diff --git a/tests/ConfigFileTest.cpp b/tests/ConfigFileTest.cpp index 525b28be3..ead15992a 100644 --- a/tests/ConfigFileTest.cpp +++ b/tests/ConfigFileTest.cpp @@ -1458,6 +1458,27 @@ TEST_CASE_METHOD(TApp, "IniVector", "[config]") { CHECK(two == std::vector({2, 3})); CHECK(three == std::vector({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"};