Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58233 - in trunk/libs/program_options: src test
From: s.ochsenknecht_at_[hidden]
Date: 2009-12-08 02:45:45


Author: s_ochsenknecht
Date: 2009-12-08 02:45:44 EST (Tue, 08 Dec 2009)
New Revision: 58233
URL: http://svn.boost.org/trac/boost/changeset/58233

Log:
config file parser now stores original_tokens, Fixes #2727
Added:
   trunk/libs/program_options/test/unrecognized_test.cpp (contents, props changed)
Text files modified:
   trunk/libs/program_options/src/config_file.cpp | 3 +++
   trunk/libs/program_options/test/Jamfile.v2 | 1 +
   2 files changed, 4 insertions(+), 0 deletions(-)

Modified: trunk/libs/program_options/src/config_file.cpp
==============================================================================
--- trunk/libs/program_options/src/config_file.cpp (original)
+++ trunk/libs/program_options/src/config_file.cpp 2009-12-08 02:45:44 EST (Tue, 08 Dec 2009)
@@ -111,6 +111,9 @@
                     this->value().value.clear();
                     this->value().value.push_back(value);
                     this->value().unregistered = !registered;
+ this->value().original_tokens.clear();
+ this->value().original_tokens.push_back(name);
+ this->value().original_tokens.push_back(value);
                     break;
 
                 } else {

Modified: trunk/libs/program_options/test/Jamfile.v2
==============================================================================
--- trunk/libs/program_options/test/Jamfile.v2 (original)
+++ trunk/libs/program_options/test/Jamfile.v2 2009-12-08 02:45:44 EST (Tue, 08 Dec 2009)
@@ -29,6 +29,7 @@
     [ po-test winmain.cpp ]
     [ po-test exception_test.cpp ]
     [ po-test split_test.cpp ]
+ [ po-test unrecognized_test.cpp ]
     ;
         
 exe test_convert : test_convert.cpp ;

Added: trunk/libs/program_options/test/unrecognized_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/program_options/test/unrecognized_test.cpp 2009-12-08 02:45:44 EST (Tue, 08 Dec 2009)
@@ -0,0 +1,88 @@
+// Copyright Sascha Ochsenknecht 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+
+#include <boost/program_options/cmdline.hpp>
+#include <boost/program_options/options_description.hpp>
+#include <boost/program_options/parsers.hpp>
+#include <boost/program_options/detail/cmdline.hpp>
+using namespace boost::program_options;
+using boost::program_options::detail::cmdline;
+
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include <cassert>
+using namespace std;
+
+#include "minitest.hpp"
+
+
+// Test free function collect_unrecognized()
+//
+// it collects the tokens of all not registered options. It can be used
+// to pass them to an own parser implementation
+
+
+
+void test_unrecognize_cmdline()
+{
+ options_description desc;
+
+ string content = "prg --input input.txt --optimization 4 --opt option";
+ vector< string > tokens = split_unix(content);
+
+ cmdline cmd(tokens);
+ cmd.set_options_description(desc);
+ cmd.allow_unregistered();
+
+ vector< option > opts = cmd.run();
+ vector< string > result = collect_unrecognized(opts, include_positional);
+
+ BOOST_CHECK_EQUAL(result.size(), 7);
+ BOOST_CHECK_EQUAL(result[0], "prg");
+ BOOST_CHECK_EQUAL(result[1], "--input");
+ BOOST_CHECK_EQUAL(result[2], "input.txt");
+ BOOST_CHECK_EQUAL(result[3], "--optimization");
+ BOOST_CHECK_EQUAL(result[4], "4");
+ BOOST_CHECK_EQUAL(result[5], "--opt");
+ BOOST_CHECK_EQUAL(result[6], "option");
+}
+
+
+
+void test_unrecognize_config()
+{
+
+ options_description desc;
+
+ string content =
+ " input = input.txt\n"
+ " optimization = 4\n"
+ " opt = option\n"
+ ;
+
+ stringstream ss(content);
+ vector< option > opts = parse_config_file(ss, desc, true).options;
+ vector< string > result = collect_unrecognized(opts, include_positional);
+
+ BOOST_CHECK_EQUAL(result.size(), 6);
+ BOOST_CHECK_EQUAL(result[0], "input");
+ BOOST_CHECK_EQUAL(result[1], "input.txt");
+ BOOST_CHECK_EQUAL(result[2], "optimization");
+ BOOST_CHECK_EQUAL(result[3], "4");
+ BOOST_CHECK_EQUAL(result[4], "opt");
+ BOOST_CHECK_EQUAL(result[5], "option");
+}
+
+
+
+int main(int /*ac*/, char** /*av*/)
+{
+ test_unrecognize_cmdline();
+ test_unrecognize_config();
+
+ return 0;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk