diff options
author | Alexey Salmin <alexey.salmin@gmail.com> | 2022-02-10 16:49:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:37 +0300 |
commit | 71af077a5dfe7e9f932a508422c2dac81a57ebc0 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/getopt | |
parent | 3c5b1607b38f637d2f3313791ed25c2e080d2647 (diff) | |
download | ydb-71af077a5dfe7e9f932a508422c2dac81a57ebc0.tar.gz |
Restoring authorship annotation for Alexey Salmin <alexey.salmin@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/getopt')
-rw-r--r-- | library/cpp/getopt/last_getopt_demo/demo.cpp | 6 | ||||
-rw-r--r-- | library/cpp/getopt/print.cpp | 2 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt.h | 72 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_handlers.h | 12 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_opt.h | 2 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_parse_result.h | 2 | ||||
-rw-r--r-- | library/cpp/getopt/small/last_getopt_support.h | 14 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.cpp | 18 | ||||
-rw-r--r-- | library/cpp/getopt/small/modchooser.h | 4 | ||||
-rw-r--r-- | library/cpp/getopt/small/opt.cpp | 8 | ||||
-rw-r--r-- | library/cpp/getopt/small/opt.h | 2 | ||||
-rw-r--r-- | library/cpp/getopt/small/opt2.h | 48 | ||||
-rw-r--r-- | library/cpp/getopt/ut/last_getopt_ut.cpp | 112 |
13 files changed, 151 insertions, 151 deletions
diff --git a/library/cpp/getopt/last_getopt_demo/demo.cpp b/library/cpp/getopt/last_getopt_demo/demo.cpp index fcfe5ac3ea..79426a9cc9 100644 --- a/library/cpp/getopt/last_getopt_demo/demo.cpp +++ b/library/cpp/getopt/last_getopt_demo/demo.cpp @@ -92,7 +92,7 @@ protected: {"OPTIONS", "describe the communication options for the target resource"}, {"TRACE", "perform a message loop-back test"}, {"PATCH", "apply partial modifications to the specified resource"}})); - + opts.AddLongOption('U', "user-agent") .RequiredArgument("agent-string") .DefaultValue("LastGetoptDemo/1.0.0") @@ -202,8 +202,8 @@ protected: << colors.Cyan() << " $ last_getopt_demo -b -U 'Wget/1.0.0' https://wordpress.org/latest.zip" << colors.Reset()); - } - + } + int DoRun(NLastGetopt::TOptsParseResult&& parsedOptions) override { using namespace NColorizer; diff --git a/library/cpp/getopt/print.cpp b/library/cpp/getopt/print.cpp index b9539a4400..8cf1c62e4d 100644 --- a/library/cpp/getopt/print.cpp +++ b/library/cpp/getopt/print.cpp @@ -31,7 +31,7 @@ namespace NLastGetoptPrivate { TString& ShortVersionString(); struct TInit { - TInit() { + TInit() { VersionString() = InitVersionString(); ShortVersionString() = InitShortVersionString(); } diff --git a/library/cpp/getopt/small/last_getopt.h b/library/cpp/getopt/small/last_getopt.h index 6778416cd0..07687bc914 100644 --- a/library/cpp/getopt/small/last_getopt.h +++ b/library/cpp/getopt/small/last_getopt.h @@ -4,7 +4,7 @@ #include "last_getopt_easy_setup.h" #include "last_getopt_parse_result.h" -#include <util/generic/function.h> +#include <util/generic/function.h> #include <util/string/split.h> /// see some documentation in @@ -17,7 +17,7 @@ namespace NLastGetopt { /// Handler to split option value by delimiter into a target container and allow ranges. - template <class Container> + template <class Container> struct TOptRangeSplitHandler: public IOptHandler { public: using TContainer = Container; @@ -26,9 +26,9 @@ namespace NLastGetopt { explicit TOptRangeSplitHandler(TContainer* target, const char elementsDelim, const char rangesDelim) : Target(target) , ElementsDelim(elementsDelim) - , RangesDelim(rangesDelim) - { - } + , RangesDelim(rangesDelim) + { + } void HandleOpt(const TOptsParser* parser) override { const TStringBuf curval(parser->CurValOrDef()); @@ -56,7 +56,7 @@ namespace NLastGetopt { char RangesDelim; }; - template <class Container> + template <class Container> struct TOptSplitHandler: public IOptHandler { public: using TContainer = Container; @@ -64,9 +64,9 @@ namespace NLastGetopt { explicit TOptSplitHandler(TContainer* target, const char delim) : Target(target) - , Delim(delim) - { - } + , Delim(delim) + { + } void HandleOpt(const TOptsParser* parser) override { const TStringBuf curval(parser->CurValOrDef()); @@ -82,36 +82,36 @@ namespace NLastGetopt { char Delim; }; - template <class TpFunc> + template <class TpFunc> struct TOptKVHandler: public IOptHandler { - public: - using TKey = typename TFunctionArgs<TpFunc>::template TGet<0>; - using TValue = typename TFunctionArgs<TpFunc>::template TGet<1>; - - explicit TOptKVHandler(TpFunc func, const char kvdelim = '=') - : Func(func) - , KVDelim(kvdelim) - { - } - - void HandleOpt(const TOptsParser* parser) override { - const TStringBuf curval(parser->CurValOrDef()); - const TOpt* curOpt(parser->CurOpt()); - if (curval.IsInited()) { - TStringBuf key, value; - if (!curval.TrySplit(KVDelim, key, value)) { + public: + using TKey = typename TFunctionArgs<TpFunc>::template TGet<0>; + using TValue = typename TFunctionArgs<TpFunc>::template TGet<1>; + + explicit TOptKVHandler(TpFunc func, const char kvdelim = '=') + : Func(func) + , KVDelim(kvdelim) + { + } + + void HandleOpt(const TOptsParser* parser) override { + const TStringBuf curval(parser->CurValOrDef()); + const TOpt* curOpt(parser->CurOpt()); + if (curval.IsInited()) { + TStringBuf key, value; + if (!curval.TrySplit(KVDelim, key, value)) { throw TUsageException() << "failed to parse opt " << NPrivate::OptToString(curOpt) << " value " << TString(curval).Quote() << ": expected key" << KVDelim << "value format"; - } - Func(NPrivate::OptFromString<TKey>(key, curOpt), NPrivate::OptFromString<TValue>(value, curOpt)); - } - } - - private: - TpFunc Func; - char KVDelim; - }; - + } + Func(NPrivate::OptFromString<TKey>(key, curOpt), NPrivate::OptFromString<TValue>(value, curOpt)); + } + } + + private: + TpFunc Func; + char KVDelim; + }; + namespace NPrivate { template <typename TpFunc, typename TpArg> void THandlerFunctor1<TpFunc, TpArg>::HandleOpt(const TOptsParser* parser) { diff --git a/library/cpp/getopt/small/last_getopt_handlers.h b/library/cpp/getopt/small/last_getopt_handlers.h index 5311fbbe42..d35456ef34 100644 --- a/library/cpp/getopt/small/last_getopt_handlers.h +++ b/library/cpp/getopt/small/last_getopt_handlers.h @@ -7,17 +7,17 @@ namespace NLastGetopt { /// Handler to split option value by delimiter into a target container. - template <class Container> + template <class Container> struct TOptSplitHandler; /// Handler to split option value by delimiter into a target container and allow ranges. - template <class Container> + template <class Container> struct TOptRangeSplitHandler; - /// Handler to parse key-value pairs (default delimiter is '=') and apply user-supplied handler to each pair - template <class TpFunc> - struct TOptKVHandler; - + /// Handler to parse key-value pairs (default delimiter is '=') and apply user-supplied handler to each pair + template <class TpFunc> + struct TOptKVHandler; + [[noreturn]] void PrintUsageAndExit(const TOptsParser* parser); [[noreturn]] void PrintVersionAndExit(const TOptsParser* parser); [[noreturn]] void PrintShortVersionAndExit(const TString& appName); diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h index 1f0820ed41..a8dd5adca9 100644 --- a/library/cpp/getopt/small/last_getopt_opt.h +++ b/library/cpp/getopt/small/last_getopt_opt.h @@ -699,7 +699,7 @@ namespace NLastGetopt { TOpt& RangeSplitHandler(Container* target, const char elementsDelim, const char rangesDelim) { return Handler(new NLastGetopt::TOptRangeSplitHandler<Container>(target, elementsDelim, rangesDelim)); } - + template <class TpFunc> TOpt& KVHandler(TpFunc func, const char kvdelim = '=') { return Handler(new NLastGetopt::TOptKVHandler<TpFunc>(func, kvdelim)); diff --git a/library/cpp/getopt/small/last_getopt_parse_result.h b/library/cpp/getopt/small/last_getopt_parse_result.h index 013bedc507..1ab6f598c9 100644 --- a/library/cpp/getopt/small/last_getopt_parse_result.h +++ b/library/cpp/getopt/small/last_getopt_parse_result.h @@ -313,7 +313,7 @@ namespace NLastGetopt { } virtual ~TOptsParseResultException() = default; void HandleError() const override; - + protected: TOptsParseResultException() = default; }; diff --git a/library/cpp/getopt/small/last_getopt_support.h b/library/cpp/getopt/small/last_getopt_support.h index 5fdb145dfe..17bed3e614 100644 --- a/library/cpp/getopt/small/last_getopt_support.h +++ b/library/cpp/getopt/small/last_getopt_support.h @@ -47,7 +47,7 @@ namespace NLastGetopt { Func_(); } }; - + template <typename TpFunc, typename TpArg = const TOptsParser*> class THandlerFunctor1 : public IOptHandler { @@ -62,7 +62,7 @@ namespace NLastGetopt { , HasDef_(false) { } - + template <typename T> THandlerFunctor1(const TpFunc& func, const T& def) : Func_(func) @@ -70,7 +70,7 @@ namespace NLastGetopt { , HasDef_(true) { } - + void HandleOpt(const TOptsParser* parser) override; }; @@ -78,7 +78,7 @@ namespace NLastGetopt { class THandlerFunctor1<TpFunc, const TOptsParser*> : public IOptHandler { TpFunc Func_; - + public: THandlerFunctor1(TpFunc func) : Func_(func) @@ -89,7 +89,7 @@ namespace NLastGetopt { Func_(parser); } }; - + template <typename T, typename TpVal = T> class TStoreResultFunctor { private: @@ -100,7 +100,7 @@ namespace NLastGetopt { : Target_(target) { } - + void operator()(const TpVal& val) { *Target_ = val; } @@ -118,7 +118,7 @@ namespace NLastGetopt { , Func_(func) { } - + void operator()(const TpVal& val) { *Target_ = Func_(val); } diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index b0d80adef3..2fa5cfd070 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -16,9 +16,9 @@ class PtrWrapper: public TMainClass { public: explicit PtrWrapper(const TMainFunctionPtr main) - : Main(main) - { - } + : Main(main) + { + } int operator()(const int argc, const char** argv) override { return Main(argc, argv); @@ -31,9 +31,9 @@ private: class PtrvWrapper: public TMainClass { public: explicit PtrvWrapper(const TMainFunctionPtrV main) - : Main(main) - { - } + : Main(main) + { + } int operator()(const int argc, const char** argv) override { TVector<TString> nargv(argv, argv + argc); @@ -47,9 +47,9 @@ private: class ClassWrapper: public TMainClass { public: explicit ClassWrapper(TMainClassV* main) - : Main(main) - { - } + : Main(main) + { + } int operator()(const int argc, const char** argv) override { TVector<TString> nargv(argv, argv + argc); diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h index 07ece740e8..0a8de6d50b 100644 --- a/library/cpp/getopt/small/modchooser.h +++ b/library/cpp/getopt/small/modchooser.h @@ -112,8 +112,8 @@ public: TMode() : Main(nullptr) - { - } + { + } TMode(const TString& name, TMainClass* main, const TString& descr, bool hidden, bool noCompletion); diff --git a/library/cpp/getopt/small/opt.cpp b/library/cpp/getopt/small/opt.cpp index d6282dfd3b..744501765c 100644 --- a/library/cpp/getopt/small/opt.cpp +++ b/library/cpp/getopt/small/opt.cpp @@ -8,10 +8,10 @@ using namespace NLastGetopt; namespace { struct TOptsNoDefault: public TOpts { - TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) - : TOpts(optstring) - { - } + TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) + : TOpts(optstring) + { + } }; } diff --git a/library/cpp/getopt/small/opt.h b/library/cpp/getopt/small/opt.h index 2767124dbb..ecb57439bc 100644 --- a/library/cpp/getopt/small/opt.h +++ b/library/cpp/getopt/small/opt.h @@ -85,7 +85,7 @@ public: // Get() means next int Get(); int Get(int* longOptionIndex); - int operator()() { + int operator()() { return Get(); } diff --git a/library/cpp/getopt/small/opt2.h b/library/cpp/getopt/small/opt2.h index 7d649beaa3..4d9d943237 100644 --- a/library/cpp/getopt/small/opt2.h +++ b/library/cpp/getopt/small/opt2.h @@ -35,38 +35,38 @@ struct Opt2Param { TString HelpUsage; TVector<const char*> ActualValue; const char* LongOptName; - Opt2Param() - : HasArg(false) - , IsFound(0) - , IsNumeric(0) - , IsRequired(0) - , MultipleUse(0) - , DefValue(nullptr) - , LongOptName(nullptr) - { - } + Opt2Param() + : HasArg(false) + , IsFound(0) + , IsNumeric(0) + , IsRequired(0) + , MultipleUse(0) + , DefValue(nullptr) + , LongOptName(nullptr) + { + } }; struct IntRange { int Left, Right; - IntRange() = delete; - IntRange(int both) - : Left(both) - , Right(both) - { - } - - IntRange(int left, int right) - : Left(left) - , Right(right) - { - } + IntRange() = delete; + IntRange(int both) + : Left(both) + , Right(both) + { + } + + IntRange(int left, int right) + : Left(left) + , Right(right) + { + } }; class Opt2 { public: - Opt2() = default; - + Opt2() = default; + Opt2(int argc, char* const* argv, const char* optspec, IntRange free_args_num = -1, const char* long_alias = nullptr) { Init(argc, argv, optspec, free_args_num, long_alias); } diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index 7ccf25f3af..c99a1d053d 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/colorizer/colors.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/array_size.h> +#include <util/generic/array_size.h> #include <util/string/subst.h> #include <util/string/vector.h> #include <util/string/split.h> @@ -12,23 +12,23 @@ using namespace NLastGetopt; namespace { struct TOptsNoDefault: public TOpts { - TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) - : TOpts(optstring) - { - } + TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) + : TOpts(optstring) + { + } }; class TOptsParseResultTestWrapper: public TOptsParseResultException { TVector<const char*> Argv_; - - public: + + public: TOptsParseResultTestWrapper(const TOpts* opts, TVector<const char*> argv) - : Argv_(argv) - { + : Argv_(argv) + { Init(opts, (int)Argv_.size(), Argv_.data()); - } - }; - + } + }; + using V = TVector<const char*>; } @@ -137,7 +137,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; opts.AddLongOption("from"); opts.AddLongOption("to"); - TOptsParseResultTestWrapper r(&opts, V({"copy", "--from=/", "--to=/etc"})); + TOptsParseResultTestWrapper r(&opts, V({"copy", "--from=/", "--to=/etc"})); UNIT_ASSERT_VALUES_EQUAL("copy", r.GetProgramName()); UNIT_ASSERT_VALUES_EQUAL("/", r.Get("from")); @@ -154,7 +154,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddCharOption('R', NO_ARGUMENT); opts.AddCharOption('l', NO_ARGUMENT); opts.AddCharOption('h', NO_ARGUMENT); - TOptsParseResultTestWrapper r(&opts, V({"cp", "/etc", "-Rl", "/tmp/etc"})); + TOptsParseResultTestWrapper r(&opts, V({"cp", "/etc", "-Rl", "/tmp/etc"})); UNIT_ASSERT(r.Has('R')); UNIT_ASSERT(r.Has('l')); UNIT_ASSERT(!r.Has('h')); @@ -168,20 +168,20 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { Y_UNIT_TEST(TestFreeArgs) { TOptsNoDefault opts; opts.SetFreeArgsNum(1, 3); - TOptsParseResultTestWrapper r11(&opts, V({"cp", "/etc"})); - TOptsParseResultTestWrapper r12(&opts, V({"cp", "/etc", "/tmp/etc"})); - TOptsParseResultTestWrapper r13(&opts, V({"cp", "/etc", "/tmp/etc", "verbose"})); + TOptsParseResultTestWrapper r11(&opts, V({"cp", "/etc"})); + TOptsParseResultTestWrapper r12(&opts, V({"cp", "/etc", "/tmp/etc"})); + TOptsParseResultTestWrapper r13(&opts, V({"cp", "/etc", "/tmp/etc", "verbose"})); UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cp", "/etc", "/tmp/etc", "verbose", "nosymlink"})), + TOptsParseResultTestWrapper(&opts, V({"cp", "/etc", "/tmp/etc", "verbose", "nosymlink"})), yexception); UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cp"})), + TOptsParseResultTestWrapper(&opts, V({"cp"})), yexception); opts.SetFreeArgsNum(2); - TOptsParseResultTestWrapper r22(&opts, V({"cp", "/etc", "/var/tmp"})); + TOptsParseResultTestWrapper r22(&opts, V({"cp", "/etc", "/var/tmp"})); } Y_UNIT_TEST(TestCharOptionsRequiredOptional) { @@ -191,7 +191,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddCharOption('x', REQUIRED_ARGUMENT); opts.AddCharOption('y', REQUIRED_ARGUMENT); opts.AddCharOption('l', NO_ARGUMENT); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "-ld11", "-e", "22", "-lllx33", "-y", "44"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "-ld11", "-e", "22", "-lllx33", "-y", "44"})); UNIT_ASSERT_VALUES_EQUAL("11", r.Get('d')); UNIT_ASSERT_VALUES_EQUAL("22", r.Get('e')); UNIT_ASSERT_VALUES_EQUAL("33", r.Get('x')); @@ -446,7 +446,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddLongOption('b', "beta").NoArgument().StoreValue(&b, 24); opts.AddLongOption('e', "enum").NoArgument().StoreValue(&e, REQUIRED_ARGUMENT).StoreValue(&c, 12345); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "-a", "-e"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "-a", "-e"})); UNIT_ASSERT_VALUES_EQUAL(42, a); UNIT_ASSERT_VALUES_EQUAL(0, b); @@ -476,7 +476,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddLongOption("path").DefaultValue("/etc"); int value = 42; opts.AddLongOption("value").StoreResult(&value).DefaultValue(32); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "dfdf"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "dfdf"})); UNIT_ASSERT_VALUES_EQUAL("/etc", r.Get("path")); UNIT_ASSERT_VALUES_EQUAL(32, value); } @@ -485,7 +485,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; TVector<TString> vals; opts.AddLongOption('s', "split").SplitHandler(&vals, ','); - TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=a,b,c"})); + TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=a,b,c"})); UNIT_ASSERT_EQUAL(vals.size(), 3); UNIT_ASSERT_EQUAL(vals[0], "a"); UNIT_ASSERT_EQUAL(vals[1], "b"); @@ -496,7 +496,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; TVector<ui32> vals; opts.AddLongOption('s', "split").RangeSplitHandler(&vals, ',', '-'); - TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=1,8-10", "--split=12-14"})); + TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=1,8-10", "--split=12-14"})); UNIT_ASSERT_EQUAL(vals.size(), 7); UNIT_ASSERT_EQUAL(vals[0], 1); UNIT_ASSERT_EQUAL(vals[1], 8); @@ -523,15 +523,15 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { // test 'not required' // makes sure that the problem will only be in 'required' - TOptsParseResultTestWrapper r1(&opts, V({"cmd"})); + TOptsParseResultTestWrapper r1(&opts, V({"cmd"})); // test 'required' opt_d.Required(); UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cmd"})), + TOptsParseResultTestWrapper(&opts, V({"cmd"})), TUsageException); - TOptsParseResultTestWrapper r3(&opts, V({"cmd", "-d11"})); + TOptsParseResultTestWrapper r3(&opts, V({"cmd", "-d11"})); UNIT_ASSERT_VALUES_EQUAL("11", r3.Get('d')); } @@ -541,8 +541,8 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { public: HandlerStoreTrue(bool* flag) : Flag(flag) - { - } + { + } void operator()() { *Flag = true; } @@ -552,7 +552,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; bool flag = false; opts.AddLongOption("flag").Handler0(HandlerStoreTrue(&flag)).NoArgument(); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--flag"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--flag"})); UNIT_ASSERT(flag); } { @@ -564,11 +564,11 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { 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"})), + TOptsParseResultTestWrapper(&opts, V({"cmd", "--flag3", "-2.0", "--flag1", "-1"})), yexception); UNIT_ASSERT_VALUES_EQUAL(uval, 5u); UNIT_ASSERT_VALUES_EQUAL(fval, 2.0); - TOptsParseResultTestWrapper r1(&opts, V({"cmd", "--flag4", "9.0", "--flag2", "-1"})); + TOptsParseResultTestWrapper r1(&opts, V({"cmd", "--flag4", "9.0", "--flag2", "-1"})); UNIT_ASSERT_VALUES_EQUAL(uval, Max<unsigned>()); UNIT_ASSERT_VALUES_EQUAL(fval, 3.0); } @@ -706,7 +706,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; opts.AddLongOption("size").AppendTo(&ints); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--size=17", "--size=19"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--size=17", "--size=19"})); UNIT_ASSERT_VALUES_EQUAL(size_t(2), ints.size()); UNIT_ASSERT_VALUES_EQUAL(17, ints.at(0)); @@ -727,16 +727,16 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } Y_UNIT_TEST(TestKVHandler) { - TStringBuilder keyvals; - - TOptsNoDefault opts; + TStringBuilder keyvals; + + TOptsNoDefault opts; 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"})); - - UNIT_ASSERT_VALUES_EQUAL(keyvals, "x:1,y:2,z:3,"); - } - + + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--set", "x=1", "--set", "y=2", "--set=z=3"})); + + UNIT_ASSERT_VALUES_EQUAL(keyvals, "x:1,y:2,z:3,"); + } + Y_UNIT_TEST(TestEasySetup) { TEasySetup opts; bool flag = false; @@ -744,41 +744,41 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { { gSimpleFlag = false; - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract"})); UNIT_ASSERT(!flag); UNIT_ASSERT(!gSimpleFlag); } { - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--global", "-t"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--global", "-t"})); UNIT_ASSERT(flag); UNIT_ASSERT(gSimpleFlag); } { UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cmd", "--true"})), + TOptsParseResultTestWrapper(&opts, V({"cmd", "--true"})), TUsageException); } { - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--buffer=512"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--buffer=512"})); UNIT_ASSERT(r.Has('b')); UNIT_ASSERT_VALUES_EQUAL(r.Get('b', 0), "512"); } } Y_UNIT_TEST(TestTOptsParseResultException) { - // verify that TOptsParseResultException actually throws a TUsageException instead of exit() - // not using wrapper here because it can hide bugs (see review #243810 and r2737774) - TOptsNoDefault opts; - opts.AddLongOption("required-opt").Required(); - const char* argv[] = {"cmd"}; - // 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), + // verify that TOptsParseResultException actually throws a TUsageException instead of exit() + // not using wrapper here because it can hide bugs (see review #243810 and r2737774) + TOptsNoDefault opts; + opts.AddLongOption("required-opt").Required(); + const char* argv[] = {"cmd"}; + // 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); - } + } Y_UNIT_TEST(TestFreeArgsStoreResult) { TOptsNoDefault opts; |