mirror of
https://github.com/jarro2783/cxxopts.git
synced 2026-08-29 01:25:31 +02:00
Fix arguments after -- without declared positional
Fixes #36. This fixes handling arguments passed after `--` when no positional arguments have been declared, or when the positional arguments have all been used up. The bug was that the extra arguments were lost. Now they are retained in the modified argv.
This commit is contained in:
@@ -153,3 +153,25 @@ TEST_CASE("Some positional explicit", "[positional]")
|
||||
CHECK(positional[0] == "c");
|
||||
CHECK(positional[1] == "d");
|
||||
}
|
||||
|
||||
TEST_CASE("No positional with extras", "[positional]")
|
||||
{
|
||||
cxxopts::Options options("posargmaster", "shows incorrect handling");
|
||||
options.add_options()
|
||||
("dummy", "oh no", cxxopts::value<std::string>())
|
||||
;
|
||||
|
||||
Argv av({"extras", "--", "a", "b", "c", "d"});
|
||||
|
||||
char** argv = av.argv();
|
||||
auto argc = av.argc();
|
||||
|
||||
auto old_argv = argv;
|
||||
auto old_argc = argc;
|
||||
|
||||
options.parse(argc, argv);
|
||||
|
||||
REQUIRE(argc == old_argc - 1);
|
||||
CHECK(argv[0] == std::string("extras"));
|
||||
CHECK(argv[1] == std::string("a"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user