diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/getopt/ut/last_getopt_ut.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/getopt/ut/last_getopt_ut.cpp')
-rw-r--r-- | library/cpp/getopt/ut/last_getopt_ut.cpp | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index c99a1d053d..0bdfff4f52 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/getopt/last_getopt.h> - + #include <library/cpp/colorizer/colors.h> #include <library/cpp/testing/unittest/registar.h> @@ -11,14 +11,14 @@ using namespace NLastGetopt; namespace { - struct TOptsNoDefault: public TOpts { + struct TOptsNoDefault: public TOpts { TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) : TOpts(optstring) { } }; - class TOptsParseResultTestWrapper: public TOptsParseResultException { + class TOptsParseResultTestWrapper: public TOptsParseResultException { TVector<const char*> Argv_; public: @@ -174,11 +174,11 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cp", "/etc", "/tmp/etc", "verbose", "nosymlink"})), - yexception); + yexception); UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cp"})), - yexception); + yexception); opts.SetFreeArgsNum(2); TOptsParseResultTestWrapper r22(&opts, V({"cp", "/etc", "/var/tmp"})); @@ -347,16 +347,16 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } Y_UNIT_TEST(TestDuplicatedOptionCrash) { - // this test is broken, cause UNIT_ASSERT(false) always throws - return; - + // this test is broken, cause UNIT_ASSERT(false) always throws + return; + bool exception = false; try { TOpts opts; opts.AddLongOption('x', "one"); opts.AddLongOption('x', "two"); UNIT_ASSERT(false); - } catch (...) { + } catch (...) { // we should go here, duplicating options are forbidden exception = true; } @@ -529,21 +529,21 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opt_d.Required(); UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd"})), - TUsageException); + TUsageException); TOptsParseResultTestWrapper r3(&opts, V({"cmd", "-d11"})); UNIT_ASSERT_VALUES_EQUAL("11", r3.Get('d')); } - class HandlerStoreTrue { - bool* Flag; - + class HandlerStoreTrue { + bool* Flag; + public: - HandlerStoreTrue(bool* flag) + HandlerStoreTrue(bool* flag) : Flag(flag) { } - void operator()() { + void operator()() { *Flag = true; } }; @@ -561,11 +561,11 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { double fval = 0.0; opts.AddLongOption("flag1").RequiredArgument().StoreResult(&uval); opts.AddLongOption("flag2").RequiredArgument().StoreResultT<int>(&uval); - opts.AddLongOption("flag3").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))fabs); - opts.AddLongOption("flag4").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))sqrt); + opts.AddLongOption("flag3").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))fabs); + opts.AddLongOption("flag4").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))sqrt); UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd", "--flag3", "-2.0", "--flag1", "-1"})), - yexception); + yexception); UNIT_ASSERT_VALUES_EQUAL(uval, 5u); UNIT_ASSERT_VALUES_EQUAL(fval, 2.0); TOptsParseResultTestWrapper r1(&opts, V({"cmd", "--flag4", "9.0", "--flag2", "-1"})); @@ -580,7 +580,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TString title = TString("Sample ") + TString(prog).Quote() + " application"; opts.SetTitle(title); int argc = 2; - const char* cmd[] = {prog}; + const char* cmd[] = {prog}; TOptsParser parser(&opts, argc, cmd); TStringStream out; parser.PrintUsage(out); @@ -595,7 +595,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { const char* prog = "my_program"; TString customDescr = "<FILE|TABLE> USER [OPTIONS]"; int argc = 2; - const char* cmd[] = {prog}; + const char* cmd[] = {prog}; opts.SetCmdLineDescr(customDescr); TOptsParser parser(&opts, argc, cmd); TStringStream out; @@ -615,7 +615,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.SetFreeArgTitle(0, "first_free_arg", "help"); opts.SetFreeArgTitle(2, "second_free_arg"); opts.AddSection("Section", "Section\n text"); - const char* cmd[] = {prog}; + const char* cmd[] = {prog}; TOptsParser parser(&opts, Y_ARRAY_SIZE(cmd), cmd); TStringStream out; NColorizer::TColors colors(true); @@ -663,12 +663,12 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { for (bool withColors : withColorsOpt) { TOpts opts; const char* prog = "my_program"; - opts.AddLongOption("option", "description 1").Required(); // long option - opts.AddLongOption('o', "other", "description 2"); // char and long option - opts.AddCharOption('d', "description 3").RequiredArgument("DD"); // char option + opts.AddLongOption("option", "description 1").Required(); // long option + opts.AddLongOption('o', "other", "description 2"); // char and long option + opts.AddCharOption('d', "description 3").RequiredArgument("DD"); // char option opts.AddCharOption('s', "description 4\ndescription 5\ndescription 6"); // multiline desc opts.AddLongOption('l', "very_very_very_loooong_ooooption", "description 7").RequiredArgument("LONG_ARGUMENT"); - const char* cmd[] = {prog}; + const char* cmd[] = {prog}; TOptsParser parser(&opts, Y_ARRAY_SIZE(cmd), cmd); TStringStream out; @@ -730,7 +730,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TStringBuilder keyvals; TOptsNoDefault opts; - opts.AddLongOption("set").KVHandler([&keyvals](TString k, TString v) { keyvals << k << ":" << v << ","; }); + opts.AddLongOption("set").KVHandler([&keyvals](TString k, TString v) { keyvals << k << ":" << v << ","; }); TOptsParseResultTestWrapper r(&opts, V({"cmd", "--set", "x=1", "--set", "y=2", "--set=z=3"})); @@ -740,7 +740,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { Y_UNIT_TEST(TestEasySetup) { TEasySetup opts; bool flag = false; - opts('v', "version", "print version information")('a', "abstract", "some abstract param", true)('b', "buffer", "SIZE", "some param with argument")('c', "count", "SIZE", "some param with required argument")('t', "true", HandlerStoreTrue(&flag), "Some arg with handler")("global", SimpleHander, "Another arg with handler"); + opts('v', "version", "print version information")('a', "abstract", "some abstract param", true)('b', "buffer", "SIZE", "some param with argument")('c', "count", "SIZE", "some param with required argument")('t', "true", HandlerStoreTrue(&flag), "Some arg with handler")("global", SimpleHander, "Another arg with handler"); { gSimpleFlag = false; @@ -758,7 +758,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { { UNIT_ASSERT_EXCEPTION( TOptsParseResultTestWrapper(&opts, V({"cmd", "--true"})), - TUsageException); + TUsageException); } { @@ -777,7 +777,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { // Should throw TUsageException. Other exception types, no exceptions at all and exit(1) are failures UNIT_ASSERT_EXCEPTION( TOptsParseResultException(&opts, Y_ARRAY_SIZE(argv), argv), - TUsageException); + TUsageException); } Y_UNIT_TEST(TestFreeArgsStoreResult) { |