mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
fix edge case with config files pointer (#1199)
generating a seg fault if no default and no config file provided. Fixes #1197 This was likely introduced by the combination of fixes for some issues with the config parsing and some updates to the as<T> method a while back. This edge case on the handling of the config pointer with as was not overlooked in the earlier testing. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -4208,3 +4208,24 @@ TEST_CASE_METHOD(TApp, "RoundTripArrayFloat", "[config]") {
|
||||
CHECK(cv[0] == -1.0F);
|
||||
CHECK(cv[1] == 1.0F);
|
||||
}
|
||||
|
||||
// Code from https://github.com/CLIUtils/CLI11/issues/1197
|
||||
TEST_CASE_METHOD(TApp, "CrashTest", "[config]") {
|
||||
args = {"spdlog", "--level=off"};
|
||||
|
||||
app.configurable()->allow_config_extras(false);
|
||||
app.set_config("--conf")->check(CLI::ExistingFile);
|
||||
|
||||
std::string level;
|
||||
|
||||
auto *command = app.add_subcommand("spdlog");
|
||||
command->add_option("--level", level, "Log level")->default_val("info");
|
||||
|
||||
run();
|
||||
|
||||
auto *ptr = app.get_config_ptr();
|
||||
std::string conf_filename;
|
||||
CHECK_NOTHROW(conf_filename = ptr->as<std::string>());
|
||||
CHECK(conf_filename.empty());
|
||||
CHECK(level == "off");
|
||||
}
|
||||
|
||||
@@ -1516,6 +1516,14 @@ TEST_CASE("Types: LexicalConversionVectorDouble", "[helpers]") {
|
||||
CHECK(-3.54 == Approx(x[2]));
|
||||
}
|
||||
|
||||
TEST_CASE("Types: LexicalConversionEmptyVectorDouble", "[helpers]") {
|
||||
CLI::results_t input = {};
|
||||
std::vector<double> x;
|
||||
bool res = CLI::detail::lexical_conversion<std::vector<double>, std::vector<double>>(input, x);
|
||||
CHECK(res);
|
||||
CHECK(x.empty());
|
||||
}
|
||||
|
||||
static_assert(!CLI::detail::is_tuple_like<std::vector<double>>::value, "vector should not be like a tuple");
|
||||
static_assert(CLI::detail::is_tuple_like<std::pair<double, double>>::value, "pair of double should be like a tuple");
|
||||
static_assert(CLI::detail::is_tuple_like<std::array<double, 4>>::value, "std::array<double,4> should be like a tuple");
|
||||
|
||||
Reference in New Issue
Block a user