18#include <boost/program_options.hpp>
19#include <boost/program_options/parsers.hpp>
20#include <catch_amalgamated.hpp>
31 auto specs = std::vector<ConfigParamSpec>{
32 {
"someInt", VariantType::Int, 2, {
"some int option"}},
33 {
"someInt8", VariantType::Int8,
static_cast<int8_t
>(2), {
"some int8 option"}},
34 {
"someInt16", VariantType::Int16,
static_cast<int16_t
>(2), {
"some int16 option"}},
35 {
"someUInt8", VariantType::UInt8,
static_cast<uint8_t
>(2u), {
"some uint8 option"}},
36 {
"someUInt16", VariantType::UInt16,
static_cast<uint16_t
>(2u), {
"some uint16 option"}},
37 {
"someUInt32", VariantType::UInt32, 2u, {
"some uint32 option"}},
38 {
"someUInt64", VariantType::UInt64,
static_cast<uint64_t
>(2ul), {
"some uint64 option"}},
39 {
"someInt64", VariantType::Int64, 4ll, {
"some int64 option"}},
40 {
"someBool", VariantType::Bool,
false, {
"some bool option"}},
41 {
"someFloat", VariantType::Float, 2.0f, {
"some float option"}},
42 {
"someDouble", VariantType::Double, 2.0, {
"some double option"}},
43 {
"someString", VariantType::String, strdup(
"barfoo"), {
"some string option"}}};
44 const char* args[] = {
54 "--someInt64",
"50000000000000",
56 "--someDouble",
"0.5",
57 "--someString",
"foobar"};
58 bpo::variables_map vm;
59 bpo::options_description opts;
63 bpo::store(parse_command_line(
sizeof(args) /
sizeof(
char*), args, opts), vm);
65 REQUIRE(vm[
"someInt"].as<int>() == 1);
66 REQUIRE(vm[
"someInt8"].as<int8_t>() ==
'1');
67 REQUIRE(vm[
"someInt16"].as<int16_t>() == 1);
68 REQUIRE(vm[
"someUInt8"].as<uint8_t>() ==
'1');
69 REQUIRE(vm[
"someUInt16"].as<uint16_t>() == 1);
70 REQUIRE(vm[
"someUInt32"].as<uint32_t>() == 1);
71 REQUIRE(vm[
"someUInt64"].as<uint64_t>() == 1);
72 REQUIRE(vm[
"someInt64"].as<int64_t>() == 50000000000000ll);
73 REQUIRE(vm[
"someBool"].as<bool>() ==
true);
74 REQUIRE(vm[
"someString"].as<std::string>() ==
"foobar");
75 REQUIRE(vm[
"someFloat"].as<float>() == 0.5);
76 REQUIRE(vm[
"someDouble"].as<double>() == 0.5);
81constexpr char const* fullLabeledJSON = R
"({"labels_rows":["a","b"],"labels_cols":["x","y"],"values":[[5,6],[7,8]]})";
85 int m[2][2] = {{1, 2}, {3, 4}};
89std::unique_ptr<ConfigParamRegistry> registryFromCommandLine(std::vector<ConfigParamSpec>
const& specs, std::vector<char const*> args)
91 args.insert(args.begin(),
"test");
92 std::vector<std::unique_ptr<ParamRetriever>> retrievers;
93 retrievers.emplace_back(std::make_unique<BoostOptionsRetriever>(
true, args.size(),
const_cast<char**
>(args.data())));
94 auto store = std::make_unique<ConfigParamStore>(specs, std::move(retrievers));
97 return std::make_unique<ConfigParamRegistry>(std::move(store));
104 auto specs = std::vector<ConfigParamSpec>{
105 {
"someLabeledArray", VariantType::LabeledArrayInt, defaultLabeledArray(), {
"some labeled array option"}}};
108 bpo::options_description opts;
110 const char* args[] = {
"test",
"--someLabeledArray", fullLabeledJSON};
111 bpo::variables_map vm;
112 bpo::store(parse_command_line(
sizeof(args) /
sizeof(
char*), args, opts), vm);
114 REQUIRE(vm[
"someLabeledArray"].as<std::string>() == fullLabeledJSON);
117 bpo::variables_map vmDefault;
118 const char* noArgs[] = {
"test"};
119 bpo::store(parse_command_line(1, noArgs, opts), vmDefault);
120 REQUIRE(vmDefault[
"someLabeledArray"].as<std::string>() == specs[0].defaultValue.asString());
125 auto specs = std::vector<ConfigParamSpec>{
126 {
"someLabeledArray", VariantType::LabeledArrayInt, defaultLabeledArray(), {
"some labeled array option"}}};
129 auto registry = registryFromCommandLine(specs, {
"--someLabeledArray", fullLabeledJSON});
131 REQUIRE(la.getLabelsRows() == std::vector<std::string>{
"a",
"b"});
132 REQUIRE(la.getLabelsCols() == std::vector<std::string>{
"x",
"y"});
133 REQUIRE(la.get(
"b",
"y") == 8);
136 registry = registryFromCommandLine(specs, {});
138 REQUIRE(la.get(
"r2",
"c2") == 4);
141 registry = registryFromCommandLine(specs, {
"--someLabeledArray", R
"({"values":[[5,6],[7,8]]})"});
143 REQUIRE(la.getLabelsRows() == std::vector<std::string>{
"r1",
"r2"});
144 REQUIRE(la.getLabelsCols() == std::vector<std::string>{
"c1",
"c2"});
145 REQUIRE(la.get(
"r2",
"c1") == 7);
148 REQUIRE_THROWS(registryFromCommandLine(specs, {
"--someLabeledArray", R
"({"values":[[5,6,7]]})"}));
156 std::string atLimit(
max,
'x');
159 std::string longValue = std::string(
"BEGIN") + std::string(100,
'-') +
"END";
161 REQUIRE(shown.size() ==
max);
162 REQUIRE(shown.starts_with(
"BEGIN"));
163 REQUIRE(shown.ends_with(
"END"));
164 REQUIRE(shown.find(
"...") != std::string::npos);
171 std::vector<int>
values(30, 12345);
172 std::vector<std::string>
rows{
"row"};
173 std::vector<std::string>
cols;
174 for (
auto i = 0U;
i <
values.size(); ++
i) {
178 auto workflowOptions = std::vector<ConfigParamSpec>{
179 {
"longLabeledArray", VariantType::LabeledArrayInt, la, {
"a labeled array option with a long default"}}};
180 auto full = workflowOptions[0].defaultValue.asString();
185 std::stringstream help;
188 REQUIRE(help.str().find(full) == std::string::npos);
191 bpo::options_description forwarded;
193 const char* noArgs[] = {
"test"};
194 bpo::variables_map vm;
195 bpo::store(parse_command_line(1, noArgs, forwarded), vm);
196 REQUIRE(vm[
"longLabeledArray"].as<std::string>() == full);
199 bpo::options_description deviceOptions;
201 std::stringstream deviceHelp;
202 deviceHelp << deviceOptions;
203 REQUIRE(deviceHelp.str().find(full) == std::string::npos);
204 bpo::variables_map deviceVm;
205 bpo::store(parse_command_line(1, noArgs, deviceOptions), deviceVm);
206 REQUIRE(deviceVm[
"longLabeledArray"].as<std::string>() == full);
header::DataDescription description
GLenum GLsizei GLsizei GLint * values
Defining ITS Vertex explicitly as messageable.
std::string to_string(gsl::span< T, Size > span)
static constexpr size_t MaxHelpDefaultLength
static boost::program_options::options_description prepareOptionDescriptions(ContainerType const &workflow, std::vector< ConfigParamSpec > const ¤tWorkflowOptions, options_description vetos=options_description(), std::string mode="full")
populate boost program options for a complete workflow
static bool dpl2BoostOptions(const std::vector< ConfigParamSpec > &spec, options_description &options, boost::program_options::options_description const &vetos=options_description())
static void populateBoostProgramOptions(options_description &options, const std::vector< ConfigParamSpec > &specs, options_description vetos=options_description())
static std::string defaultValueForHelp(std::string const &value)
TEST_CASE("TrivialBoostOptionsRetrieverTest")
std::vector< ReadoutWindowData > rows