mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-30 12:43:52 +00:00
This adds a round trip test for config file generation to the fuzzer. (the next step after this PR will be a fuzzer that verifies that the round trip actually matches the results. This change ended up requiring quite a few minor changes to fix the ambiguities between the config file generation and config file reader. 1). There was a number of potential conflicts between positional names and regular option names that could be triggered in config files, this required a number of additional checks on the positional naming to ensure no conflicts. 2). flag options with disable flag override can produce output results that are not valid by themselves, resolving this required flag input to be able to handle an array and output the original value set of results. 3). strings with non-printable characters could cause all sorts of chaos in the config files. This was resolved by generating a binary string conversion format and handling multiline comments and characters, and handling escaped characters. Note; I think a better solution is to move to fully supporting string formatting and escaping along with the binary strings from TOML now that TOML 1.0 is finalized. That will not be this PR though, maybe the next one. 4). Lot of ambiguities and edge cases in the string splitter, this was reworked 5). handling of comments was not done well, especially comment characters in the name of the option which is allowed. 6). non printable characters in the option naming. This would be weird in practice but it also cause some big holes in the config file generation, so the restricted character set for option naming was expanded. (don't allow spaces or control characters). --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
119 lines
3.0 KiB
C++
119 lines
3.0 KiB
C++
// Copyright (c) 2017-2023, University of Cincinnati, developed by Henry Schreiner
|
|
// under NSF AWARD 1414736 and by the respective contributors.
|
|
// All rights reserved.
|
|
//
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
#pragma once
|
|
|
|
#ifdef CLI11_SINGLE_FILE
|
|
#include "CLI11.hpp"
|
|
#else
|
|
#include "CLI/CLI.hpp"
|
|
#endif
|
|
|
|
#include <atomic>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
namespace CLI {
|
|
|
|
class intWrapper64 {
|
|
public:
|
|
intWrapper64() = default;
|
|
explicit intWrapper64(int64_t v) : val(v){};
|
|
CLI11_NODISCARD int64_t value() const { return val; }
|
|
|
|
private:
|
|
int64_t val{0};
|
|
};
|
|
|
|
class doubleWrapper {
|
|
public:
|
|
doubleWrapper() = default;
|
|
explicit doubleWrapper(double v) : val(v){};
|
|
CLI11_NODISCARD double value() const { return val; }
|
|
|
|
private:
|
|
double val{0.0};
|
|
};
|
|
|
|
class stringWrapper {
|
|
public:
|
|
stringWrapper() = default;
|
|
explicit stringWrapper(std::string_view v) : val(v){};
|
|
CLI11_NODISCARD std::string value() const { return val; }
|
|
|
|
private:
|
|
std::string val{};
|
|
};
|
|
|
|
class FuzzApp {
|
|
public:
|
|
FuzzApp() = default;
|
|
|
|
std::shared_ptr<CLI::App> generateApp();
|
|
|
|
int32_t val32{0};
|
|
int16_t val16{0};
|
|
int8_t val8{0};
|
|
int64_t val64{0};
|
|
|
|
uint32_t uval32{0};
|
|
uint16_t uval16{0};
|
|
uint8_t uval8{0};
|
|
uint64_t uval64{0};
|
|
|
|
std::atomic<int64_t> atomicval64{0};
|
|
std::atomic<uint64_t> atomicuval64{0};
|
|
|
|
double v1{0};
|
|
float v2{0};
|
|
|
|
std::vector<double> vv1{};
|
|
std::vector<std::string> vstr{};
|
|
|
|
std::vector<std::vector<double>> vecvecd{};
|
|
std::vector<std::vector<std::string>> vvs{};
|
|
std::optional<double> od1{};
|
|
std::optional<std::string> ods{};
|
|
std::pair<double, std::string> p1{};
|
|
std::pair<std::vector<double>, std::string> p2{};
|
|
std::tuple<int64_t, uint16_t, std::optional<double>> t1{};
|
|
std::tuple<std::tuple<std::tuple<std::string, double, std::vector<int>>, std::string, double>,
|
|
std::vector<int>,
|
|
std::optional<std::string>>
|
|
tcomplex{};
|
|
std::tuple<std::tuple<std::tuple<std::string, double, std::vector<int>>, std::string, double>,
|
|
std::vector<int>,
|
|
std::optional<std::string>>
|
|
tcomplex2{};
|
|
std::vector<std::tuple<std::string, double, char, std::vector<std::string>>> vectup{};
|
|
std::string_view vstrv = "";
|
|
|
|
bool flag1{false};
|
|
int flagCnt{0};
|
|
std::atomic<bool> flagAtomic{false};
|
|
|
|
intWrapper64 iwrap{0};
|
|
doubleWrapper dwrap{0.0};
|
|
stringWrapper swrap{};
|
|
std::string buffer{};
|
|
int intbuffer{0};
|
|
std::atomic<double> doubleAtomic{0.0};
|
|
|
|
// for testing restrictions and reduction methods
|
|
std::vector<std::string> vstrA{};
|
|
std::vector<std::string> vstrB{};
|
|
std::vector<std::string> vstrC{};
|
|
std::vector<std::string> vstrD{};
|
|
std::vector<std::string> vstrE{};
|
|
std::vector<std::string> vstrF{};
|
|
std::string mergeBuffer{};
|
|
std::vector<std::string> validator_strings{};
|
|
};
|
|
} // namespace CLI
|