diff options
author | Pavel Belikov <pavel.fuchs.belikov@gmail.com> | 2019-06-25 22:21:36 +0300 |
---|---|---|
committer | Pavel Belikov <pavel.fuchs.belikov@gmail.com> | 2019-06-25 22:23:06 +0300 |
commit | f9ccd0d64bdc6fabe7fde2965db762ddbf1d8e68 (patch) | |
tree | 93b125da2b1d0323300d2b040858317adbce0977 /test.cxx | |
parent | Merge pull request #73 from zhihaoy/cmake-targets (diff) | |
download | args.hxx-f9ccd0d64bdc6fabe7fde2965db762ddbf1d8e68.tar.xz |
Fixes #74 : Fix group validation in Subparser/Command
Diffstat (limited to 'test.cxx')
-rw-r--r-- | test.cxx | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -936,6 +936,25 @@ TEST_CASE("Subparser validation works as expected", "[args]") REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"unknown-command"}), args::ParseError); } +TEST_CASE("Subparser group validation works as expected", "[args]") +{ + int x = 0; + args::ArgumentParser p("parser"); + args::Command a(p, "a", "command a", [&](args::Subparser &s) + { + args::Group required(s, "", args::Group::Validators::All); + args::ValueFlag<std::string> f(required, "", "", {'f'}); + s.Parse(); + ++x; + }); + + p.RequireCommand(false); + REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{})); + REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"a", "-f", "F"})); + REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"a"}), args::ValidationError); + REQUIRE(x == 1); +} + TEST_CASE("Global options work as expected", "[args]") { args::Group globals; |