Compare commits

..

36 Commits

Author SHA1 Message Date
Ronald Garcia
2b9118089f Created a branch from trunk
[SVN r38959]
2007-08-26 05:34:35 +00:00
Vladimir Prus
8329c28a1a Apply patch to fix gcc warning.
Fixes #1209.


[SVN r38871]
2007-08-23 19:51:47 +00:00
Vladimir Prus
73cf706164 Remove V1 Jamfiles
[SVN r38516]
2007-08-08 19:02:26 +00:00
Vladimir Prus
e51a3ae742 Support for 'implicit' options.
Patch from Bryan Green.
Fixes #1131.


[SVN r38514]
2007-08-08 18:40:48 +00:00
Vladimir Prus
a0a661e4ec Fix examples Jamfile
[SVN r38507]
2007-08-08 17:15:09 +00:00
Vladimir Prus
c25408f6d2 Document config file support in more detail. Fixes #808. Fixes #1125.
[SVN r38495]
2007-08-07 13:55:41 +00:00
Vladimir Prus
63fca63679 Fix dependency
[SVN r38494]
2007-08-07 13:54:47 +00:00
Vladimir Prus
8c39e5aa8d When parsing vector<T>, use validator for
type T.
Fixes #1118.


[SVN r38459]
2007-08-05 18:38:07 +00:00
Vladimir Prus
d0aa5abee5 Implement support for unregistered options in config files. Closes #687.
[SVN r38191]
2007-07-11 19:39:06 +00:00
Vladimir Prus
90dc6b94d0 Clarify comment
[SVN r38190]
2007-07-11 19:37:51 +00:00
Vladimir Prus
2320c07267 Add todo
[SVN r38189]
2007-07-11 19:37:18 +00:00
Vladimir Prus
cd647f785a Fix #898. Two approximate matches followed by an exact match
no longer cause an ambiguity to be reported.


[SVN r38187]
2007-07-11 19:07:44 +00:00
Vladimir Prus
4223d3231d Fix typo
[SVN r38186]
2007-07-11 18:22:57 +00:00
Vladimir Prus
d1d5636365 Compilation fix for sun. Fixes #739.
[SVN r38109]
2007-06-28 07:09:38 +00:00
Vladimir Prus
c00c4a57db Define static const member in .cpp. Fixes #646.
[SVN r38108]
2007-06-28 07:05:50 +00:00
Vladimir Prus
8ad16ee97c Fix typo. Closes #749
[SVN r38107]
2007-06-28 06:54:11 +00:00
Vladimir Prus
0c3e43f2ce Fix typo. Closes #748
[SVN r38106]
2007-06-28 06:51:48 +00:00
Hartmut Kaiser
e42f028278 Fixed VC8 warnings about inconsistent dll export declarations.
[SVN r38099]
2007-06-26 19:13:33 +00:00
Eric Niebler
a29728e679 fix xincludes of doxygen-generated reference sections
[SVN r37571]
2007-05-03 01:18:48 +00:00
Vladimir Prus
232894cb3d Add missing include, to try to fix compilation on sun
[SVN r37005]
2007-02-19 19:27:54 +00:00
Daniel James
d39f2b5979 Merge fixed links from RC_1_34_0.
[SVN r36660]
2007-01-07 23:50:56 +00:00
Vladimir Prus
8c68a478c9 Fix dynamic linking
[SVN r35991]
2006-11-10 20:29:40 +00:00
Vladimir Prus
5d1345c5a9 Allow building of shared versions of some Boost.Test libraries.
Adjust tests to use always use static linking to Boost.Test, since
linking to the shared version requires test changes.

Patch from Juergen Hunold.


