mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
Fix some minor fuzzing issues. (#1138)
One in the fuzz check handling of NaN's and a pathway to generate a HorribleError. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -306,14 +306,13 @@ TEST_CASE("fuzz_config_modifier_test1") {
|
||||
CHECK(opt3->get_multi_option_policy() == CLI::MultiOptionPolicy::Sum);
|
||||
}
|
||||
|
||||
// this test uses the same tests as above just with a full roundtrip test
|
||||
// this test enables the custom option creation operation
|
||||
TEST_CASE("app_roundtrip_custom") {
|
||||
CLI::FuzzApp fuzzdata;
|
||||
CLI::FuzzApp fuzzdata2;
|
||||
auto app = fuzzdata.generateApp();
|
||||
auto app2 = fuzzdata2.generateApp();
|
||||
int index = GENERATE(range(1, 4));
|
||||
std::string optionString, flagString;
|
||||
int index = GENERATE(range(1, 5));
|
||||
auto parseData = loadFailureFile("round_trip_custom", index);
|
||||
std::size_t pstring_start{0};
|
||||
pstring_start = fuzzdata.add_custom_options(app.get(), parseData);
|
||||
@@ -335,3 +334,43 @@ TEST_CASE("app_roundtrip_custom") {
|
||||
auto result = fuzzdata2.compare(fuzzdata);
|
||||
CHECK(result);
|
||||
}
|
||||
|
||||
// this test
|
||||
TEST_CASE("app_roundtrip_parse_normal_fail") {
|
||||
// this is mostly checking that no unexpected errors occur
|
||||
// like HorribleErrors
|
||||
CLI::FuzzApp fuzzdata;
|
||||
auto app = fuzzdata.generateApp();
|
||||
int index = GENERATE(range(1, 3));
|
||||
std::string optionString, flagString;
|
||||
auto parseData = loadFailureFile("parse_fail_check", index);
|
||||
std::size_t pstring_start{0};
|
||||
pstring_start = fuzzdata.add_custom_options(app.get(), parseData);
|
||||
|
||||
try {
|
||||
if(pstring_start > 0) {
|
||||
app->parse(parseData.substr(pstring_start));
|
||||
} else {
|
||||
app->parse(parseData);
|
||||
}
|
||||
} catch(const CLI::HorribleError & /*he*/) {
|
||||
CHECK(false);
|
||||
return;
|
||||
} catch(const CLI::ParseError & /*e*/) {
|
||||
CHECK(true);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// should be able to write the config to a file and read from it again
|
||||
std::string configOut = app->config_to_str();
|
||||
app->clear();
|
||||
std::stringstream out(configOut);
|
||||
app->parse_from_stream(out);
|
||||
} catch(const CLI::HorribleError & /*he*/) {
|
||||
CHECK(false);
|
||||
return;
|
||||
} catch(const CLI::ParseError & /*e*/) {
|
||||
CHECK(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
1
tests/fuzzFail/parse_fail_check1
Normal file
1
tests/fuzzFail/parse_fail_check1
Normal file
@@ -0,0 +1 @@
|
||||
'--sub1.!-vA '
|
||||
BIN
tests/fuzzFail/parse_fail_check2
Normal file
BIN
tests/fuzzFail/parse_fail_check2
Normal file
Binary file not shown.
1
tests/fuzzFail/round_trip_custom4
Normal file
1
tests/fuzzFail/round_trip_custom4
Normal file
@@ -0,0 +1 @@
|
||||
--vC
|
||||
Reference in New Issue
Block a user