Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#11893 closed Bugs (fixed)

boost program_options regression (--arg1 value) fails ( --arg1=value) ok

Reported by: avibahra@… Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost 1.61.0 Severity: Regression
Keywords: unix_style Cc:

Description

The following test passes with boost 1.53 and fails with boost > 1.59

{

This test fails on boost 1.59, can't cope --arg1 10, only --arg1=10 * It does not honour the default style i.e unix * char* argv[] = {

const_cast<char*>("test_program_options_implicit_value"), const_cast<char*>("--arg1"), const_cast<char*>("10")

};

po::variables_map vm; po::store(po::parse_command_line(3, argv, desc), vm); po::notify(vm);

BOOST_CHECK_MESSAGE(vm.count("arg1"), "Expected arg1"); BOOST_CHECK_MESSAGE(vmarg1.as<string>() == "10", "Expected arg1 with value of 10 but found '" << vmarg1.as<string>() << "'");

}

In addition the default style is unix_style, which according to the header file should be able to cope with both styles.

Change History (3)

comment:1 by avibahra@…, 7 years ago

The correct program should be:

   po::options_description desc("Allowed options");
   desc.add_options()
       ("help", "produce help message")
       ("arg1", po::value<string>()->implicit_value( string("") ), "optional arg1 description") ;
   {
      // ******* This test fails on boost 1.59, can't cope --arg1 10, only --arg1=10 *******
      char* argv[] = {
            const_cast<char*>("test_program_options_implicit_value"),
            const_cast<char*>("--arg1"),
            const_cast<char*>("10")
      };

      po::variables_map vm;
      po::store(po::parse_command_line(3, argv, desc), vm);  // populate variable map
      po::notify(vm);

      BOOST_CHECK_MESSAGE(vm.count("arg1"), "Expected arg1");
      BOOST_CHECK_MESSAGE(vm["arg1"].as<string>() == "10", "Expected arg1 with value of 10 but found '" << vm["arg1"].as<string>() << "'");
   }

comment:2 by Vladimir Prus, 5 years ago

Resolution: fixed
Status: newclosed

comment:3 by Vladimir Prus, 5 years ago

Fixed as of revision b35e654.

Note: See TracTickets for help on using tickets.