Commit 0a49b82072f9dbe1d13c5f1b5db54ac07a0e078e

Authored by Jarryd Beck
1 parent 92779bef

add a test for broken boolean options

The parsing for boolean options was broken by 6c9bae4a07 which added implicit
and default values, and the ability to parse boolean strings. Having an option
after the boolean tried to parse that into the boolean instead of as a
positional parameter.

See #84 for the bug report.
Showing 1 changed file with 6 additions and 1 deletions
test/options.cpp
... ... @@ -423,9 +423,12 @@ TEST_CASE("Booleans", "[boolean]") {
423 423 ("bool", "A Boolean", cxxopts::value<bool>())
424 424 ("debug", "Debugging", cxxopts::value<bool>())
425 425 ("timing", "Timing", cxxopts::value<bool>())
  426 + ("others", "Other arguments", cxxopts::value<std::vector<std::string>>())
426 427 ;
427 428  
428   - Argv av({"booleans", "--bool=false", "--debug", "true", "--timing"});
  429 + options.parse_positional("others");
  430 +
  431 + Argv av({"booleans", "--bool=false", "--debug", "true", "--timing", "extra"});
429 432  
430 433 char** argv = av.argv();
431 434 auto argc = av.argc();
... ... @@ -439,4 +442,6 @@ TEST_CASE(&quot;Booleans&quot;, &quot;[boolean]&quot;) {
439 442 CHECK(result["bool"].as<bool>() == false);
440 443 CHECK(result["debug"].as<bool>() == true);
441 444 CHECK(result["timing"].as<bool>() == true);
  445 +
  446 + REQUIRE(result.count("others") == 1);
442 447 }
... ...