This PR adds a missing check in the API for getOptionInfo().
CVC5_API_TRY_CATCH_BEGIN;
//////// all checks before this line
auto info = options::getInfo(d_smtEngine->getOptions(), option);
+ CVC5_API_CHECK(info.name != "")
+ << "Querying invalid or unknown option " << option;
return std::visit(
overloaded{
[&info](const options::OptionInfo::VoidInfo& vi) {
['name == "{}"'.format(x) for x in sorted(names)])
# Generate code for getOptionInfo
+ if option.alias:
+ alias = ', '.join(map(lambda s: '"{}"'.format(s), option.alias))
+ else:
+ alias = ''
if option.name:
constr = None
fmt = {
constr = 'OptionInfo::ModeInfo{{"{default}", {value}, {{ {modes} }}}}'.format(**fmt, modes=values)
else:
constr = 'OptionInfo::VoidInfo{}'
- if option.alias:
- alias = ', '.join(map(lambda s: '"{}"'.format(s), option.alias))
- else:
- alias = ''
options_get_info.append('if ({}) return OptionInfo{{"{}", {{{alias}}}, opts.{}.{}WasSetByUser, {}}};'.format(cond, long_get_option(option.long), module.id, option.name, constr, alias=alias))
+ else:
+ options_get_info.append('if ({}) return OptionInfo{{"{}", {{{alias}}}, false, OptionInfo::VoidInfo{{}}}};'.format(cond, long_get_option(option.long), alias=alias))
if setoption_handlers:
setoption_handlers.append(' }} else if ({}) {{'.format(cond))
// clang-format off
${options_get_info}$
// clang-format on
- return OptionInfo{name, {}, false, OptionInfo::VoidInfo{}};
+ return OptionInfo{"", {}, false, OptionInfo::VoidInfo{}};
}
#undef DO_SEMANTIC_CHECKS_BY_DEFAULT
TEST_F(TestApiBlackSolver, getOptionInfo)
{
{
- auto info = d_solver.getOptionInfo("verbose");
- ASSERT_EQ(info.name, "verbose");
- ASSERT_EQ(info.aliases, std::vector<std::string>{});
- ASSERT_TRUE(std::holds_alternative<api::OptionInfo::VoidInfo>(info.valueInfo));
+ EXPECT_THROW(d_solver.getOptionInfo("asdf-invalid"), CVC5ApiException);
+ }
+ {
+ api::OptionInfo info = d_solver.getOptionInfo("verbose");
+ EXPECT_EQ("verbose", info.name);
+ EXPECT_EQ(std::vector<std::string>{}, info.aliases);
+ EXPECT_TRUE(std::holds_alternative<OptionInfo::VoidInfo>(info.valueInfo));
}
{
// int64 type with default