/** * Copyright - See the COPYRIGHT that is included with this distribution. * pvxs is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include #include #include #include #include "cliutil.h" namespace pvxs { namespace detail { template struct test_print> { template static inline void op(C& strm, const std::vector& v) { bool first = true; for(auto& e : v) { if(first) { first = false; } else { strm<<' '; } test_print::op(strm, e); } } }; template<> struct test_print> { template static inline void op(C& strm, const std::pair& v) { strm<<'-'<(argv), "a:v"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}, {'a',"Aa"}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-v", "-a", "Aa", "hello"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}, {'a',"Aa"}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-v", "-aAa", "hello"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}, {'a',"Aa"}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-v", "-a"}; // missing value pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}, {'?',nullptr}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional; testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-vvaTest", "hello"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}, {'v', nullptr}, {'a', "Test"}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-vvQQ", "hello"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}, {'v', nullptr}, {-1, nullptr}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-v", "--", "-vvaTest", "hello"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"-vvaTest", "hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "--vvQQ", "hello"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{-1, "--vvQQ"}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-v", "-1", "hello"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}, {-1, nullptr}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello"}); testArrEq(opts.positional, positional); } { testDiag("case @%d", __LINE__); const char* argv[] = {"exe", "-v", "hello", "-1"}; pvxs::GetOpt opts(NELEMENTS(argv), const_cast(argv), "va:"); testOk(strcmp(opts.argv0, "exe")==0, "%s", opts.argv0); decltype (opts.arguments) arguments({{'v', nullptr}}); testArrEq(opts.arguments, arguments); decltype (opts.positional) positional({"hello", "-1"}); testArrEq(opts.positional, positional); } return testDone(); }