add option modifiers pathways to custom options in the fuzzer (#1128)

Next phase of the fuzzer, adds some mechanics for the fuzzer itself to
add modifiers on the options.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Philip Top
2025-03-03 04:54:46 -08:00
committed by GitHub
parent 4160d259d9
commit 0eb88ed958
10 changed files with 185 additions and 10 deletions

View File

@@ -248,6 +248,7 @@ TEST_CASE("app_roundtrip_single") {
CHECK(result);
}
/** test the fuzzer itself to support custom options*/
TEST_CASE("fuzz_config_test1") {
CLI::FuzzApp fuzzdata;
auto app = fuzzdata.generateApp();
@@ -261,6 +262,50 @@ TEST_CASE("fuzz_config_test1") {
CHECK(app->get_option_no_throw("--new_vector") != nullptr);
}
/** test the fuzzer itself to support custom options*/
TEST_CASE("fuzz_config_test2") {
CLI::FuzzApp fuzzdata;
auto app = fuzzdata.generateApp();
std::string config_string =
"<option>--new_option</option><flag>--new_flag</flag><vector>--new_vector</vector> --new_flag --new_option 10";
auto loc = fuzzdata.add_custom_options(app.get(), config_string);
config_string = config_string.substr(loc);
CHECK(!config_string.empty());
CHECK(config_string == " --new_flag --new_option 10");
CHECK(app->get_option_no_throw("--new_option") != nullptr);
CHECK(app->get_option_no_throw("--new_flag") != nullptr);
CHECK(app->get_option_no_throw("--new_vector") != nullptr);
}
/** test the fuzzer itself to support custom option modifiers*/
TEST_CASE("fuzz_config_modifier_test1") {
CLI::FuzzApp fuzzdata;
auto app = fuzzdata.generateApp();
std::string config_string = "<option modifiers=R2CG>--new_option</option><flag "
"modifiers=cFg>--new_flag</flag><vector modifiers=35s+>--new_vector</vector>";
auto loc = fuzzdata.add_custom_options(app.get(), config_string);
config_string = config_string.substr(loc);
CHECK(config_string.empty());
auto *opt1 = app->get_option_no_throw("--new_option");
REQUIRE(opt1 != nullptr);
CHECK(opt1->get_required());
CHECK(opt1->get_expected_min() == 2);
CHECK(opt1->get_configurable());
CHECK(opt1->get_ignore_case());
auto *opt2 = app->get_option_no_throw("--new_flag");
REQUIRE(opt2 != nullptr);
CHECK(opt2->get_disable_flag_override());
CHECK(!opt2->get_configurable());
CHECK(!opt2->get_ignore_case());
auto *opt3 = app->get_option_no_throw("--new_vector");
REQUIRE(opt3 != nullptr);
CHECK(opt3->get_expected_min() == 0);
CHECK(opt3->get_expected_max() == 3);
CHECK(opt3->get_multi_option_policy() == CLI::MultiOptionPolicy::Sum);
}
// this test uses the same tests as above just with a full roundtrip test
TEST_CASE("app_roundtrip_custom") {
CLI::FuzzApp fuzzdata;