| 58 | } // namespace |
| 59 | |
| 60 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 61 | { |
| 62 | FuzzedDataProvider fdp(data, size); |
| 63 | |
| 64 | args::ArgumentParser parser("completion_fuzzer"); |
| 65 | args::CompletionFlag completion(parser, {"completion"}); |
| 66 | |
| 67 | args::Flag foo(parser, "foo", "foo", {'f', "foo"}); |
| 68 | args::ValueFlag<std::string> bar(parser, "bar", "bar", {'b', "bar"}, "abc"); |
| 69 | args::ValueFlag<int> num(parser, "num", "num", {'n', "num"}); |
| 70 | args::MapFlag<std::string, int> map(parser, "map", "map", {'m', "map"}, kChoices); |
| 71 | args::MapPositional<std::string, int> mpos(parser, "mpos", "mpos", kChoices); |
| 72 | args::Positional<std::string> pos(parser, "pos", "pos"); |
| 73 | |
| 74 | // Vary the long separator, including prefix-overlapping values. |
| 75 | try |
| 76 | { |
| 77 | parser.LongSeparator(kSeparators[fdp.ConsumeIntegralInRange<size_t>(0, ArraySize(kSeparators) - 1)]); |
| 78 | } |
| 79 | catch (...) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | // Command subparsers, mirroring test/completion.cxx: arguments are |
| 84 | // created inside the coroutine and Parse() is called before any result |
| 85 | // is consumed; the objects stay alive for the duration of the parse. |
| 86 | args::Command command1(parser, "command1", "first command", [](args::Subparser &sp) |
| 87 | { |
| 88 | args::ValueFlag<std::string> cfoo(sp, "cfoo", "cfoo", {'f', "cfoo"}, "abc"); |
| 89 | sp.Parse(); |
| 90 | if (cfoo) |
| 91 | { |
| 92 | (void)*cfoo; |
| 93 | } |
| 94 | }); |
| 95 | |
| 96 | args::Command command2(parser, "command2", "second command", [](args::Subparser &sp) |
| 97 | { |
| 98 | sp.Parse(); |
| 99 | }); |
| 100 | |
| 101 | for (int round = 0; round < 2; ++round) |
| 102 | { |
| 103 | std::vector<std::string> argv; |
| 104 | argv.reserve(8); |
| 105 | argv.emplace_back("--completion"); |
| 106 | if (fdp.ConsumeBool()) |
| 107 | { |
| 108 | argv.emplace_back("bash"); |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | argv.emplace_back(fdp.ConsumeRandomLengthString(8)); |
| 113 | } |
| 114 | if (fdp.ConsumeBool()) |
| 115 | { |
| 116 | argv.emplace_back(kCwords[fdp.ConsumeIntegralInRange<size_t>(0, ArraySize(kCwords) - 1)]); |
| 117 | } |
nothing calls this directly
no test coverage detected