1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-28 19:53:52 +00:00

Value initialization (#416)

* work on the flags book chapter and making sure the values are initialized properly.

* Fix initialization of values used in flags or options

* update some formatting and more brace initialization

* update more formatting and fix a incorrect initializer

* more formatting and some error fixes

* more formatting

* Small formatting fix

Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
This commit is contained in:
Philip Top 2020-01-27 07:42:03 -08:00 committed by Henry Schreiner
parent 0c3020b9ef
commit 6b7f6a7480
24 changed files with 287 additions and 261 deletions

View File

@ -7,7 +7,7 @@ The most basic addition to a command line program is a flag. This is simply some
The simplest way to add a flag is probably a boolean flag:
```cpp
bool my_flag;
bool my_flag{false};
app.add_flag("-f", my_flag, "Optional description");
```
@ -19,12 +19,38 @@ This will bind the flag `-f` to the boolean `my_flag`. After the parsing step, `
If you want to allow multiple flags, simply use any integer-like instead of a bool:
```cpp
int my_flag;
int my_flag{0};
app.add_flag("-f", my_flag, "Optional description");
```
After the parsing step, `my_flag` will contain the number of times this flag was found on the command line, including 0 if not found.
## Arbitrary type flags
CLI11 allows the type of the variable to assign to in the `add_flag` function to be any supported type. This is particularly useful in combination with specifying default values for flags. The allowed types include bool, int, float, vector, enum, or string-like.
### Default Flag Values
Flag options specified through the `add_flag*` functions allow a syntax for the option names to default particular options to a false value or any other value if some flags are passed. For example:
```cpp
app.add_flag("--flag,!--no-flag",result,"help for flag");
```
specifies that if `--flag` is passed on the command line result will be true or contain a value of 1. If `--no-flag` is
passed `result` will contain false or -1 if `result` is a signed integer type, or 0 if it is an unsigned type. An
alternative form of the syntax is more explicit: `"--flag,--no-flag{false}"`; this is equivalent to the previous
example. This also works for short form options `"-f,!-n"` or `"-f,-n{false}"`. If `variable_to_bind_to` is anything but an integer value the
default behavior is to take the last value given, while if `variable_to_bind_to` is an integer type the behavior will be to sum
all the given arguments and return the result. This can be modified if needed by changing the `multi_option_policy` on each flag (this is not inherited).
The default value can be any value. For example if you wished to define a numerical flag:
```cpp
app.add_flag("-1{1},-2{2},-3{3}",result,"numerical flag")
```
using any of those flags on the command line will result in the specified number in the output. Similar things can be done for string values, and enumerations, as long as the default value can be converted to the given type.
## Pure flags
Every command that starts with `add_`, such as the flag commands, return a pointer to the internally stored `CLI::Option` that describes your addition. If you prefer, you can capture this pointer and use it, and that allows you to skip adding a variable to bind to entirely:
@ -52,7 +78,7 @@ The name string, the first item of every `add_` method, can contain as many shor
If you want to make an option case insensitive, you can use the `->ignore_case()` method on the `CLI::Option` to do that. For example,
```cpp
bool flag;
bool flag{false};
app.add_flag("--flag", flag)
->ignore_case();
```

View File

@ -5,14 +5,14 @@ The most versatile addition to a command line program is a option. This is like
```cpp
int int_option;
int int_option{0};
app.add_option("-i", int_option, "Optional description");
```
This will bind the option `-i` to the integer `int_option`. On the command line, a single value that can be converted to an integer will be expected. Non-integer results will fail. If that option is not given, CLI11 will not touch the initial value. This allows you to set up defaults by simply setting your value beforehand. If you want CLI11 to display your default value, you can add the optional final argument `true` when you add the option. If you do not add this, you do not even need your option value to be printable[^1].
```cpp
int int_option = 0;
int int_option{0};
app.add_option("-i", int_option, "Optional description", true);
```
@ -138,7 +138,7 @@ Besides `add_option` and `add_flag`, there are several special ways to create op
You can add a set with `add_set`, where you give a variable to set and a `std::set` of choices to pick from. There also is a `add_set_ignore_case` version which ignores case when set matching. If you use an existing set instead of an inline one, you can edit the set after adding it and changes will be reflected in the set checking and help message.
```cpp
int val;
int val{0};
app.add_set("--even", val, {0,2,4,6,8});
```
@ -147,7 +147,7 @@ app.add_set("--even", val, {0,2,4,6,8});
You can also add a complex number. This type just needs to support a `(T x, T y)` constructor and be printable. You can also pass one extra argument that will set the label of the type; by default it is "COMPLEX".
```cpp
std::complex<float> val;
std::complex<float> val{0.0F,0.0F};
app.add_complex("--cplx", val);
```
@ -197,7 +197,7 @@ app.add_option("--opt",val,"description");
gets into the complicated cases where the type size is now 3. and the expected max is set to a large number and `allow_extra_args` is set to true. In this case at least 3 arguments are required to follow the option, and subsequent groups must come in groups of three, otherwise an error will result.
```cpp
bool val;
bool val{false};
app.add_flag("--opt",val,"description");
```

View File

@ -4,7 +4,7 @@
int main(int argc, char **argv) {
CLI::App app;
int val;
int val{0};
// add a set of flags with default values associate with them
app.add_flag("-1{1},-2{2},-3{3},-4{4},-5{5},-6{6}, -7{7}, -8{8}, -9{9}", val, "compression level");

View File

@ -11,10 +11,10 @@ int main(int argc, char **argv) {
std::string file;
CLI::Option *opt = app.add_option("-f,--file,file", file, "File name")->required()->group("Important");
int count;
int count{0};
CLI::Option *copt = app.add_flag("-c,--count", count, "Counter")->required()->group("Important");
double value; // = 3.14;
double value{0.0}; // = 3.14;
app.add_option("-d,--double", value, "Some Value")->group("Other");
try {

View File

@ -9,9 +9,9 @@ int main(int argc, char **argv) {
auto format = app.add_option_group("output_format", "formatting type for output");
auto target = app.add_option_group("output target", "target location for the output");
bool csv = false;
bool human = false;
bool binary = false;
bool csv{false};
bool human{false};
bool binary{false};
format->add_flag("--csv", csv, "specify the output in csv format");
format->add_flag("--human", human, "specify the output in human readable text format");
format->add_flag("--binary", binary, "specify the output in binary format");

View File

@ -8,7 +8,7 @@ int main(int argc, char **argv) {
auto numbers = app.add_option_group("numbers", "specify key numbers");
auto files = app.add_option_group("files", "specify files");
int num1 = -1, num2 = -1;
int num1{-1}, num2{-1};
numbers->add_option("num1", num1, "first number");
numbers->add_option("num2", num2, "second number");
std::string file1, file2;

View File

@ -6,7 +6,7 @@ int main(int argc, char **argv) {
CLI::App app("test for positional validation");
int num1 = -1, num2 = -1;
int num1{-1}, num2{-1};
app.add_option("num1", num1, "first number")->check(CLI::Number);
app.add_option("num2", num2, "second number")->check(CLI::Number);
std::string file1, file2;

View File

@ -10,7 +10,7 @@ int main(int argc, char **argv) {
app.add_option("--range,-R", range, "A range")->expected(-2);
auto ogroup = app.add_option_group("min_max_step", "set the min max and step");
int min, max, step = 1;
int min{0}, max{0}, step{1};
ogroup->add_option("--min,-m", min, "The minimum")->required();
ogroup->add_option("--max,-M", max, "The maximum")->required();
ogroup->add_option("--step,-s", step, "The step", true);

View File

@ -9,7 +9,7 @@ int main(int argc, char **argv) {
app.set_help_all_flag("--help-all");
auto circle = app.add_subcommand("circle", "draw a circle")->immediate_callback();
double radius{0.0};
int circle_counter = 0;
int circle_counter{0};
circle->callback([&radius, &circle_counter] {
++circle_counter;
std::cout << "circle" << circle_counter << " with radius " << radius << std::endl;
@ -20,7 +20,7 @@ int main(int argc, char **argv) {
auto rect = app.add_subcommand("rectangle", "draw a rectangle")->immediate_callback();
double edge1{0.0};
double edge2{0.0};
int rect_counter = 0;
int rect_counter{0};
rect->callback([&edge1, &edge2, &rect_counter] {
++rect_counter;
if(edge2 == 0) {

View File

@ -9,13 +9,13 @@ int main(int argc, char **argv) {
std::string file;
CLI::Option *opt = app.add_option("-f,--file,file", file, "File name");
int count;
int count{0};
CLI::Option *copt = app.add_option("-c,--count", count, "Counter");
int v;
int v{0};
CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times");
double value; // = 3.14;
double value{0.0}; // = 3.14;
app.add_option("-d,--double", value, "Some Value");
CLI11_PARSE(app, argc, argv);

View File

@ -13,11 +13,11 @@ int main(int argc, char **argv) {
std::string file;
CLI::Option *opt = impOpt->add_option("-f,--file,file", file, "File name")->required();
int count;
int count{0};
CLI::Option *copt = impOpt->add_flag("-c,--count", count, "Counter")->required();
CLI::App_p otherOpt = std::make_shared<CLI::App>("Other");
double value; // = 3.14;
double value{0.0}; // = 3.14;
otherOpt->add_option("-d,--double", value, "Some Value");
// add the subapps to the main one

View File

@ -9,7 +9,7 @@ int main(int argc, char **argv) {
std::string file;
app.add_option("-f,--file,file", file, "File name")->check(CLI::ExistingFile);
int count;
int count{0};
app.add_option("-v,--value", count, "Value in range")->check(CLI::Range(3, 6));
CLI11_PARSE(app, argc, argv);

View File

@ -141,7 +141,7 @@ TEST_F(TApp, RequireOptionsError) {
}
TEST_F(TApp, BoolFlagOverride) {
bool val;
bool val{false};
auto flg = app.add_flag("--this,--that", val);
app.parse("--this");
@ -161,7 +161,7 @@ TEST_F(TApp, BoolFlagOverride) {
}
TEST_F(TApp, OneFlagRef) {
int ref;
int ref{0};
app.add_flag("-c,--count", ref);
args = {"--count"};
run();
@ -171,7 +171,7 @@ TEST_F(TApp, OneFlagRef) {
}
TEST_F(TApp, OneFlagRefValue) {
int ref;
int ref{0};
app.add_flag("-c,--count", ref);
args = {"--count=7"};
run();
@ -181,7 +181,7 @@ TEST_F(TApp, OneFlagRefValue) {
}
TEST_F(TApp, OneFlagRefValueFalse) {
int ref;
int ref{0};
auto flg = app.add_flag("-c,--count", ref);
args = {"--count=false"};
run();
@ -201,7 +201,7 @@ TEST_F(TApp, OneFlagRefValueFalse) {
}
TEST_F(TApp, FlagNegation) {
int ref;
int ref{0};
auto flg = app.add_flag("-c,--count,--ncount{false}", ref);
args = {"--count", "-c", "--ncount"};
EXPECT_FALSE(flg->check_fname("count"));
@ -214,7 +214,7 @@ TEST_F(TApp, FlagNegation) {
}
TEST_F(TApp, FlagNegationShortcutNotation) {
int ref;
int ref{0};
app.add_flag("-c,--count{true},!--ncount", ref);
args = {"--count=TRUE", "-c", "--ncount"};
run();
@ -225,7 +225,7 @@ TEST_F(TApp, FlagNegationShortcutNotation) {
}
TEST_F(TApp, FlagNegationShortcutNotationInvalid) {
int ref;
int ref{0};
app.add_flag("-c,--count,!--ncount", ref);
args = {"--ncount=happy"};
EXPECT_THROW(run(), CLI::ConversionError);
@ -418,7 +418,7 @@ TEST_F(TApp, OneStringFlagLike) {
}
TEST_F(TApp, OneIntFlagLike) {
int val;
int val{0};
auto opt = app.add_option("-i", val)->expected(0, 1);
args = {"-i"};
run();
@ -433,7 +433,7 @@ TEST_F(TApp, OneIntFlagLike) {
}
TEST_F(TApp, TogetherInt) {
int i;
int i{0};
app.add_option("-i,--int", i);
args = {"-i4"};
run();
@ -445,7 +445,7 @@ TEST_F(TApp, TogetherInt) {
}
TEST_F(TApp, SepInt) {
int i;
int i{0};
app.add_option("-i,--int", i);
args = {"-i", "4"};
run();
@ -475,7 +475,7 @@ TEST_F(TApp, OneStringFunction) {
}
TEST_F(TApp, doubleFunction) {
double res;
double res{0.0};
app.add_option_function<double>("--val", [&res](double val) { res = std::abs(val + 54); });
args = {"--val", "-354.356"};
run();
@ -596,7 +596,7 @@ TEST_F(TApp, LotsOfFlags) {
TEST_F(TApp, NumberFlags) {
int val;
int val{0};
app.add_flag("-1{1},-2{2},-3{3},-4{4},-5{5},-6{6}, -7{7}, -8{8}, -9{9}", val);
args = {"-7"};
@ -607,7 +607,7 @@ TEST_F(TApp, NumberFlags) {
TEST_F(TApp, DisableFlagOverrideTest) {
int val;
int val{0};
auto opt = app.add_flag("--1{1},--2{2},--3{3},--4{4},--5{5},--6{6}, --7{7}, --8{8}, --9{9}", val);
EXPECT_FALSE(opt->get_disable_flag_override());
opt->disable_flag_override();
@ -649,9 +649,9 @@ TEST_F(TApp, LotsOfFlagsSingleStringExtraSpace) {
TEST_F(TApp, BoolAndIntFlags) {
bool bflag;
int iflag;
unsigned int uflag;
bool bflag{false};
int iflag{0};
unsigned int uflag{0};
app.add_flag("-b", bflag);
app.add_flag("-i", iflag);
@ -677,7 +677,7 @@ TEST_F(TApp, BoolAndIntFlags) {
}
TEST_F(TApp, FlagLikeOption) {
bool val = false;
bool val{false};
auto opt = app.add_option("--flag", val)->type_size(0)->default_str("true");
args = {"--flag"};
run();
@ -693,7 +693,7 @@ TEST_F(TApp, FlagLikeOption) {
}
TEST_F(TApp, FlagLikeIntOption) {
int val = -47;
int val{-47};
auto opt = app.add_option("--flag", val)->expected(0, 1);
// normally some default value should be set, but this test is for some paths in the validators checks to skip
// validation on empty string if nothing is expected
@ -713,7 +713,7 @@ TEST_F(TApp, FlagLikeIntOption) {
}
TEST_F(TApp, BoolOnlyFlag) {
bool bflag;
bool bflag{false};
app.add_flag("-b", bflag)->multi_option_policy(CLI::MultiOptionPolicy::Throw);
args = {"-b"};
@ -725,7 +725,7 @@ TEST_F(TApp, BoolOnlyFlag) {
}
TEST_F(TApp, BoolOption) {
bool bflag;
bool bflag{false};
app.add_option("-b", bflag);
args = {"-b", "false"};
@ -752,7 +752,7 @@ TEST_F(TApp, BoolOption) {
TEST_F(TApp, ShortOpts) {
unsigned long long funnyint;
unsigned long long funnyint{0};
std::string someopt;
app.add_flag("-z", funnyint);
app.add_option("-y", someopt);
@ -772,7 +772,7 @@ TEST_F(TApp, ShortOpts) {
TEST_F(TApp, TwoParamTemplateOpts) {
double funnyint;
double funnyint{0.0};
auto opt = app.add_option<double, unsigned int>("-y", funnyint);
args = {"-y", "32"};
@ -793,7 +793,7 @@ TEST_F(TApp, TwoParamTemplateOpts) {
TEST_F(TApp, DefaultOpts) {
int i = 3;
int i{3};
std::string s = "HI";
app.add_option("-i,i", i);
@ -971,7 +971,7 @@ TEST_F(TApp, ComplexOptMulti) {
}
TEST_F(TApp, MissingValueNonRequiredOpt) {
int count;
int count{0};
app.add_option("-c,--count", count);
args = {"-c"};
@ -1191,7 +1191,7 @@ TEST_F(TApp, RequiredPositionalVector) {
// Tests positionals at end
TEST_F(TApp, RequiredPositionalValidation) {
std::vector<std::string> sources;
int dest;
int dest; // required
std::string d2;
app.add_option("src", sources);
app.add_option("dest", dest)->required()->check(CLI::PositiveNumber);
@ -1432,7 +1432,7 @@ TEST_F(TApp, RequiredFlags) {
TEST_F(TApp, CallbackFlags) {
std::int64_t value = 0;
std::int64_t value{0};
auto func = [&value](std::int64_t x) { value = x; };
@ -1454,7 +1454,7 @@ TEST_F(TApp, CallbackFlags) {
TEST_F(TApp, CallbackBoolFlags) {
bool value = false;
bool value{false};
auto func = [&value]() { value = true; };
@ -1534,7 +1534,7 @@ TEST_F(TApp, CallbackFlagsFalseShortcut) {
#if __cplusplus >= 201402L || _MSC_VER >= 1900
TEST_F(TApp, CallbackFlagsAuto) {
std::int64_t value = 0;
std::int64_t value{0};
auto func = [&value](std::int64_t x) { value = x; };
@ -1593,7 +1593,7 @@ TEST_F(TApp, ForcedPositional) {
TEST_F(TApp, MixedPositionals) {
int positional_int;
int positional_int{0};
std::string positional_string;
app.add_option("posit1,--posit1", positional_int, "");
app.add_option("posit2,--posit2", positional_string, "");
@ -1626,7 +1626,7 @@ TEST_F(TApp, BigPositional) {
TEST_F(TApp, Reset) {
app.add_flag("--simple");
double doub;
double doub{0.0};
app.add_option("-d,--double", doub);
args = {"--simple", "--double", "1.2"};
@ -1850,7 +1850,7 @@ TEST_F(TApp, VectorIndexedValidator) {
TEST_F(TApp, DefaultedResult) {
std::string sval = "NA";
int ival;
int ival{0};
auto opts = app.add_option("--string", sval)->capture_default_str();
auto optv = app.add_option("--val", ival);
args = {};
@ -2095,7 +2095,7 @@ TEST_F(TApp, Env) {
put_env("CLI11_TEST_ENV_TMP", "2");
int val = 1;
int val{1};
CLI::Option *vopt = app.add_option("--tmp", val)->envname("CLI11_TEST_ENV_TMP");
run();
@ -2111,7 +2111,7 @@ TEST_F(TApp, Env) {
}
TEST_F(TApp, RangeInt) {
int x = 0;
int x{0};
app.add_option("--one", x)->check(CLI::Range(3, 6));
args = {"--one=1"};
@ -2132,7 +2132,7 @@ TEST_F(TApp, RangeInt) {
TEST_F(TApp, RangeDouble) {
double x = 0;
double x{0.0};
/// Note that this must be a double in Range, too
app.add_option("--one", x)->check(CLI::Range(3.0, 6.0));
@ -2157,7 +2157,7 @@ TEST_F(TApp, AllowExtras) {
app.allow_extras();
bool val = true;
bool val{true};
app.add_flag("-f", val);
args = {"-x", "-f"};
@ -2217,8 +2217,8 @@ TEST_F(TApp, AllowExtrasCascadeDirect) {
EXPECT_EQ(app.remaining(), std::vector<std::string>({"-x", "45", "-f", "27"}));
CLI::App capp{"cascade_program"};
int v1 = 0;
int v2 = 0;
int v1{0};
int v2{0};
capp.add_option("-x", v1);
capp.add_option("-f", v2);
@ -2229,8 +2229,8 @@ TEST_F(TApp, AllowExtrasCascadeDirect) {
TEST_F(TApp, AllowExtrasArgModify) {
int v1 = 0;
int v2 = 0;
int v1{0};
int v2{0};
app.allow_extras();
app.add_option("-f", v2);
args = {"27", "-f", "45", "-x"};
@ -2308,7 +2308,7 @@ TEST_F(TApp, FallthroughParents) {
}
TEST_F(TApp, OptionWithDefaults) {
int someint = 2;
int someint{2};
app.add_option("-a", someint)->capture_default_str();
args = {"-a1", "-a2"};
@ -2587,7 +2587,7 @@ TEST_F(TApp, BeforeRequirements) {
// #209
TEST_F(TApp, CustomUserSepParse) {
std::vector<int> vals = {1, 2, 3};
std::vector<int> vals{1, 2, 3};
args = {"--idx", "1,2,3"};
auto opt = app.add_option("--idx", vals)->delimiter(',');
run();
@ -2631,7 +2631,7 @@ TEST_F(TApp, BadUserSepParse) {
// #209
TEST_F(TApp, CustomUserSepParse2) {
std::vector<int> vals = {1, 2, 3};
std::vector<int> vals{1, 2, 3};
args = {"--idx", "1,2,"};
auto opt = app.add_option("--idx", vals)->delimiter(',');
run();
@ -2646,7 +2646,7 @@ TEST_F(TApp, CustomUserSepParse2) {
TEST_F(TApp, CustomUserSepParseFunction) {
std::vector<int> vals = {1, 2, 3};
std::vector<int> vals{1, 2, 3};
args = {"--idx", "1,2,3"};
app.add_option_function<std::vector<int>>("--idx", [&vals](std::vector<int> v) { vals = std::move(v); })
->delimiter(',');

View File

@ -439,7 +439,7 @@ TEST_F(TApp, IniSuccessOnUnknownOption) {
out << "two=99" << std::endl;
}
int two = 0;
int two{0};
app.add_option("--two", two);
run();
EXPECT_EQ(99, two);
@ -459,7 +459,7 @@ TEST_F(TApp, IniGetRemainingOption) {
out << "two=99" << std::endl;
}
int two = 0;
int two{0};
app.add_option("--two", two);
ASSERT_NO_THROW(run());
std::vector<std::string> ExpectedRemaining = {ExtraOption};
@ -477,7 +477,7 @@ TEST_F(TApp, IniGetNoRemaining) {
out << "two=99" << std::endl;
}
int two = 0;
int two{0};
app.add_option("--two", two);
ASSERT_NO_THROW(run());
EXPECT_EQ(app.remaining().size(), 0u);
@ -487,7 +487,7 @@ TEST_F(TApp, IniRequiredNoDefault) {
app.set_config("--config")->required();
int two = 0;
int two{0};
app.add_option("--two", two);
ASSERT_THROW(run(), CLI::FileError);
}
@ -496,7 +496,7 @@ TEST_F(TApp, IniNotRequiredNoDefault) {
app.set_config("--config");
int two = 0;
int two{0};
app.add_option("--two", two);
ASSERT_NO_THROW(run());
}
@ -523,7 +523,7 @@ TEST_F(TApp, IniRequiredbadConfigurator) {
app.set_config("--config", tmpini)->required();
app.config_formatter(std::make_shared<EvilConfig>());
int two = 0;
int two{0};
app.add_option("--two", two);
ASSERT_THROW(run(), CLI::FileError);
}
@ -541,7 +541,7 @@ TEST_F(TApp, IniNotRequiredbadConfigurator) {
app.set_config("--config", tmpini);
app.config_formatter(std::make_shared<EvilConfig>());
int two = 0;
int two{0};
app.add_option("--two", two);
ASSERT_NO_THROW(run());
}
@ -567,7 +567,7 @@ TEST_F(TApp, IniNotRequiredNotDefault) {
out << "three=4" << std::endl;
}
int one = 0, two = 0, three = 0;
int one{0}, two{0}, three{0};
app.add_option("--one", one);
app.add_option("--two", two);
app.add_option("--three", three);
@ -616,7 +616,7 @@ TEST_F(TApp, IniOverwrite) {
app.set_config("--config", orig);
// Make sure this can be overwritten
app.set_config("--conf", next);
int two = 7;
int two{7};
app.add_option("--two", two);
run();
@ -637,7 +637,7 @@ TEST_F(TApp, IniRequired) {
out << "three=3" << std::endl;
}
int one = 0, two = 0, three = 0;
int one{0}, two{0}, three{0};
app.add_option("--one", one)->required();
app.add_option("--two", two)->required();
app.add_option("--three", three)->required();
@ -726,7 +726,7 @@ TEST_F(TApp, ColonValueSep) {
out << "three:3\n";
}
int two, three;
int two{0}, three{0};
app.add_option("--two", two);
app.add_option("--three", three);
@ -830,7 +830,7 @@ TEST_F(TApp, IniLayered) {
out << "subsubcom.val=3" << std::endl;
}
int one = 0, two = 0, three = 0;
int one{0}, two{0}, three{0};
app.add_option("--val", one);
auto subcom = app.add_subcommand("subcom");
subcom->add_option("--val", two);
@ -863,7 +863,7 @@ TEST_F(TApp, IniLayeredDotSection) {
out << "val=3" << std::endl;
}
int one = 0, two = 0, three = 0;
int one{0}, two{0}, three{0};
app.add_option("--val", one);
auto subcom = app.add_subcommand("subcom");
subcom->add_option("--val", two);
@ -895,7 +895,7 @@ TEST_F(TApp, IniSubcommandConfigurable) {
out << "subsubcom.val=3" << std::endl;
}
int one = 0, two = 0, three = 0;
int one{0}, two{0}, three{0};
app.add_option("--val", one);
auto subcom = app.add_subcommand("subcom");
subcom->configurable();
@ -929,7 +929,7 @@ TEST_F(TApp, IniSubcommandConfigurablePreParse) {
out << "subsubcom.val=3" << std::endl;
}
int one = 0, two = 0, three = 0, four = 0;
int one{0}, two{0}, three{0}, four{0};
app.add_option("--val", one);
auto subcom = app.add_subcommand("subcom");
auto subcom2 = app.add_subcommand("subcom2");
@ -971,7 +971,7 @@ TEST_F(TApp, IniSubcommandConfigurableParseComplete) {
out << "val=3" << std::endl;
}
int one = 0, two = 0, three = 0, four = 0;
int one{0}, two{0}, three{0}, four{0};
app.add_option("--val", one);
auto subcom = app.add_subcommand("subcom");
auto subcom2 = app.add_subcommand("subcom2");
@ -1018,7 +1018,7 @@ TEST_F(TApp, IniSubcommandMultipleSections) {
out << "val=4" << std::endl;
}
int one = 0, two = 0, three = 0, four = 0;
int one{0}, two{0}, three{0}, four{0};
app.add_option("--val", one);
auto subcom = app.add_subcommand("subcom");
auto subcom2 = app.add_subcommand("subcom2");
@ -1062,7 +1062,7 @@ TEST_F(TApp, DuplicateSubcommandCallbacks) {
}
auto foo = app.add_subcommand("foo");
int count = 0;
int count{0};
foo->callback([&count]() { ++count; });
foo->immediate_callback();
EXPECT_TRUE(foo->get_immediate_callback());
@ -1092,7 +1092,7 @@ TEST_F(TApp, IniConfigurable) {
TempFile tmpini{"TestIniTmp.ini"};
app.set_config("--config", tmpini);
bool value;
bool value{false};
app.add_flag("--val", value)->configurable(true);
{
@ -1110,7 +1110,7 @@ TEST_F(TApp, IniNotConfigurable) {
TempFile tmpini{"TestIniTmp.ini"};
app.set_config("--config", tmpini);
bool value;
bool value{false};
app.add_flag("--val", value)->configurable(false);
{
@ -1165,7 +1165,7 @@ TEST_F(TApp, IniFlagConvertFailure) {
out << "flag=moobook" << std::endl;
}
run();
bool result;
bool result{false};
auto *opt = app.get_option("--flag");
EXPECT_THROW(opt->results(result), CLI::ConversionError);
std::string res;
@ -1177,7 +1177,7 @@ TEST_F(TApp, IniFlagNumbers) {
TempFile tmpini{"TestIniTmp.ini"};
bool boo;
bool boo{false};
app.add_flag("--flag", boo);
app.set_config("--config", tmpini);
@ -1194,7 +1194,7 @@ TEST_F(TApp, IniFlagDual) {
TempFile tmpini{"TestIniTmp.ini"};
bool boo;
bool boo{false};
app.add_flag("--flag", boo);
app.set_config("--config", tmpini);
@ -1210,7 +1210,7 @@ TEST_F(TApp, IniFlagText) {
TempFile tmpini{"TestIniTmp.ini"};
bool flag1, flag2, flag3, flag4;
bool flag1{false}, flag2{false}, flag3{false}, flag4{false};
app.add_flag("--flag1", flag1);
app.add_flag("--flag2", flag2);
app.add_flag("--flag3", flag3);
@ -1246,8 +1246,8 @@ TEST_F(TApp, IniFlags) {
out << "five" << std::endl;
}
int two;
bool three, four, five;
int two{0};
bool three{false}, four{false}, five{false};
app.add_flag("--two", two);
app.add_flag("--three", three);
app.add_flag("--four", four);
@ -1274,8 +1274,8 @@ TEST_F(TApp, IniFalseFlags) {
out << "five" << std::endl;
}
int two;
bool three, four, five;
int two{0};
bool three{false}, four{false}, five{false};
app.add_flag("--two", two);
app.add_flag("--three", three);
app.add_flag("--four", four);
@ -1302,8 +1302,8 @@ TEST_F(TApp, IniFalseFlagsDef) {
out << "five" << std::endl;
}
int two;
bool three, four, five;
int two{0};
bool three{false}, four{false}, five{false};
app.add_flag("--two{false}", two);
app.add_flag("--three", three);
app.add_flag("!--four", four);
@ -1329,8 +1329,8 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideError) {
out << "five" << std::endl;
}
int two;
bool four, five;
int two{0};
bool four{false}, five{false};
app.add_flag("--two{false}", two)->disable_flag_override();
app.add_flag("!--four", four);
app.add_flag("--five", five);
@ -1350,7 +1350,7 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideSuccess) {
out << "val=15" << std::endl;
}
int two, four, val;
int two{0}, four{0}, val{0};
app.add_flag("--two{2}", two)->disable_flag_override();
app.add_flag("--four{4}", four)->disable_flag_override();
app.add_flag("--val", val);
@ -1364,7 +1364,7 @@ TEST_F(TApp, IniFalseFlagsDefDisableOverrideSuccess) {
TEST_F(TApp, IniOutputSimple) {
int v;
int v{0};
app.add_option("--simple", v);
args = {"--simple=3"};
@ -1377,7 +1377,7 @@ TEST_F(TApp, IniOutputSimple) {
TEST_F(TApp, IniOutputNoConfigurable) {
int v1, v2;
int v1{0}, v2{0};
app.add_option("--simple", v1);
app.add_option("--noconf", v2)->configurable(false);
@ -1433,7 +1433,7 @@ TEST_F(TApp, IniOutputGroups) {
TEST_F(TApp, IniOutputHiddenOptions) {
std::string flag1 = "flagnr1";
std::string flag2 = "flagnr2";
double val = 12.7;
double val{12.7};
const std::string description1 = "First description.";
const std::string description2 = "Second description.";
app.add_flag("--" + flag1, description1)->group("group1");
@ -1470,7 +1470,7 @@ TEST_F(TApp, IniOutputMultiLineDescription) {
TEST_F(TApp, IniOutputOptionGroup) {
std::string flag1 = "flagnr1";
std::string flag2 = "flagnr2";
double val = 12.7;
double val{12.7};
const std::string description1 = "First description.";
const std::string description2 = "Second description.";
app.add_flag("--" + flag1, description1)->group("group1");
@ -1539,7 +1539,7 @@ TEST_F(TApp, IniOutputVectorCustom) {
TEST_F(TApp, IniOutputFlag) {
int v, q;
int v{0}, q{0};
app.add_option("--simple", v);
app.add_flag("--nothing");
app.add_flag("--onething");
@ -1561,7 +1561,7 @@ TEST_F(TApp, IniOutputFlag) {
TEST_F(TApp, IniOutputSet) {
int v;
int v{0};
app.add_option("--simple", v)->check(CLI::IsMember({1, 2, 3}));
args = {"--simple=2"};
@ -1574,7 +1574,7 @@ TEST_F(TApp, IniOutputSet) {
TEST_F(TApp, IniOutputDefault) {
int v = 7;
int v{7};
app.add_option("--simple", v, "", true);
run();
@ -1726,7 +1726,7 @@ TEST_F(TApp, StopReadingConfigOnClear) {
out << "volume=1" << std::endl;
}
int volume = 0;
int volume{0};
app.add_option("--volume", volume, "volume1");
run();

View File

@ -164,12 +164,12 @@ TEST_F(TApp, MultipleSubcomNoMatchingInplaceUnderscore2) {
TEST_F(TApp, IncorrectConstructionFlagPositional1) { EXPECT_THROW(app.add_flag("cat"), CLI::IncorrectConstruction); }
TEST_F(TApp, IncorrectConstructionFlagPositional2) {
int x;
int x{0};
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
}
TEST_F(TApp, IncorrectConstructionFlagPositional3) {
bool x;
bool x{false};
EXPECT_THROW(app.add_flag("cat", x), CLI::IncorrectConstruction);
}
@ -220,7 +220,7 @@ TEST_F(TApp, CheckName) {
auto long2 = app.add_flag("--Long2");
auto short1 = app.add_flag("-a");
auto short2 = app.add_flag("-B");
int x, y;
int x{0}, y{0};
auto pos1 = app.add_option("pos1", x);
auto pos2 = app.add_option("pOs2", y);
@ -248,7 +248,7 @@ TEST_F(TApp, CheckNameNoCase) {
auto long2 = app.add_flag("--Long2")->ignore_case();
auto short1 = app.add_flag("-a")->ignore_case();
auto short2 = app.add_flag("-B")->ignore_case();
int x, y;
int x{0}, y{0};
auto pos1 = app.add_option("pos1", x)->ignore_case();
auto pos2 = app.add_option("pOs2", y)->ignore_case();
@ -275,7 +275,7 @@ TEST_F(TApp, CheckNameNoUnderscore) {
auto long1 = app.add_flag("--longoption1")->ignore_underscore();
auto long2 = app.add_flag("--long_option2")->ignore_underscore();
int x, y;
int x{0}, y{0};
auto pos1 = app.add_option("pos_option_1", x)->ignore_underscore();
auto pos2 = app.add_option("posoption2", y)->ignore_underscore();
@ -306,7 +306,7 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
auto long1 = app.add_flag("--LongoptioN1")->ignore_underscore()->ignore_case();
auto long2 = app.add_flag("--long_Option2")->ignore_case()->ignore_underscore();
int x, y;
int x{0}, y{0};
auto pos1 = app.add_option("pos_Option_1", x)->ignore_underscore()->ignore_case();
auto pos2 = app.add_option("posOption2", y)->ignore_case()->ignore_underscore();
@ -334,7 +334,7 @@ TEST_F(TApp, CheckNameNoCaseNoUnderscore) {
}
TEST_F(TApp, PreSpaces) {
int x;
int x{0};
auto myapp = app.add_option(" -a, --long, other", x);
EXPECT_TRUE(myapp->check_lname("long"));
@ -343,7 +343,7 @@ TEST_F(TApp, PreSpaces) {
}
TEST_F(TApp, AllSpaces) {
int x;
int x{0};
auto myapp = app.add_option(" -a , --long , other ", x);
EXPECT_TRUE(myapp->check_lname("long"));
@ -355,7 +355,7 @@ TEST_F(TApp, OptionFromDefaults) {
app.option_defaults()->required();
// Options should remember defaults
int x;
int x{0};
auto opt = app.add_option("--simple", x);
EXPECT_TRUE(opt->get_required());
@ -411,7 +411,7 @@ TEST_F(TApp, OptionFromDefaultsSubcommands) {
}
TEST_F(TApp, GetNameCheck) {
int x;
int x{0};
auto a = app.add_flag("--that");
auto b = app.add_flag("-x");
auto c = app.add_option("pos", x);
@ -523,7 +523,7 @@ TEST_F(TApp, SubcommandMinMax) {
}
TEST_F(TApp, GetOptionList) {
int two;
int two{0};
auto flag = app.add_flag("--one");
auto opt = app.add_option("--two", two);
@ -704,7 +704,7 @@ TEST(ValidatorTests, ValidatorDefaults) {
class Unstreamable {
private:
int x_ = -1;
int x_{-1};
public:
Unstreamable() = default;

View File

@ -49,7 +49,7 @@ TEST(Formatter, OptCustomize) {
optfmt->label("REQUIRED", "(MUST HAVE)");
app.formatter(optfmt);
int v;
int v{0};
app.add_option("--opt", v, "Something")->required();
std::string help = app.help();
@ -69,7 +69,7 @@ TEST(Formatter, OptCustomizeSimple) {
app.get_formatter()->column_width(25);
app.get_formatter()->label("REQUIRED", "(MUST HAVE)");
int v;
int v{0};
app.add_option("--opt", v, "Something")->required();
std::string help = app.help();
@ -89,10 +89,10 @@ TEST(Formatter, FalseFlagExample) {
app.get_formatter()->column_width(25);
app.get_formatter()->label("REQUIRED", "(MUST HAVE)");
int v;
int v{0};
app.add_flag("--opt,!--no_opt", v, "Something");
bool flag;
bool flag{false};
app.add_flag("!-O,--opt2,--no_opt2{false}", flag, "Something else");
std::string help = app.help();
@ -180,7 +180,7 @@ TEST(Formatter, NamelessSubInGroup) {
CLI::App *sub = app.add_subcommand("", "This subcommand");
CLI::App *sub2 = app.add_subcommand("sub2", "subcommand2");
sub->add_flag("--insub", "MyFlag");
int val;
int val{0};
sub2->add_option("pos", val, "positional");
sub->group("group1");
sub2->group("group1");

View File

@ -330,7 +330,7 @@ TEST(THelp, Needs) {
TEST(THelp, NeedsPositional) {
CLI::App app{"My prog"};
int x, y;
int x{0}, y{0};
CLI::Option *op1 = app.add_option("op1", x, "one");
app.add_option("op2", y, "two")->needs(op1);
@ -355,7 +355,7 @@ TEST(THelp, Excludes) {
TEST(THelp, ExcludesPositional) {
CLI::App app{"My prog"};
int x, y;
int x{0}, y{0};
CLI::Option *op1 = app.add_option("op1", x);
app.add_option("op2", y)->excludes(op1);
@ -381,7 +381,7 @@ TEST(THelp, ManualSetters) {
CLI::App app{"My prog"};
int x = 1;
int x{1};
CLI::Option *op1 = app.add_option("--op", x);
op1->default_str("12");
@ -418,7 +418,7 @@ TEST(THelp, ManualSetterOverFunction) {
CLI::App app{"My prog"};
int x = 1;
int x{1};
CLI::Option *op1 = app.add_option("--op1", x)->check(CLI::IsMember({1, 2}));
CLI::Option *op2 = app.add_option("--op2", x)->transform(CLI::IsMember({1, 2}));
@ -650,7 +650,7 @@ TEST(THelp, CustomHelp) {
TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) {
CLI::App app;
int i;
int i{0};
const std::string first{"first line"};
const std::string second{"second line"};
app.add_option("-i,--int", i, first + "\n" + second);
@ -663,7 +663,7 @@ TEST(THelp, NextLineShouldBeAlignmentInMultilineDescription) {
TEST(THelp, NiceName) {
CLI::App app;
int x;
int x{0};
auto long_name = app.add_option("-s,--long,-q,--other,that", x);
auto short_name = app.add_option("more,-x,-y", x);
auto positional = app.add_option("posit", x);
@ -878,7 +878,7 @@ TEST(THelp, SetDescriptionAfterCreation) {
TEST(THelp, AccessOptionDescription) {
CLI::App app{};
int x;
int x{0};
auto opt = app.add_option("-a,--alpha", x, "My description goes here");
EXPECT_EQ(opt->get_description(), "My description goes here");
@ -887,7 +887,7 @@ TEST(THelp, AccessOptionDescription) {
TEST(THelp, SetOptionDescriptionAfterCreation) {
CLI::App app{};
int x;
int x{0};
auto opt = app.add_option("-a,--alpha", x);
opt->description("My description goes here");
@ -898,7 +898,7 @@ TEST(THelp, SetOptionDescriptionAfterCreation) {
TEST(THelp, CleanNeeds) {
CLI::App app;
int x;
int x{0};
auto a_name = app.add_option("-a,--alpha", x);
app.add_option("-b,--boo", x)->needs(a_name);
@ -910,7 +910,7 @@ TEST(THelp, CleanNeeds) {
TEST(THelp, RequiredPrintout) {
CLI::App app;
int x;
int x{0};
app.add_option("-a,--alpha", x)->required();
EXPECT_THAT(app.help(), HasSubstr(" REQUIRED"));
@ -936,8 +936,8 @@ TEST(THelp, ValidatorsText) {
CLI::App app;
std::string filename;
int x;
unsigned int y;
int x{0};
unsigned int y{0};
app.add_option("--f1", filename)->check(CLI::ExistingFile);
app.add_option("--f3", x)->check(CLI::Range(1, 4));
app.add_option("--f4", y)->check(CLI::Range(12));
@ -1032,7 +1032,7 @@ TEST(THelp, ChangingSet) {
CLI::App app;
std::set<int> vals{1, 2, 3};
int val;
int val{0};
app.add_option("--val", val)->check(CLI::IsMember(&vals));
std::string help = app.help();
@ -1053,7 +1053,7 @@ TEST(THelp, ChangingSetDefaulted) {
CLI::App app;
std::set<int> vals{1, 2, 3};
int val = 2;
int val{2};
app.add_option("--val", val, "")->check(CLI::IsMember(&vals))->capture_default_str();
std::string help = app.help();

View File

@ -105,7 +105,7 @@ TEST(String, InvalidName) {
}
TEST(StringTools, Modify) {
int cnt = 0;
int cnt{0};
std::string newString = CLI::detail::find_and_modify("======", "=", [&cnt](std::string &str, std::size_t index) {
if((++cnt) % 2 == 0) {
str[index] = ':';
@ -444,8 +444,8 @@ TEST(Validators, ProgramNameSplit) {
}
TEST(CheckedMultiply, Int) {
int a = 10;
int b = -20;
int a{10};
int b{-20};
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_EQ(a, -200);
@ -562,55 +562,55 @@ TEST(CheckedMultiply, SizeT) {
}
TEST(CheckedMultiply, Float) {
float a = 10;
float b = 20;
float a{10.0F};
float b{20.0F};
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, 200);
a = 0;
b = 20;
a = 0.0F;
b = 20.0F;
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, 0);
a = INFINITY;
b = 20;
b = 20.0F;
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, INFINITY);
a = 2;
a = 2.0F;
b = -INFINITY;
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, -INFINITY);
a = std::numeric_limits<float>::max() / 100;
b = 1;
a = std::numeric_limits<float>::max() / 100.0F;
b = 1.0F;
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100);
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F);
a = std::numeric_limits<float>::max() / 100;
b = 99;
a = std::numeric_limits<float>::max() / 100.0F;
b = 99.0F;
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100 * 99);
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F * 99.0F);
a = std::numeric_limits<float>::max() / 100;
a = std::numeric_limits<float>::max() / 100.0F;
b = 101;
ASSERT_FALSE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100);
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F);
a = std::numeric_limits<float>::max() / 100;
a = std::numeric_limits<float>::max() / 100.0F;
b = -99;
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100 * -99);
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F * -99.0F);
a = std::numeric_limits<float>::max() / 100;
a = std::numeric_limits<float>::max() / 100.0F;
b = -101;
ASSERT_FALSE(CLI::detail::checked_multiply(a, b));
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100);
ASSERT_FLOAT_EQ(a, std::numeric_limits<float>::max() / 100.0F);
}
TEST(CheckedMultiply, Double) {
double a = 10;
double b = 20;
double a{10.0F};
double b{20.0F};
ASSERT_TRUE(CLI::detail::checked_multiply(a, b));
ASSERT_DOUBLE_EQ(a, 200);
@ -1014,7 +1014,7 @@ TEST(Types, LexicalCastEnum) {
EXPECT_FALSE(CLI::detail::lexical_cast("invalid", output));
enum class t2 : std::uint64_t { enum1 = 65, enum2 = 45667, enum3 = 9999999999999 };
t2 output2;
t2 output2{t2::enum2};
EXPECT_TRUE(CLI::detail::lexical_cast("65", output2));
EXPECT_EQ(output2, t2::enum1);
@ -1026,7 +1026,7 @@ TEST(Types, LexicalCastEnum) {
TEST(Types, LexicalConversionDouble) {
CLI::results_t input = {"9.12"};
long double x;
long double x{0.0};
bool res = CLI::detail::lexical_conversion<long double, double>(input, x);
EXPECT_TRUE(res);
EXPECT_FLOAT_EQ((float)9.12, (float)x);
@ -1038,7 +1038,7 @@ TEST(Types, LexicalConversionDouble) {
TEST(Types, LexicalConversionDoubleTuple) {
CLI::results_t input = {"9.12"};
std::tuple<double> x;
std::tuple<double> x{0.0};
bool res = CLI::detail::lexical_conversion<decltype(x), decltype(x)>(input, x);
EXPECT_TRUE(res);
EXPECT_DOUBLE_EQ(9.12, std::get<0>(x));
@ -1073,7 +1073,7 @@ static_assert(CLI::detail::is_tuple_like<std::tuple<double, int, double>>::value
TEST(Types, LexicalConversionTuple2) {
CLI::results_t input = {"9.12", "19"};
std::tuple<double, int> x;
std::tuple<double, int> x{0.0, 0};
static_assert(CLI::detail::is_tuple_like<decltype(x)>::value,
"tuple type must have is_tuple_like trait to be true");
bool res = CLI::detail::lexical_conversion<decltype(x), decltype(x)>(input, x);

View File

@ -269,7 +269,7 @@ template <> bool lexical_cast<std::complex<double>>(const std::string &input, st
R"(([+-]?(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)\s*([+-]\s*(\d+(\.\d+)?|\.\d+)([eE][+-]?\d+)?)[ji]*)");
std::smatch m;
double x = 0.0, y = 0.0;
double x{0.0}, y{0.0};
bool worked;
std::regex_search(input, m, creg);
if(m.size() == 9) {

View File

@ -23,11 +23,11 @@ TEST_F(TApp, BasicOptionGroup) {
TEST_F(TApp, BasicOptionGroupExact) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(1);
args = {"--test1", "5"};
@ -47,11 +47,11 @@ TEST_F(TApp, BasicOptionGroupExact) {
TEST_F(TApp, BasicOptionGroupExactTooMany) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(10);
args = {"--test1", "5"};
@ -60,11 +60,11 @@ TEST_F(TApp, BasicOptionGroupExactTooMany) {
TEST_F(TApp, BasicOptionGroupMinMax) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(1, 1);
args = {"--test1", "5"};
@ -84,11 +84,11 @@ TEST_F(TApp, BasicOptionGroupMinMax) {
TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(1, 2);
args = {"--test1", "5"};
@ -112,11 +112,11 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferent) {
TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(2, 1);
EXPECT_EQ(ogroup->get_require_option_min(), 2u);
@ -144,7 +144,7 @@ TEST_F(TApp, BasicOptionGroupMinMaxDifferentReversed) {
TEST_F(TApp, BasicOptionGroupMax) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
@ -168,11 +168,11 @@ TEST_F(TApp, BasicOptionGroupMax) {
TEST_F(TApp, BasicOptionGroupMax1) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(-1);
args = {"--test1", "5"};
@ -192,11 +192,11 @@ TEST_F(TApp, BasicOptionGroupMax1) {
TEST_F(TApp, BasicOptionGroupMin) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option();
@ -213,11 +213,11 @@ TEST_F(TApp, BasicOptionGroupMin) {
TEST_F(TApp, BasicOptionGroupExact2) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(2);
@ -237,11 +237,11 @@ TEST_F(TApp, BasicOptionGroupExact2) {
TEST_F(TApp, BasicOptionGroupMin2) {
auto ogroup = app.add_option_group("clusters");
int res;
int res{0};
ogroup->add_option("--test1", res);
ogroup->add_option("--test2", res);
ogroup->add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
ogroup->require_option(2, 0);
@ -258,11 +258,11 @@ TEST_F(TApp, BasicOptionGroupMin2) {
TEST_F(TApp, BasicOptionGroupMinMoved) {
int res;
int res{0};
auto opt1 = app.add_option("--test1", res);
auto opt2 = app.add_option("--test2", res);
auto opt3 = app.add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
auto ogroup = app.add_option_group("clusters");
@ -287,11 +287,11 @@ TEST_F(TApp, BasicOptionGroupMinMoved) {
TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
int res;
int res{0};
auto opt1 = app.add_option("--test1", res);
auto opt2 = app.add_option("--test2", res);
auto opt3 = app.add_option("--test3", res);
int val2;
int val2{0};
app.add_option("--option", val2);
auto ogroup = app.add_option_group("clusters");
@ -315,10 +315,10 @@ TEST_F(TApp, BasicOptionGroupMinMovedAsGroup) {
TEST_F(TApp, BasicOptionGroupAddFailures) {
int res;
int res{0};
auto opt1 = app.add_option("--test1", res);
app.set_config("--config");
int val2;
int val2{0};
app.add_option("--option", val2);
auto ogroup = app.add_option_group("clusters");
@ -341,10 +341,10 @@ TEST_F(TApp, BasicOptionGroupAddFailures) {
TEST_F(TApp, BasicOptionGroupScrewedUpMove) {
int res;
int res{0};
auto opt1 = app.add_option("--test1", res);
auto opt2 = app.add_option("--test2", res);
int val2;
int val2{0};
app.add_option("--option", val2);
auto ogroup = app.add_option_group("clusters");

View File

@ -26,7 +26,7 @@ static_assert(CLI::detail::pair_adaptor<std::map<int, int>>::value == true, "Sho
static_assert(CLI::detail::pair_adaptor<std::vector<std::pair<int, int>>>::value == true, "Should have pairs");
TEST_F(TApp, SimpleMaps) {
int value;
int value{0};
std::map<std::string, int> map = {{"one", 1}, {"two", 2}};
auto opt = app.add_option("-s,--set", value)->transform(CLI::Transformer(map));
args = {"-s", "one"};
@ -319,7 +319,7 @@ TEST_F(TApp, SetFromCharStarArrayVector) {
}
TEST_F(TApp, OtherTypeSets) {
int value;
int value{0};
std::vector<int> set = {2, 3, 4};
auto opt = app.add_option("--set", value)->check(CLI::IsMember(set));
args = {"--set", "3"};
@ -353,7 +353,7 @@ TEST_F(TApp, OtherTypeSets) {
}
TEST_F(TApp, NumericalSets) {
int value;
int value{0};
auto opt = app.add_option("-s,--set", value)->check(CLI::IsMember{std::set<int>({1, 2, 3})});
args = {"-s", "1"};
run();
@ -366,7 +366,7 @@ TEST_F(TApp, NumericalSets) {
// Converted original set tests
TEST_F(TApp, SetWithDefaults) {
int someint = 2;
int someint{2};
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
args = {"-a1", "-a2"};
@ -375,7 +375,7 @@ TEST_F(TApp, SetWithDefaults) {
}
TEST_F(TApp, SetWithDefaultsConversion) {
int someint = 2;
int someint{2};
app.add_option("-a", someint, "", true)->check(CLI::IsMember({1, 2, 3, 4}));
args = {"-a", "hi"};
@ -442,7 +442,7 @@ TEST_F(TApp, InCaselessSetWithDefault) {
TEST_F(TApp, InIntSet) {
int choice;
int choice{0};
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
args = {"--quick", "2"};
@ -456,7 +456,7 @@ TEST_F(TApp, InIntSet) {
TEST_F(TApp, InIntSetWindows) {
int choice;
int choice{0};
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
app.allow_windows_style_options();
args = {"/q", "2"};
@ -473,7 +473,7 @@ TEST_F(TApp, InIntSetWindows) {
TEST_F(TApp, FailSet) {
int choice;
int choice{0};
app.add_option("-q,--quick", choice)->check(CLI::IsMember({1, 2, 3}));
args = {"--quick", "3", "--quick=2"};
@ -485,7 +485,7 @@ TEST_F(TApp, FailSet) {
TEST_F(TApp, FailMutableSet) {
int choice;
int choice{0};
auto vals = std::shared_ptr<std::set<int>>(new std::set<int>({1, 2, 3}));
app.add_option("-q,--quick", choice)->check(CLI::IsMember(vals));
app.add_option("-s,--slow", choice, "", true)->check(CLI::IsMember(vals));

View File

@ -192,7 +192,7 @@ TEST_F(TApp, DuplicateSubcommands) {
TEST_F(TApp, DuplicateSubcommandCallbacks) {
auto foo = app.add_subcommand("foo");
int count = 0;
int count{0};
foo->callback([&count]() { ++count; });
foo->immediate_callback();
EXPECT_TRUE(foo->get_immediate_callback());
@ -208,7 +208,7 @@ TEST_F(TApp, DuplicateSubcommandCallbacks) {
TEST_F(TApp, DuplicateSubcommandCallbacksValues) {
auto foo = app.add_subcommand("foo");
int val;
int val{0};
foo->add_option("--val", val);
std::vector<int> vals;
foo->callback([&vals, &val]() { vals.push_back(val); });
@ -231,7 +231,7 @@ TEST_F(TApp, Callbacks) {
auto sub1 = app.add_subcommand("sub1");
sub1->callback([]() { throw CLI::Success(); });
auto sub2 = app.add_subcommand("sub2");
bool val = false;
bool val{false};
sub2->callback([&val]() { val = true; });
args = {"sub2"};
@ -353,7 +353,7 @@ TEST_F(TApp, RuntimeErrorInCallback) {
}
TEST_F(TApp, NoFallThroughOpts) {
int val = 1;
int val{1};
app.add_option("--val", val);
app.add_subcommand("sub");
@ -363,7 +363,7 @@ TEST_F(TApp, NoFallThroughOpts) {
}
TEST_F(TApp, NoFallThroughPositionals) {
int val = 1;
int val{1};
app.add_option("val", val);
app.add_subcommand("sub");
@ -373,7 +373,7 @@ TEST_F(TApp, NoFallThroughPositionals) {
}
TEST_F(TApp, NoFallThroughOptsWithTerminator) {
int val = 1;
int val{1};
app.add_option("--val", val);
app.add_subcommand("sub");
@ -384,7 +384,7 @@ TEST_F(TApp, NoFallThroughOptsWithTerminator) {
}
TEST_F(TApp, NoFallThroughPositionalsWithTerminator) {
int val = 1;
int val{1};
app.add_option("val", val);
app.add_subcommand("sub");
@ -402,7 +402,7 @@ TEST_F(TApp, NoFallThroughPositionalsWithTerminator) {
TEST_F(TApp, NamelessSubComPositionals) {
auto sub = app.add_subcommand();
int val = 1;
int val{1};
sub->add_option("val", val);
args = {"2"};
@ -515,7 +515,7 @@ TEST_F(TApp, Nameless4LayerDeepMulti) {
TEST_F(TApp, FallThroughRegular) {
app.fallthrough();
int val = 1;
int val{1};
app.add_option("--val", val);
app.add_subcommand("sub");
@ -527,7 +527,7 @@ TEST_F(TApp, FallThroughRegular) {
TEST_F(TApp, FallThroughShort) {
app.fallthrough();
int val = 1;
int val{1};
app.add_option("-v", val);
app.add_subcommand("sub");
@ -539,7 +539,7 @@ TEST_F(TApp, FallThroughShort) {
TEST_F(TApp, FallThroughPositional) {
app.fallthrough();
int val = 1;
int val{1};
app.add_option("val", val);
app.add_subcommand("sub");
@ -551,7 +551,7 @@ TEST_F(TApp, FallThroughPositional) {
TEST_F(TApp, FallThroughEquals) {
app.fallthrough();
int val = 1;
int val{1};
app.add_option("--val", val);
app.add_subcommand("sub");
@ -563,7 +563,7 @@ TEST_F(TApp, FallThroughEquals) {
TEST_F(TApp, EvilParseFallthrough) {
app.fallthrough();
int val1 = 0, val2 = 0;
int val1{0}, val2{0};
app.add_option("--val1", val1);
auto sub = app.add_subcommand("sub");
@ -579,7 +579,7 @@ TEST_F(TApp, EvilParseFallthrough) {
TEST_F(TApp, CallbackOrdering) {
app.fallthrough();
int val = 1, sub_val = 0;
int val{1}, sub_val{0};
app.add_option("--val", val);
auto sub = app.add_subcommand("sub");
@ -598,7 +598,7 @@ TEST_F(TApp, CallbackOrdering) {
TEST_F(TApp, CallbackOrderingImmediate) {
app.fallthrough();
int val = 1, sub_val = 0;
int val{1}, sub_val{0};
app.add_option("--val", val);
auto sub = app.add_subcommand("sub")->immediate_callback();
@ -617,7 +617,7 @@ TEST_F(TApp, CallbackOrderingImmediate) {
TEST_F(TApp, CallbackOrderingImmediateMain) {
app.fallthrough();
int val = 0, sub_val = 0;
int val{0}, sub_val{0};
auto sub = app.add_subcommand("sub");
sub->callback([&val, &sub_val]() {
@ -814,9 +814,9 @@ struct SubcommandProgram : public TApp {
CLI::App *start{nullptr};
CLI::App *stop{nullptr};
int dummy{};
int dummy{0};
std::string file{};
int count{};
int count{0};
SubcommandProgram(const SubcommandProgram &) = delete;
SubcommandProgram &operator=(const SubcommandProgram &) = delete;
@ -1360,7 +1360,7 @@ TEST_F(ManySubcommands, SubcommandNeedsOptions) {
}
TEST_F(ManySubcommands, SubcommandNeedsOptionsCallbackOrdering) {
int count = 0;
int count{0};
auto opt = app.add_flag("--subactive");
app.add_flag("--flag1");
sub1->needs(opt);
@ -1461,7 +1461,7 @@ TEST_F(ManySubcommands, SubcommandTriggeredOn) {
}
TEST_F(TApp, UnnamedSub) {
double val;
double val{0.0};
auto sub = app.add_subcommand("", "empty name");
auto opt = sub->add_option("-v,--value", val);
args = {"-v", "4.56"};
@ -1481,7 +1481,7 @@ TEST_F(TApp, UnnamedSub) {
}
TEST_F(TApp, UnnamedSubMix) {
double val, val2, val3;
double val{0.0}, val2{0.0}, val3{0.0};
app.add_option("-t", val2);
auto sub1 = app.add_subcommand("", "empty name");
sub1->add_option("-v,--value", val);
@ -1497,7 +1497,7 @@ TEST_F(TApp, UnnamedSubMix) {
}
TEST_F(TApp, UnnamedSubMixExtras) {
double val, val2;
double val{0.0}, val2{0.0};
app.add_option("-t", val2);
auto sub = app.add_subcommand("", "empty name");
sub->add_option("-v,--value", val);
@ -1511,7 +1511,7 @@ TEST_F(TApp, UnnamedSubMixExtras) {
}
TEST_F(TApp, UnnamedSubNoExtras) {
double val, val2;
double val{0.0}, val2{0.0};
app.add_option("-t", val2);
auto sub = app.add_subcommand();
sub->add_option("-v,--value", val);
@ -1524,7 +1524,7 @@ TEST_F(TApp, UnnamedSubNoExtras) {
}
TEST_F(TApp, SubcommandAlias) {
double val;
double val{0.0};
auto sub = app.add_subcommand("sub1");
sub->alias("sub2");
sub->alias("sub3");
@ -1552,7 +1552,7 @@ TEST_F(TApp, SubcommandAlias) {
}
TEST_F(TApp, SubcommandAliasIgnoreCaseUnderscore) {
double val;
double val{0.0};
auto sub = app.add_subcommand("sub1");
sub->alias("sub2");
sub->alias("sub3");
@ -1595,7 +1595,7 @@ TEST_F(TApp, SubcommandAliasIgnoreCaseUnderscore) {
}
TEST_F(TApp, OptionGroupAlias) {
double val;
double val{0.0};
auto sub = app.add_option_group("sub1");
sub->alias("sub2");
sub->alias("sub3");
@ -1694,7 +1694,7 @@ TEST_F(TApp, AliasErrorsInOptionGroup) {
}
TEST(SharedSubTests, SharedSubcommand) {
double val, val2, val3, val4;
double val{0.0}, val2{0.0}, val3{0.0}, val4{0.0};
CLI::App app1{"test program1"};
app1.add_option("-t", val2);
@ -1724,7 +1724,7 @@ TEST(SharedSubTests, SharedSubcommand) {
}
TEST(SharedSubTests, SharedSubIndependent) {
double val, val2, val4;
double val{0.0}, val2{0.0}, val4{0.0};
CLI::App_p app1 = std::make_shared<CLI::App>("test program1");
app1->allow_extras();
app1->add_option("-t", val2);
@ -1752,7 +1752,7 @@ TEST(SharedSubTests, SharedSubIndependent) {
}
TEST(SharedSubTests, SharedSubIndependentReuse) {
double val, val2, val4;
double val{0.0}, val2{0.0}, val4{0.0};
CLI::App_p app1 = std::make_shared<CLI::App>("test program1");
app1->allow_extras();
app1->add_option("-t", val2);

View File

@ -14,7 +14,7 @@
#endif
TEST_F(TApp, SimpleTransform) {
int value;
int value{0};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", std::string("1")}}));
args = {"-s", "one"};
run();
@ -24,7 +24,7 @@ TEST_F(TApp, SimpleTransform) {
}
TEST_F(TApp, SimpleTransformInitList) {
int value;
int value{0};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}}));
args = {"-s", "one"};
run();
@ -34,7 +34,7 @@ TEST_F(TApp, SimpleTransformInitList) {
}
TEST_F(TApp, SimpleNumericalTransform) {
int value;
int value{0};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer(CLI::TransformPairs<int>{{"one", 1}}));
args = {"-s", "one"};
run();
@ -45,7 +45,7 @@ TEST_F(TApp, SimpleNumericalTransform) {
TEST_F(TApp, EnumTransform) {
enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
test value;
test value{test::val2};
auto opt = app.add_option("-s", value)
->transform(CLI::Transformer(
CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}}));
@ -74,7 +74,7 @@ TEST_F(TApp, EnumTransform) {
TEST_F(TApp, EnumCheckedTransform) {
enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
test value;
test value{test::val1};
auto opt = app.add_option("-s", value)
->transform(CLI::CheckedTransformer(
CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}}));
@ -141,7 +141,7 @@ TEST_F(TApp, EnumCheckedDefaultTransformCallback) {
}
TEST_F(TApp, SimpleTransformFn) {
int value;
int value{0};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer({{"one", "1"}}, CLI::ignore_case));
args = {"-s", "ONE"};
run();
@ -164,7 +164,7 @@ TEST_F(TApp, StringViewTransformFn) {
#endif
TEST_F(TApp, SimpleNumericalTransformFn) {
int value;
int value{0};
auto opt =
app.add_option("-s", value)
->transform(CLI::Transformer(std::vector<std::pair<std::string, int>>{{"one", 1}}, CLI::ignore_case));
@ -177,7 +177,7 @@ TEST_F(TApp, SimpleNumericalTransformFn) {
TEST_F(TApp, SimpleNumericalTransformFnVector) {
std::vector<std::pair<std::string, int>> conversions{{"one", 1}, {"two", 2}};
int value;
int value{0};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case));
args = {"-s", "ONe"};
run();
@ -191,7 +191,7 @@ TEST_F(TApp, SimpleNumericalTransformFnArray) {
conversions[0] = std::make_pair(std::string("one"), 1);
conversions[1] = std::make_pair(std::string("two"), 2);
int value;
int value{0};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer(conversions, CLI::ignore_case));
args = {"-s", "ONe"};
run();
@ -207,7 +207,7 @@ TEST_F(TApp, SimpleNumericalTransformFnconstexprArray) {
constexpr std::pair<const char *, int> p2{"two", 2};
constexpr std::array<std::pair<const char *, int>, 2> conversions_c{{p1, p2}};
int value;
int value{0};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&conversions_c, CLI::ignore_case));
args = {"-s", "ONe"};
run();
@ -225,7 +225,7 @@ TEST_F(TApp, SimpleNumericalTransformFnconstexprArray) {
TEST_F(TApp, EnumTransformFn) {
enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
test value;
test value{test::val2};
auto opt = app.add_option("-s", value)
->transform(CLI::Transformer(
CLI::TransformPairs<test>{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}},
@ -252,7 +252,7 @@ TEST_F(TApp, EnumTransformFn) {
TEST_F(TApp, EnumTransformFnMap) {
enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17 };
std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}};
test value;
test value{test::val3};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore));
args = {"-s", "val_1"};
run();
@ -275,7 +275,7 @@ TEST_F(TApp, EnumTransformFnMap) {
TEST_F(TApp, EnumTransformFnPtrMap) {
enum class test : std::int16_t { val1 = 3, val2 = 4, val3 = 17, val4 = 37 };
std::map<std::string, test> map{{"val1", test::val1}, {"val2", test::val2}, {"val3", test::val3}};
test value;
test value{test::val2};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer(&map, CLI::ignore_case, CLI::ignore_underscore));
args = {"-s", "val_1"};
run();
@ -307,7 +307,7 @@ TEST_F(TApp, EnumTransformFnSharedPtrMap) {
mp["val2"] = test::val2;
mp["val3"] = test::val3;
test value;
test value{test::val2};
auto opt = app.add_option("-s", value)->transform(CLI::Transformer(map, CLI::ignore_case, CLI::ignore_underscore));
args = {"-s", "val_1"};
run();
@ -565,7 +565,7 @@ TEST_F(TApp, NumberWithUnitCorrecltySplitNumber) {
TEST_F(TApp, NumberWithUnitFloatTest) {
std::map<std::string, double> mapping{{"a", 10}, {"b", 100}, {"cc", 1000}};
double value = 0;
double value{0.0};
app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping));
args = {"-n", "42"};
@ -588,7 +588,7 @@ TEST_F(TApp, NumberWithUnitFloatTest) {
TEST_F(TApp, NumberWithUnitCaseSensitive) {
std::map<std::string, int> mapping{{"a", 10}, {"A", 100}};
int value = 0;
int value{0};
app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping, CLI::AsNumberWithUnit::CASE_SENSITIVE));
args = {"-n", "42a"};
@ -603,7 +603,7 @@ TEST_F(TApp, NumberWithUnitCaseSensitive) {
TEST_F(TApp, NumberWithUnitCaseInsensitive) {
std::map<std::string, int> mapping{{"a", 10}, {"B", 100}};
int value = 0;
int value{0};
app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping, CLI::AsNumberWithUnit::CASE_INSENSITIVE));
args = {"-n", "42a"};
@ -626,7 +626,7 @@ TEST_F(TApp, NumberWithUnitCaseInsensitive) {
TEST_F(TApp, NumberWithUnitMandatoryUnit) {
std::map<std::string, int> mapping{{"a", 10}, {"A", 100}};
int value;
int value{0};
app.add_option("-n", value)
->transform(CLI::AsNumberWithUnit(mapping,
CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED |
@ -647,7 +647,7 @@ TEST_F(TApp, NumberWithUnitMandatoryUnit) {
TEST_F(TApp, NumberWithUnitMandatoryUnit2) {
std::map<std::string, int> mapping{{"a", 10}, {"B", 100}};
int value;
int value{0};
app.add_option("-n", value)
->transform(CLI::AsNumberWithUnit(mapping,
CLI::AsNumberWithUnit::Options(CLI::AsNumberWithUnit::UNIT_REQUIRED |
@ -677,7 +677,7 @@ TEST_F(TApp, NumberWithUnitBadMapping) {
TEST_F(TApp, NumberWithUnitBadInput) {
std::map<std::string, int> mapping{{"a", 10}, {"b", 100}};
int value;
int value{0};
app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping));
args = {"-n", "13 a b"};
@ -723,7 +723,7 @@ TEST_F(TApp, NumberWithUnitIntOverflow) {
TEST_F(TApp, NumberWithUnitFloatOverflow) {
std::map<std::string, float> mapping{{"a", 2.f}, {"b", 1.f}, {"c", 0.f}};
float value;
float value{0.0F};
app.add_option("-n", value)->transform(CLI::AsNumberWithUnit(mapping));
args = {"-n", "3e+38 a"};
@ -739,7 +739,7 @@ TEST_F(TApp, NumberWithUnitFloatOverflow) {
}
TEST_F(TApp, AsSizeValue1000_1024) {
std::uint64_t value;
std::uint64_t value{0};
app.add_option("-s", value)->transform(CLI::AsSizeValue(true));
args = {"-s", "10240"};
@ -750,8 +750,8 @@ TEST_F(TApp, AsSizeValue1000_1024) {
run();
EXPECT_EQ(value, 1u);
std::uint64_t k_value = 1000u;
std::uint64_t ki_value = 1024u;
std::uint64_t k_value{1000u};
std::uint64_t ki_value{1024u};
args = {"-s", "1k"};
run();
EXPECT_EQ(value, k_value);
@ -845,7 +845,7 @@ TEST_F(TApp, AsSizeValue1000_1024) {
}
TEST_F(TApp, AsSizeValue1024) {
std::uint64_t value;
std::uint64_t value{0};
app.add_option("-s", value)->transform(CLI::AsSizeValue(false));
args = {"-s", "10240"};
@ -856,7 +856,7 @@ TEST_F(TApp, AsSizeValue1024) {
run();
EXPECT_EQ(value, 1u);
std::uint64_t ki_value = 1024u;
std::uint64_t ki_value{1024u};
args = {"-s", "1k"};
run();
EXPECT_EQ(value, ki_value);

View File

@ -4,7 +4,7 @@
struct TApp_TBO : public TApp, public ::testing::WithParamInterface<const char *> {};
TEST_P(TApp_TBO, TrueBoolOption) {
bool value = false; // Not used, but set just in case
bool value{false}; // Not used, but set just in case
app.add_option("-b,--bool", value);
args = {"--bool", GetParam()};
run();
@ -19,7 +19,7 @@ INSTANTIATE_TEST_CASE_P(TrueBoolOptions, TApp_TBO, ::testing::Values("true", "on
struct TApp_FBO : public TApp, public ::testing::WithParamInterface<const char *> {};
TEST_P(TApp_FBO, FalseBoolOptions) {
bool value = true; // Not used, but set just in case
bool value{true}; // Not used, but set just in case
app.add_option("-b,--bool", value);
args = {"--bool", GetParam()};
run();