aboutsummaryrefslogtreecommitdiff
path: root/test.cxx
diff options
context:
space:
mode:
authorPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-09 21:31:58 +0300
committerPavel Belikov <pavel.fuchs.belikov@gmail.com>2017-11-09 21:31:58 +0300
commit34d613b02b69fdb1c66eb61184c6f660d98ff95d (patch)
treee28b72f3d9db0ce7d490650598d24b9422cdb7ee /test.cxx
parentadd documentation for Command::RequireCommand (diff)
downloadargs.hxx-34d613b02b69fdb1c66eb61184c6f660d98ff95d.tar.xz
change default value of RequireCommand
Diffstat (limited to 'test.cxx')
-rw-r--r--test.cxx15
1 files changed, 6 insertions, 9 deletions
diff --git a/test.cxx b/test.cxx
index 0bb58d2..ba4d5f8 100644
--- a/test.cxx
+++ b/test.cxx
@@ -770,6 +770,7 @@ TEST_CASE("Subparser help works as expected", "[args]")
});
p.Prog("git");
+ p.RequireCommand(false);
std::ostringstream s;
@@ -877,15 +878,12 @@ TEST_CASE("Subparser validation works as expected", "[args]")
args::Command c(p, "c", "command c", [](args::Subparser&){});
- REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{}));
+ REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{}), args::ValidationError);
REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"a"}), args::RequiredError);
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"a", "-f", "F"}));
REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{"b"}), args::RequiredError);
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"b", "-f", "F"}));
- p.RequireCommand(true);
- REQUIRE_THROWS_AS(p.ParseArgs(std::vector<std::string>{}), args::ValidationError);
-
p.RequireCommand(false);
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{}));
@@ -904,6 +902,8 @@ TEST_CASE("Global options work as expected", "[args]")
args::Command a(p, "a", "command a");
args::Command b(p, "b", "command b");
+ p.RequireCommand(false);
+
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"-f"}));
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"a", "-f"}));
REQUIRE_NOTHROW(p.ParseArgs(std::vector<std::string>{"b", "-f"}));
@@ -1012,7 +1012,7 @@ TEST_CASE("Subparser validation works as expected in noexcept mode", "[args]")
argstest::Command c(p, "c", "command c", [](argstest::Subparser&){});
p.ParseArgs(std::vector<std::string>{});
- REQUIRE(p.GetError() == argstest::Error::None);
+ REQUIRE(p.GetError() == argstest::Error::Validation);
p.ParseArgs(std::vector<std::string>{"a"});
REQUIRE((size_t)p.GetError() == (size_t)argstest::Error::Required);
@@ -1026,10 +1026,6 @@ TEST_CASE("Subparser validation works as expected in noexcept mode", "[args]")
p.ParseArgs(std::vector<std::string>{"b", "-f", "F"});
REQUIRE(p.GetError() == argstest::Error::None);
- p.RequireCommand(true);
- p.ParseArgs(std::vector<std::string>{});
- REQUIRE(p.GetError() == argstest::Error::Validation);
-
p.RequireCommand(false);
p.ParseArgs(std::vector<std::string>{});
REQUIRE(p.GetError() == argstest::Error::None);
@@ -1046,3 +1042,4 @@ TEST_CASE("Nargs work as expected in noexcept mode", "[args]")
parser.ParseArgs(std::vector<std::string>{"-a", "1", "2"});
REQUIRE(parser.GetError() == argstest::Error::Usage);
}
+