Boost logo

Boost Users :

Subject: Re: [Boost-users] boost program options
From: Klaim - Joël Lamotte (mjklaim_at_[hidden])
Date: 2016-01-06 18:17:15


On 21 December 2015 at 17:22, avib369 . <avibahra_at_[hidden]> wrote:

> With reference to boost 1.59 and program options.
> The following test passes on boost 1.53, but fails on boost 1.59.
>

You might want to create a ticket: https://svn.boost.org

> I need to able to handle.
> --arg1 10 and
> --arg1=10
>
> boost 1.59 now fails on '--arg1 10', with test below with option value
> being empty.
>
> #include <string>
> #include <iostream>
> #include <fstream>
>
> #include <boost/test/unit_test.hpp>
> #include <boost/foreach.hpp>
> #include <boost/program_options.hpp>
>
> using namespace std;
> namespace po = boost::program_options;
>
> BOOST_AUTO_TEST_SUITE( BaseTestSuite )
>
> BOOST_AUTO_TEST_CASE( test_program_options_implicit_value )
> {
> cout << "Base:: ...test_program_options_implicit_value\n";
>
> // Declare the supported options.
> po::options_description desc("Allowed options");
> desc.add_options()
> ("help", "produce help message")
> ("arg1", po::value<string>()->implicit_value( string("") ),
> "optional arg1 description") ;
>
> {
> char* argv[] = {
> const_cast<char*>("test_program_options_implicit_value"),
> const_cast<char*>("--help"),
> const_cast<char*>("--arg1")
> };
>
> po::variables_map vm;
> po::store(po::parse_command_line(3, argv, desc), vm);
> po::notify(vm);
>
> BOOST_CHECK_MESSAGE(vm.count("help"), "Expected help");
> BOOST_CHECK_MESSAGE(vm.count("arg1"), "Expected arg1");
> BOOST_CHECK_MESSAGE(vm["arg1"].as<string>() == "", "Expected arg1 to
> be empty");
> }
> {
> // ****** This fails on boost 1.59 bit passes in boost 1.53 *******
> 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::command_line_parser(3, argv, desc), vm);
> 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>() << "'");
> }
> {
> char* argv[] = {
> const_cast<char*>("test_program_options_implicit_value"),
> const_cast<char*>("--arg1=11")
> };
>
> po::variables_map vm;
> po::store(po::parse_command_line(2, argv, desc), vm);
> po::notify(vm);
>
> BOOST_CHECK_MESSAGE(vm.count("arg1"), "Expected arg1");
> BOOST_CHECK_MESSAGE(vm["arg1"].as<string>() == "11",
> "Expected arg1 with value of 11 but found " <<
> vm["arg1"].as<string>());
> }
> }
>
> Ta,
> Avi
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net