Commit f583e5baf645b8f1d9abd6ed1ca13c76c780bb2a
Committed by
GitHub
1 parent
821940c3
Fix #298, resetting config option (#301)
Showing
2 changed files
with
25 additions
and
1 deletions
include/CLI/App.hpp
| ... | ... | @@ -999,8 +999,11 @@ class App { |
| 999 | 999 | bool config_required = false) { |
| 1000 | 1000 | |
| 1001 | 1001 | // Remove existing config if present |
| 1002 | - if(config_ptr_ != nullptr) | |
| 1002 | + if(config_ptr_ != nullptr) { | |
| 1003 | 1003 | remove_option(config_ptr_); |
| 1004 | + config_name_ = ""; | |
| 1005 | + config_required_ = false; // Not really needed, but complete | |
| 1006 | + } | |
| 1004 | 1007 | |
| 1005 | 1008 | // Only add config if option passed |
| 1006 | 1009 | if(!option_name.empty()) { | ... | ... |
tests/IniTest.cpp
| ... | ... | @@ -889,3 +889,24 @@ TEST_F(TApp, DefaultsIniQuotedOutput) { |
| 889 | 889 | EXPECT_THAT(str, HasSubstr("val1=\"I am a string\"")); |
| 890 | 890 | EXPECT_THAT(str, HasSubstr("val2='I am a \"confusing\" string'")); |
| 891 | 891 | } |
| 892 | + | |
| 893 | +// #298 | |
| 894 | +TEST_F(TApp, StopReadingConfigOnClear) { | |
| 895 | + | |
| 896 | + TempFile tmpini{"TestIniTmp.ini"}; | |
| 897 | + | |
| 898 | + app.set_config("--config", tmpini); | |
| 899 | + app.set_config(); // Should *not* read config file | |
| 900 | + | |
| 901 | + { | |
| 902 | + std::ofstream out{tmpini}; | |
| 903 | + out << "volume=1" << std::endl; | |
| 904 | + } | |
| 905 | + | |
| 906 | + int volume = 0; | |
| 907 | + app.add_option("--volume", volume, "volume1"); | |
| 908 | + | |
| 909 | + run(); | |
| 910 | + | |
| 911 | + EXPECT_EQ(volume, 0); | |
| 912 | +} | ... | ... |