[SVN r35989]
2006-11-10 19:09:56 +00:00
Beman Dawes
a560d767fb Add copyright, license
[SVN r35905]
2006-11-07 19:11:57 +00:00
John Maddock
8c1982de82 Fix for Borland compilers.
[SVN r35652]
2006-10-18 12:33:54 +00:00
Vladimir Prus
928d7806f7 Make intel happy
[SVN r35034]
2006-09-07 08:06:16 +00:00
Hartmut Kaiser
b99ae04040 Fixed a dllimport/dllexport problem.
[SVN r34049]
2006-05-20 22:14:41 +00:00
Vladimir Prus
dc334deea7 Fix typo
[SVN r33990]
2006-05-18 06:06:18 +00:00
Vladimir Prus
de66d37405 Make positional_options_description::add return reference to *this.
[SVN r33989]
2006-05-18 05:59:56 +00:00
Vladimir Prus
a4375600a2 Make validation_error::what public, as it's public in std::exception.
[SVN r33969]
2006-05-15 14:05:47 +00:00
Vladimir Prus
bec34dd1b9 Note that variables_map is inherited from std::map, since BoostBook
"hides" that information.


[SVN r33786]
2006-04-24 09:50:30 +00:00
Vladimir Prus
7b73b2e84c Fix typos.
Thanks to Olaf van der Spek for the report!


[SVN r33784]
2006-04-24 09:41:22 +00:00
Vladimir Prus
2625de2dd0 If additional parser returns empty string as value, assume there's no value.
[SVN r33782]
2006-04-24 09:14:57 +00:00
Vladimir Prus
ac6de20f85 Clarify special handling of vectors.
[SVN r33780]
2006-04-24 08:51:38 +00:00
Vladimir Prus
3765e8e8e9 Fix accesses to first element of an empty string.
Thanks to Olaf van der Spek for the report.


[SVN r33778]
2006-04-24 08:25:12 +00:00
Vladimir Prus
026c527d8d Workaround "interator incremented past the end" assertion in MSVC-8.0.
[SVN r33776]
2006-04-24 08:00:13 +00:00
27 changed files with 100 additions and 332 deletions

View File

@@ -1,28 +0,0 @@
#
# Copyright Troy D. Straszheim
#
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
#
#----------------------------------------------------------------------------
# This file was automatically generated from the original CMakeLists.txt file
# Add a variable to hold the headers for the library
set (lib_headers
program_options.hpp
program_options
)
# Add a library target to the build system
boost_library_project(
program_options
SRCDIRS src
TESTDIRS test
HEADERS ${lib_headers}
# DOCDIRS
DESCRIPTION "Access to configuration data given on command line, in config files and other sources."
MODULARIZED
AUTHORS "Vladimir Prus <ghost -at- cs.msu.su>"
# MAINTAINERS
)

View File

@@ -17,4 +17,12 @@ lib boost_program_options
<link>shared:<define>BOOST_PROGRAM_OPTIONS_DYN_LINK=1 # tell source we're building dll's
;
boost-install boost_program_options ;
install dist-lib
:
boost_program_options
:
<install-type>LIB
<location>../../../dist/lib
;
explicit dist-lib ;

View File

@@ -5,7 +5,6 @@ toolset.using doxygen ;
boostbook program_option
: program_options.xml
: <implicit-dependency>autodoc
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
;
doxygen autodoc

View File

@@ -77,7 +77,7 @@ int main(int ac, char* av[])
cout << "Listen port is " << portnum << "\n";
}
catch(std::exception& e)
catch(exception& e)
{
cout << e.what() << "\n";
return 1;

View File

@@ -94,7 +94,7 @@ int main(int ac, char* av[])
<< vm["magic"].as<magic_number>().n << "\"\n";
}
}
catch(std::exception& e)
catch(exception& e)
{
cout << e.what() << "\n";
}

View File

@@ -3,8 +3,6 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See www.boost.org/libs/program_options for documentation.
#ifndef PROGRAM_OPTIONS_VP_2003_05_19
#define PROGRAM_OPTIONS_VP_2003_05_19

View File

@@ -8,8 +8,6 @@
#include <boost/program_options/detail/convert.hpp>
#include <iterator>
namespace boost { namespace program_options {
namespace detail {
@@ -40,7 +38,7 @@ namespace boost { namespace program_options {
: detail::cmdline(
// Explicit template arguments are required by gcc 3.3.1
// (at least mingw version), and do no harm on other compilers.
to_internal(detail::make_vector<charT, charT**>(argv+1, argv+argc+!argc)))
to_internal(detail::make_vector<charT, charT**>(argv+1, argv+argc)))
{}

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2001 Ronald Garcia, Indiana University (garcia@osl.iu.edu)
// Copyright © 2001 Ronald Garcia, Indiana University (garcia@osl.iu.edu)
// Andrew Lumsdaine, Indiana University (lums@osl.iu.edu). Permission to copy,
// use, modify, sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided "as is"

View File

@@ -55,12 +55,13 @@ namespace boost { namespace program_options {
{
static std::basic_string<charT> empty;
if (v.size() > 1)
boost::throw_exception(validation_error("multiple values not allowed"));
else if (v.size() == 1)
throw validation_error("multiple values not allowed");
if (v.size() == 1)
return v.front();
else if (!allow_empty)
boost::throw_exception(validation_error("at least one value required"));
return empty;
else if (allow_empty)
return empty;
else
throw validation_error("at least one value required");
}
/* Throws multiple_occurrences if 'value' is not empty. */

View File

@@ -41,7 +41,7 @@ namespace boost { namespace program_options {
add(const char* name, int max_count);
/** Returns the maximum number of positional options that can
be present. Can return (numeric_limits<unsigned>::max)() to
be present. Can return numeric_limits<unsigned>::max() to
indicate unlimited number. */
unsigned max_total_count() const;

View File

@@ -1 +0,0 @@
boost_module(program_options DEPENDS any bind smart_ptr test tokenizer)

View File

@@ -1,11 +0,0 @@
#
# Copyright Troy D. Straszheim
#
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
#
boost_add_library(boost_program_options
cmdline.cpp config_file.cpp options_description.cpp parsers.cpp
variables_map.cpp value_semantic.cpp positional_options.cpp
utf8_codecvt_facet.cpp convert.cpp winmain.cpp
SHARED_COMPILE_FLAGS "-DBOOST_PROGRAM_OPTIONS_DYN_LINK=1")

View File

@@ -23,7 +23,6 @@
#include <cassert>
#include <cstring>
#include <cctype>
#include <climits>
#include <cstdio>
@@ -99,10 +98,10 @@ namespace boost { namespace program_options { namespace detail {
{
#if defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)
vector<string> args;
copy(argv+1, argv+argc+!argc, inserter(args, args.end()));
copy(argv+1, argv+argc, inserter(args, args.end()));
init(args);
#else
init(vector<string>(argv+1, argv+argc+!argc));
init(vector<string>(argv+1, argv+argc));
#endif
}
@@ -152,7 +151,7 @@ namespace boost { namespace program_options { namespace detail {
error = "style disallows all characters for short options";
if (error)
boost::throw_exception(invalid_command_line_style(error));
throw invalid_command_line_style(error);
// Need to check that if guessing and long disguise are enabled
// -f will mean the same as -foo
@@ -196,24 +195,24 @@ namespace boost { namespace program_options { namespace detail {
if (m_additional_parser)
style_parsers.push_back(
boost::bind(&cmdline::handle_additional_parser, this, _1));
bind(&cmdline::handle_additional_parser, this, _1));
if (m_style & allow_long)
style_parsers.push_back(
boost::bind(&cmdline::parse_long_option, this, _1));
bind(&cmdline::parse_long_option, this, _1));
if ((m_style & allow_long_disguise))
style_parsers.push_back(
boost::bind(&cmdline::parse_disguised_long_option, this, _1));
bind(&cmdline::parse_disguised_long_option, this, _1));
if ((m_style & allow_short) && (m_style & allow_dash_for_short))
style_parsers.push_back(
boost::bind(&cmdline::parse_short_option, this, _1));
bind(&cmdline::parse_short_option, this, _1));
if ((m_style & allow_short) && (m_style & allow_slash_for_short))
style_parsers.push_back(boost::bind(&cmdline::parse_dos_option, this, _1));
style_parsers.push_back(bind(&cmdline::parse_dos_option, this, _1));
style_parsers.push_back(boost::bind(&cmdline::parse_terminator, this, _1));
style_parsers.push_back(bind(&cmdline::parse_terminator, this, _1));
vector<option> result;
while(!args.empty())
@@ -255,62 +254,6 @@ namespace boost { namespace program_options { namespace detail {
}
}
/* If an key option is followed by a positional option,
can can consume more tokens (e.g. it's multitoke option),
give those tokens to it. */
vector<option> result2;
for (unsigned i = 0; i < result.size(); ++i)
{
result2.push_back(result[i]);
option& opt = result2.back();
if (opt.string_key.empty())
continue;
const option_description* xd =
m_desc->find_nothrow(opt.string_key,
(m_style & allow_guessing));
if (!xd)
continue;
unsigned min_tokens = xd->semantic()->min_tokens();
unsigned max_tokens = xd->semantic()->max_tokens();
if (min_tokens < max_tokens && opt.value.size() < max_tokens)
{
// This option may grab some more tokens.
// We only allow to grab tokens that are not already
// recognized as key options.
int can_take_more = max_tokens - opt.value.size();
unsigned j = i+1;
for (; can_take_more && j < result.size(); --can_take_more, ++j)
{
option& opt2 = result[j];
if (!opt2.string_key.empty())
break;
if (opt2.position_key == INT_MAX)
{
// We use INT_MAX to mark positional options that
// were found after the '--' terminator and therefore
// should stay positional forever.
break;
}
assert(opt2.value.size() == 1);
opt.value.push_back(opt2.value[0]);
assert(opt2.original_tokens.size() == 1);
opt.original_tokens.push_back(opt2.original_tokens[0]);
}
i = j-1;
}
}
result.swap(result2);
// Assign position keys to positional options.
int position_key = 0;
for(unsigned i = 0; i < result.size(); ++i) {
@@ -326,8 +269,8 @@ namespace boost { namespace program_options { namespace detail {
if (opt.position_key != -1) {
if (position >= m_positional->max_total_count())
{
boost::throw_exception(too_many_positional_options_error(
"too many positional options"));
throw too_many_positional_options_error(
"too many positional options");
}
opt.string_key = m_positional->name_for_position(position);
++position;
@@ -347,8 +290,8 @@ namespace boost { namespace program_options { namespace detail {
// First check that the option is valid, and get its description.
// TODO: case-sensitivity.
const option_description* xd = m_desc->find_nothrow(opt.string_key,
(m_style & allow_guessing) ? true : false);
const option_description* xd =
m_desc->find_nothrow(opt.string_key, (m_style & allow_guessing));
if (!xd)
{
@@ -380,25 +323,22 @@ namespace boost { namespace program_options { namespace detail {
if (present_tokens >= min_tokens)
{
if (!opt.value.empty() && max_tokens == 0) {
boost::throw_exception(invalid_command_line_syntax(opt.string_key,
invalid_command_line_syntax::extra_parameter));
throw invalid_command_line_syntax(opt.string_key,
invalid_command_line_syntax::extra_parameter);
}
// If an option wants, at minimum, N tokens, we grab them
// there and don't care if they look syntactically like an
// option.
max_tokens -= opt.value.size();
if (opt.value.size() <= min_tokens)
{
min_tokens -= opt.value.size();
}
else
{
min_tokens = 0;
}
// A value is optional if min_tokens == 0, but max_tokens > 0.
// If a value is optional, it must appear in opt.value (because
// it was 'adjacent'. Otherwise, remove the expectation of a
// non-adjacent value. (For now, we just check max_tokens == 1,
// as there is no current support for max_tokens>1)
if (min_tokens == 0 && max_tokens == 1 && opt.value.empty())
--max_tokens;
// Everything's OK, move the values to the result.
for(;!other_tokens.empty() && min_tokens--; ) {
for(;!other_tokens.empty() && max_tokens--; ) {
opt.value.push_back(other_tokens[0]);
opt.original_tokens.push_back(other_tokens[0]);
other_tokens.erase(other_tokens.begin());
@@ -406,8 +346,8 @@ namespace boost { namespace program_options { namespace detail {
}
else
{
boost::throw_exception(invalid_command_line_syntax(opt.string_key,
invalid_command_line_syntax::missing_parameter));
throw invalid_command_line_syntax(opt.string_key,
invalid_command_line_syntax::missing_parameter);
}
}
@@ -427,8 +367,8 @@ namespace boost { namespace program_options { namespace detail {
name = tok.substr(2, p-2);
adjacent = tok.substr(p+1);
if (adjacent.empty())
boost::throw_exception( invalid_command_line_syntax(name,
invalid_command_line_syntax::empty_adjacent_parameter));
throw invalid_command_line_syntax(name,
invalid_command_line_syntax::empty_adjacent_parameter);
}
else
{
@@ -530,8 +470,7 @@ namespace boost { namespace program_options { namespace detail {
((m_style & allow_slash_for_short) && tok[0] == '/')))
{
if (m_desc->find_nothrow(tok.substr(1, tok.find('=')-1),
(m_style & allow_guessing) ? true : false))
{
m_style & allow_guessing)) {
args[0].insert(0, "-");
if (args[0][1] == '/')
args[0][1] = '-';
@@ -552,8 +491,6 @@ namespace boost { namespace program_options { namespace detail {
{
option opt;
opt.value.push_back(args[i]);
opt.original_tokens.push_back(args[i]);
opt.position_key = INT_MAX;
result.push_back(opt);
}
args.clear();

View File

@@ -408,7 +408,7 @@ namespace boost { namespace program_options {
{
// is last_space within the second half ot the
// current line
if ((unsigned)distance(last_space, line_end) <
if (unsigned(distance(last_space, line_end)) <
(line_length - indent) / 2)
{
line_end = last_space;

View File

@@ -67,16 +67,10 @@ namespace boost { namespace program_options {
woption result;
result.string_key = opt.string_key;
result.position_key = opt.position_key;
result.unregistered = opt.unregistered;
std::transform(opt.value.begin(), opt.value.end(),
back_inserter(result.value),
boost::bind(from_utf8, _1));
std::transform(opt.original_tokens.begin(),
opt.original_tokens.end(),
back_inserter(result.original_tokens),
boost::bind(from_utf8, _1));
bind(from_utf8, _1));
return result;
}
}

View File

@@ -74,13 +74,11 @@ namespace boost { namespace program_options {
try {
d.semantic()->parse(v.value(), options.options[i].value, utf8);
}
#ifndef BOOST_NO_EXCEPTIONS
catch(validation_error& e)
{
e.set_option_name(name);
throw;
}
#endif
v.m_value_semantic = d.semantic();
// The option is not composing, and the value is explicitly
@@ -135,16 +133,7 @@ namespace boost { namespace program_options {
k != vm.end();
++k)
{
/* Users might wish to use variables_map to store their own values
that are not parsed, and therefore will not have value_semantics
defined. Do no crash on such values. In multi-module programs,
one module might add custom values, and the 'notify' function
will be called after that, so we check that value_sematics is
not NULL. See:
https://svn.boost.org/trac/boost/ticket/2782
*/
if (k->second.m_value_semantic)
k->second.m_value_semantic->notify(k->second.value());
k->second.m_value_semantic->notify(k->second.value());
}
}

View File

@@ -1,39 +0,0 @@
#
# Copyright Troy D. Straszheim
#
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
#
boost_additional_test_dependencies(program_options BOOST_DEPENDS test)
set(PROGRAM_OPTIONS_LIBRARIES
boost_program_options
boost_test_exec_monitor)
set(BOOST_TEST_EXEC_MONITOR_SUFFIX "")
if (NOT BUILD_SINGLE_THREADED)
set(BOOST_TEST_EXEC_MONITOR_SUFFIX "-mt")
endif()
set(BOOST_TEST_EXEC_MONITOR_SUFFIX "${BOOST_TEST_EXEC_MONITOR_SUFFIX}-static")
if (NOT BUILD_RELEASE)
set(BOOST_TEST_EXEC_MONITOR_SUFFIX "${BOOST_TEST_EXEC_MONITOR_SUFFIX}-debug")
endif()
macro(program_options_test_run TESTNAME)
boost_test_run(${TESTNAME}
STATIC
DEPENDS boost_program_options boost_test_exec_monitor )
boost_test_run("${TESTNAME}_dll"
${TESTNAME}.cpp
SHARED
DEPENDS boost_program_options
"boost_test_exec_monitor${BOOST_TEST_EXEC_MONITOR_SUFFIX}")
endmacro(program_options_test_run)
program_options_test_run(options_description_test)
program_options_test_run(parsers_test)
program_options_test_run(variable_map_test)
program_options_test_run(cmdline_test)
program_options_test_run(positional_options_test)
program_options_test_run(unicode_test)
program_options_test_run(winmain)

View File

@@ -2,8 +2,8 @@
project
: requirements
<library>../build//boost_program_options
<library>/boost/test//boost_test_exec_monitor/<link>static
<link>static
<variant>debug
# <define>_GLIBCXX_CONCEPT_CHECKS
# <define>_GLIBCXX_DEBUG

View File

@@ -9,14 +9,15 @@
using namespace boost::program_options;
using boost::program_options::detail::cmdline;
#include <boost/test/test_tools.hpp>
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
using namespace std;
#include "minitest.hpp"
/* To facilitate testing, declare a number of error codes. Otherwise,
we'd have to specify the type of exception that should be thrown.
*/
@@ -599,7 +600,7 @@ void test_unregistered()
// It's not clear yet, so I'm leaving the decision till later.
}
int main(int ac, char* av[])
int test_main(int ac, char* av[])
{
test_long_options();
test_short_options();

View File

@@ -1,25 +0,0 @@
#ifndef BOOST_PROGRAM_OPTIONS_MINITEST
#define BOOST_PROGRAM_OPTIONS_MINITEST
#include <assert.h>
#include <iostream>
#include <stdlib.h>
#define BOOST_REQUIRE(b) assert(b)
#define BOOST_CHECK(b) assert(b)
#define BOOST_CHECK_EQUAL(a, b) assert(a == b)
#define BOOST_ERROR(description) std::cerr << description; std::cerr << "\n"; abort();
#define BOOST_CHECK_THROW(expression, exception) \
try \
{ \
expression; \
BOOST_ERROR("expected exception not thrown");\
throw 10; \
} \
catch(exception &) \
{ \
}
#endif

View File

@@ -10,13 +10,14 @@ using namespace boost::program_options;
#include <boost/function.hpp>
using namespace boost;
#define BOOST_INCLUDE_MAIN // for testing, include rather than link
#include <boost/test/test_tools.hpp>
#include <utility>
#include <string>
#include <sstream>
using namespace std;
#include "minitest.hpp"
void test_type()
{
options_description desc;
@@ -76,7 +77,7 @@ void test_formatting()
ss << desc;
}
int main(int, char* [])
int test_main(int, char* [])
{
test_type();
test_approximation();

View File

@@ -14,6 +14,9 @@ namespace po = boost::program_options;
#include <boost/function.hpp>
using namespace boost;
#define BOOST_INCLUDE_MAIN // for testing, include rather than link
#include <boost/test/test_tools.hpp>
#include <sstream>
#include <iostream>
using namespace std;
@@ -24,8 +27,6 @@ using namespace std;
#include <cstdlib> // for putenv
#endif
#include "minitest.hpp"
#define TEST_CHECK_THROW(expression, exception, description) \
try \
{ \
@@ -146,52 +147,8 @@ void test_command_line()
variables_map vm;
po::store(po::parse_command_line(3, cmdline4, desc2), vm);
char* cmdline5[] = {"", "-p7", "-o", "1", "2", "3", "-x8"};
options_description desc3;
desc3.add_options()
(",p", po::value<string>())
(",o", po::value<string>()->multitoken())
(",x", po::value<string>())
;
vector<option> a5 =
parse_command_line(7, cmdline5, desc3, 0, additional_parser).options;
BOOST_CHECK_EQUAL(a5.size(), 3u);
check_value(a5[0], "-p", "7");
BOOST_REQUIRE(a5[1].value.size() == 3);
BOOST_CHECK_EQUAL(a5[1].string_key, "-o");
BOOST_CHECK_EQUAL(a5[1].value[0], "1");
BOOST_CHECK_EQUAL(a5[1].value[1], "2");
BOOST_CHECK_EQUAL(a5[1].value[2], "3");
check_value(a5[2], "-x", "8");
po::options_description desc4( "" );
desc4.add_options()
( "multitoken,m",
po::value< std::vector< std::string > >()->multitoken(),
"values"
)
( "file",
po::value< std::string >(),
"the file to process"
)
;
po::positional_options_description p;
p.add( "file", 1 );
char* cmdline6[] = {"", "-m", "token1", "token2", "--", "some_file"};
vector<option> a6 =
command_line_parser(6, cmdline6).options(desc4).positional(p)
.run().options;
BOOST_CHECK_EQUAL(a6.size(), 2u);
BOOST_REQUIRE(a6[0].value.size() == 2);
BOOST_CHECK_EQUAL(a6[0].string_key, "multitoken");
BOOST_CHECK_EQUAL(a6[0].value[0], "token1");
BOOST_CHECK_EQUAL(a6[0].value[1], "token2");
BOOST_CHECK_EQUAL(a6[1].string_key, "file");
BOOST_REQUIRE(a6[1].value.size() == 1);
BOOST_CHECK_EQUAL(a6[1].value[0], "some_file");
}
void test_config_file()
@@ -302,7 +259,7 @@ void test_unregistered()
check_value(a3[1], "m1.v1", "1");
}
int main(int, char* [])
int test_main(int, char* [])
{
test_command_line();
test_config_file();

View File

@@ -12,8 +12,7 @@ namespace po = boost::program_options;
#include <boost/limits.hpp>
#include "minitest.hpp"
#include <boost/test/test_tools.hpp>
#include <vector>
using namespace std;
@@ -82,7 +81,7 @@ void test_parsing()
too_many_positional_options_error);
}
int main(int, char* [])
int test_main(int, char* [])
{
test_positional_options();
test_parsing();

View File

@@ -15,7 +15,7 @@
#include <boost/program_options/detail/convert.hpp>
#include <boost/program_options/detail/utf8_codecvt_facet.hpp>
#include "minitest.hpp"
#include <boost/test/test_tools.hpp>
using namespace std;
@@ -121,7 +121,7 @@ void test_convert(const std::string& input,
BOOST_CHECK(ref == input);
}
int main(int ac, char* av[])
int test_main(int ac, char* av[])
{
std::string input = file_content("utf8.txt");
std::string expected = file_content("ucs2.txt");

View File

@@ -15,11 +15,12 @@ namespace po = boost::program_options;
#include <boost/function.hpp>
using namespace boost;
#define BOOST_INCLUDE_MAIN // for testing, include rather than link
#include <boost/test/test_tools.hpp>
#include <sstream>
using namespace std;
#include "minitest.hpp"
// Test that unicode input is forwarded to unicode option without
// problems.
void test_unicode_to_unicode()
@@ -34,13 +35,9 @@ void test_unicode_to_unicode()
args.push_back(L"--foo=\x044F");
variables_map vm;
basic_parsed_options<wchar_t> parsed =
wcommand_line_parser(args).options(desc).run();
store(parsed, vm);
store(wcommand_line_parser(args).options(desc).run(), vm);
BOOST_CHECK(vm["foo"].as<wstring>() == L"\x044F");
BOOST_CHECK(parsed.options[0].original_tokens.size() == 1);
BOOST_CHECK(parsed.options[0].original_tokens[0] == L"--foo=\x044F");
BOOST_CHECK(vm["foo"].as<wstring>() == L"\x044F");
}
// Test that unicode input is property converted into
@@ -152,7 +149,7 @@ void test_config_file()
BOOST_CHECK(vm["foo"].as<string>() == "\xD1\x8F");
}
int main(int, char* [])
int test_main(int, char* [])
{
test_unicode_to_unicode();
test_unicode_to_native();

View File

@@ -15,10 +15,22 @@ namespace po = boost::program_options;
#include <boost/function.hpp>
using namespace boost;
#define BOOST_INCLUDE_MAIN // for testing, include rather than link
#include <boost/test/test_tools.hpp>
#include <sstream>
using namespace std;
#include "minitest.hpp"
#define TEST_CHECK_THROW(expression, exception, description) \
try \
{ \
expression; \
BOOST_ERROR(description);\
throw 10; \
} \
catch(exception &) \
{ \
}
vector<string> sv(char* array[], unsigned size)
{
@@ -96,11 +108,8 @@ void test_variable_map()
("imp", po::value<int>()->implicit_value(100))
("iim", po::value<int>()->implicit_value(200)->default_value(201))
("mmp,m", po::value<int>()->implicit_value(123)->default_value(124))
("foo", po::value<int>())
;
/* The -m option is implicit. It does not have value in inside the token,
and we should not grab the next token. */
char* cmdline6_[] = { "--imp=1", "-m", "--foo=1" };
char* cmdline6_[] = { "--imp=1", "-m" };
vector<string> cmdline6 = sv(cmdline6_,
sizeof(cmdline6_)/sizeof(cmdline6_[0]));
parsed_options a6 = command_line_parser(cmdline6).options(desc3).run();
@@ -108,7 +117,7 @@ void test_variable_map()
variables_map vm4;
store(a6, vm4);
notify(vm4);
BOOST_REQUIRE(vm4.size() == 4);
BOOST_REQUIRE(vm4.size() == 3);
BOOST_CHECK(vm4["imp"].as<int>() == 1);
BOOST_CHECK(vm4["iim"].as<int>() == 201);
BOOST_CHECK(vm4["mmp"].as<int>() == 123);
@@ -279,7 +288,7 @@ void test_multiple_assignments_with_different_option_description()
}
int main(int, char* [])
int test_main(int, char* [])
{
test_variable_map();
test_semantic_values();

View File

@@ -7,42 +7,26 @@
#include <string>
#include <vector>
#include <cctype>
#include <iostream>
#include <stdlib.h>
using namespace std;
#include <boost/program_options/parsers.hpp>
using namespace boost::program_options;
void check_equal(const std::vector<string>& actual, char **expected, int n)
{
if (actual.size() != n)
{
std::cerr << "Size mismatch between expected and actual data\n";
abort();
}
for (int i = 0; i < n; ++i)
{
if (actual[i] != expected[i])
{
std::cerr << "Unexpected content\n";
abort();
}
}
}
#include <boost/test/test_tools.hpp>
#include <boost/preprocessor/cat.hpp>
void test_winmain()
{
using namespace std;
#define C ,
#define TEST(input, expected) \
char* BOOST_PP_CAT(e, __LINE__)[] = expected;\
vector<string> BOOST_PP_CAT(v, __LINE__) = split_winmain(input);\
check_equal(BOOST_PP_CAT(v, __LINE__), BOOST_PP_CAT(e, __LINE__),\
sizeof(BOOST_PP_CAT(e, __LINE__))/sizeof(char*));
BOOST_CHECK_EQUAL_COLLECTIONS(BOOST_PP_CAT(v, __LINE__).begin(),\
BOOST_PP_CAT(v, __LINE__).end(),\
BOOST_PP_CAT(e, __LINE__),\
BOOST_PP_CAT(e, __LINE__) + \
sizeof(BOOST_PP_CAT(e, __LINE__))/sizeof(char*));
// The following expectations were obtained in Win2000 shell:
TEST("1 ", {"1"});
@@ -61,13 +45,13 @@ void test_winmain()
TEST("1\\\\1 ", {"1\\\\1"});
}
int main(int, char*[])
int test_main(int, char*[])
{
test_winmain();
return 0;
}
#else
int main(int, char*[])
int test_main(int, char*[])
{
return 0;
}