mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
New version of Clara.
- updated command line setup with new API - updated STITCH macros - force embedded Clara to use Catch’s console width (but restore it after) - remove command line tests (as these have now moved into the Clara project)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* CATCH v1.0 build 27 (master branch)
|
||||
* Generated: 2014-03-01 10:36:25.999888
|
||||
* Generated: 2014-03-06 08:06:07.489513
|
||||
* ----------------------------------------------------------
|
||||
* This file has been merged from multiple headers. Please don't edit it directly
|
||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||
@@ -3005,19 +3005,29 @@ namespace Catch {
|
||||
// #included from: catch_clara.h
|
||||
#define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
|
||||
|
||||
// Use Catch's value for console width (store Clara's off to the side, if present)
|
||||
#ifdef CLARA_CONFIG_CONSOLE_WIDTH
|
||||
#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
|
||||
#undef CLARA_CONFIG_CONSOLE_WIDTH
|
||||
#endif
|
||||
#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
|
||||
|
||||
// Declare Clara inside the Catch namespace
|
||||
#define STITCH_CLARA_OUTER_NAMESPACE Catch
|
||||
#define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
|
||||
// #included from: clara.h
|
||||
|
||||
// Only use header guard if we are not using an outer namespace
|
||||
#if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OUTER_NAMESPACE)
|
||||
#ifndef STITCH_CLARA_OUTER_NAMESPACE
|
||||
#if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE)
|
||||
|
||||
#ifndef STITCH_CLARA_OPEN_NAMESPACE
|
||||
#define TWOBLUECUBES_CLARA_H_INCLUDED
|
||||
#define STITCH_CLARA_OPEN_NAMESPACE
|
||||
#define STITCH_CLARA_CLOSE_NAMESPACE
|
||||
#else
|
||||
#define STITCH_CLARA_CLOSE_NAMESPACE }
|
||||
#endif
|
||||
|
||||
#define STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE Clara
|
||||
#define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE
|
||||
|
||||
// ----------- #included from tbc_text_format.h -----------
|
||||
|
||||
@@ -3166,7 +3176,7 @@ namespace Tbc {
|
||||
// ----------- end of #include from tbc_text_format.h -----------
|
||||
// ........... back in /Users/philnash/Dev/OSS/Clara/srcs/clara.h
|
||||
|
||||
#undef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
|
||||
#undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE
|
||||
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
@@ -3174,11 +3184,20 @@ namespace Tbc {
|
||||
#include <memory>
|
||||
|
||||
// Use optional outer namespace
|
||||
#ifdef STITCH_CLARA_OUTER_NAMESPACE
|
||||
namespace STITCH_CLARA_OUTER_NAMESPACE {
|
||||
#ifdef STITCH_CLARA_OPEN_NAMESPACE
|
||||
STITCH_CLARA_OPEN_NAMESPACE
|
||||
#endif
|
||||
|
||||
namespace Clara {
|
||||
|
||||
struct UnpositionalTag {};
|
||||
|
||||
extern UnpositionalTag _;
|
||||
|
||||
#ifdef CLARA_CONFIG_MAIN
|
||||
UnpositionalTag _;
|
||||
#endif
|
||||
|
||||
namespace Detail {
|
||||
|
||||
#ifdef CLARA_CONSOLE_WIDTH
|
||||
@@ -3187,7 +3206,11 @@ namespace Clara {
|
||||
const unsigned int consoleWidth = 80;
|
||||
#endif
|
||||
|
||||
using namespace ::Clara::Tbc;
|
||||
using namespace Tbc;
|
||||
|
||||
inline bool startsWith( std::string const& str, std::string const& prefix ) {
|
||||
return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix;
|
||||
}
|
||||
|
||||
template<typename T> struct RemoveConstRef{ typedef T type; };
|
||||
template<typename T> struct RemoveConstRef<T&>{ typedef T type; };
|
||||
@@ -3238,6 +3261,7 @@ namespace Clara {
|
||||
template<typename ConfigT>
|
||||
class BoundArgFunction {
|
||||
public:
|
||||
BoundArgFunction() : functionObj( NULL ) {}
|
||||
BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {}
|
||||
BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj->clone() ) {}
|
||||
BoundArgFunction& operator = ( BoundArgFunction const& other ) {
|
||||
@@ -3419,6 +3443,7 @@ namespace Clara {
|
||||
class CommandLine {
|
||||
|
||||
struct Arg {
|
||||
Arg() : position( -1 ) {}
|
||||
Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ), position( -1 ) {}
|
||||
|
||||
bool hasShortName( std::string const& shortName ) const {
|
||||
@@ -3434,7 +3459,7 @@ namespace Clara {
|
||||
return _longName == longName;
|
||||
}
|
||||
bool takesArg() const {
|
||||
return !hint.empty();
|
||||
return !placeholder.empty();
|
||||
}
|
||||
bool isFixedPositional() const {
|
||||
return position != -1;
|
||||
@@ -3451,7 +3476,7 @@ namespace Clara {
|
||||
}
|
||||
void validate() const {
|
||||
if( boundField.takesArg() && !takesArg() )
|
||||
throw std::logic_error( "command line argument '" + dbgName() + "' must specify a hint" );
|
||||
throw std::logic_error( "command line argument '" + dbgName() + "' must specify a placeholder" );
|
||||
}
|
||||
std::string commands() const {
|
||||
std::ostringstream oss;
|
||||
@@ -3469,8 +3494,8 @@ namespace Clara {
|
||||
oss << ", ";
|
||||
oss << "--" << longName;
|
||||
}
|
||||
if( !hint.empty() )
|
||||
oss << " <" << hint << ">";
|
||||
if( !placeholder.empty() )
|
||||
oss << " <" << placeholder << ">";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
@@ -3478,7 +3503,7 @@ namespace Clara {
|
||||
std::vector<std::string> shortNames;
|
||||
std::string longName;
|
||||
std::string description;
|
||||
std::string hint;
|
||||
std::string placeholder;
|
||||
int position;
|
||||
};
|
||||
|
||||
@@ -3489,14 +3514,13 @@ namespace Clara {
|
||||
typedef std::auto_ptr<Arg> ArgAutoPtr;
|
||||
#endif
|
||||
|
||||
class ArgBinder {
|
||||
class ArgBuilder {
|
||||
public:
|
||||
template<typename F>
|
||||
ArgBinder( CommandLine* cl, F f )
|
||||
: m_cl( cl ),
|
||||
m_arg( Detail::makeBoundField( f ) )
|
||||
ArgBuilder( CommandLine* cl )
|
||||
: m_cl( cl )
|
||||
{}
|
||||
ArgBinder( ArgBinder& other )
|
||||
|
||||
ArgBuilder( ArgBuilder& other )
|
||||
: m_cl( other.m_cl ),
|
||||
m_arg( other.m_arg )
|
||||
{
|
||||
@@ -3504,7 +3528,7 @@ namespace Clara {
|
||||
}
|
||||
// !TBD: Need to include workarounds to be able to declare this
|
||||
// destructor as able to throw exceptions
|
||||
~ArgBinder() /* noexcept(false) */ {
|
||||
~ArgBuilder() /* noexcept(false) */ {
|
||||
if( m_cl && !std::uncaught_exception() ) {
|
||||
m_arg.validate();
|
||||
if( m_arg.isFixedPositional() ) {
|
||||
@@ -3521,30 +3545,65 @@ namespace Clara {
|
||||
m_cl->m_options.push_back( m_arg );
|
||||
}
|
||||
}
|
||||
ArgBinder& shortOpt( std::string const& name ) {
|
||||
m_arg.shortNames.push_back( name );
|
||||
|
||||
template<typename F>
|
||||
void into( F f )
|
||||
{
|
||||
m_arg.boundField = Detail::makeBoundField( f );
|
||||
}
|
||||
|
||||
friend void addOptName( ArgBuilder& builder, std::string const& optName )
|
||||
{
|
||||
if( optName.empty() )
|
||||
return;
|
||||
if( Detail::startsWith( optName, "--" ) ) {
|
||||
if( !builder.m_arg.longName.empty() )
|
||||
throw std::logic_error( "Only one long opt may be specified. '"
|
||||
+ builder.m_arg.longName
|
||||
+ "' already specified, now attempting to add '"
|
||||
+ optName + "'" );
|
||||
builder.m_arg.longName = optName.substr( 2 );
|
||||
}
|
||||
else if( Detail::startsWith( optName, "-" ) )
|
||||
builder.m_arg.shortNames.push_back( optName.substr( 1 ) );
|
||||
else
|
||||
throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" );
|
||||
}
|
||||
friend void setPositionalArg( ArgBuilder& builder, int position )
|
||||
{
|
||||
builder.m_arg.position = position;
|
||||
}
|
||||
|
||||
// Can only supply placeholder after [str] - if it takes an arg
|
||||
ArgBuilder& placeholder( std::string const& placeholder ) {
|
||||
m_arg.placeholder = placeholder;
|
||||
return *this;
|
||||
}
|
||||
ArgBinder& longOpt( std::string const& name ) {
|
||||
m_arg.longName = name;
|
||||
return *this;
|
||||
}
|
||||
ArgBinder& describe( std::string const& description ) {
|
||||
|
||||
ArgBuilder& describe( std::string const& description ) {
|
||||
m_arg.description = description;
|
||||
return *this;
|
||||
}
|
||||
ArgBinder& hint( std::string const& hint ) {
|
||||
m_arg.hint = hint;
|
||||
return *this;
|
||||
}
|
||||
ArgBinder& position( int position ) {
|
||||
m_arg.position = position;
|
||||
ArgBuilder& detail( std::string const& ) {
|
||||
// m_arg.description = description;
|
||||
// !TBD
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
CommandLine* m_cl;
|
||||
Arg m_arg;
|
||||
};
|
||||
class OptBuilder : public ArgBuilder {
|
||||
public:
|
||||
OptBuilder( CommandLine* cl ) : ArgBuilder( cl ) {}
|
||||
OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
|
||||
|
||||
OptBuilder& operator[]( std::string const& optName ) {
|
||||
addOptName( *this, optName );
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
@@ -3569,11 +3628,24 @@ namespace Clara {
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
ArgBinder bind( F f ) {
|
||||
ArgBinder binder( this, f );
|
||||
return binder;
|
||||
OptBuilder operator[]( std::string const& optName ) {
|
||||
OptBuilder builder( this );
|
||||
addOptName( builder, optName );
|
||||
return builder;
|
||||
}
|
||||
|
||||
ArgBuilder operator[]( int position ) {
|
||||
ArgBuilder builder( this );
|
||||
setPositionalArg( builder, position );
|
||||
return builder;
|
||||
}
|
||||
|
||||
// Invoke this with the _ instance
|
||||
ArgBuilder operator[]( UnpositionalTag ) {
|
||||
ArgBuilder builder( this );
|
||||
return builder;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
void bindProcessName( F f ) {
|
||||
m_boundProcessName = Detail::makeBoundField( f );
|
||||
@@ -3616,9 +3688,9 @@ namespace Clara {
|
||||
os << " ";
|
||||
typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
|
||||
if( it != m_positionalArgs.end() )
|
||||
os << "<" << it->second.hint << ">";
|
||||
os << "<" << it->second.placeholder << ">";
|
||||
else if( m_arg.get() )
|
||||
os << "<" << m_arg->hint << ">";
|
||||
os << "<" << m_arg->placeholder << ">";
|
||||
else
|
||||
throw std::logic_error( "non consecutive positional arguments with no floating args" );
|
||||
}
|
||||
@@ -3626,7 +3698,7 @@ namespace Clara {
|
||||
if( m_arg.get() ) {
|
||||
if( m_highestSpecifiedArgPosition > 1 )
|
||||
os << " ";
|
||||
os << "[<" << m_arg->hint << "> ...]";
|
||||
os << "[<" << m_arg->placeholder << "> ...]";
|
||||
}
|
||||
}
|
||||
std::string argSynopsis() const {
|
||||
@@ -3766,12 +3838,18 @@ namespace Clara {
|
||||
|
||||
} // end namespace Clara
|
||||
|
||||
#ifdef STITCH_CLARA_OUTER_NAMESPACE
|
||||
} // end outer namespace
|
||||
#endif
|
||||
STITCH_CLARA_CLOSE_NAMESPACE
|
||||
#undef STITCH_CLARA_OPEN_NAMESPACE
|
||||
#undef STITCH_CLARA_CLOSE_NAMESPACE
|
||||
|
||||
#endif // TWOBLUECUBES_CLARA_H_INCLUDED
|
||||
#undef STITCH_CLARA_OUTER_NAMESPACE
|
||||
#undef STITCH_CLARA_OPEN_NAMESPACE
|
||||
|
||||
// Restore Clara's value for console width, if present
|
||||
#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||
#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||
#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
|
||||
@@ -3816,107 +3894,95 @@ namespace Catch {
|
||||
|
||||
inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
|
||||
|
||||
Clara::CommandLine<ConfigData> cli;
|
||||
using namespace Clara;
|
||||
CommandLine<ConfigData> cli;
|
||||
|
||||
cli.bindProcessName( &ConfigData::processName );
|
||||
|
||||
cli.bind( &ConfigData::showHelp )
|
||||
cli["-?"]["-h"]["--help"]
|
||||
.describe( "display usage information" )
|
||||
.shortOpt( "?")
|
||||
.shortOpt( "h")
|
||||
.longOpt( "help" );
|
||||
.into( &ConfigData::showHelp );
|
||||
|
||||
cli.bind( &ConfigData::listTests )
|
||||
cli["-l"]["--list-tests"]
|
||||
.describe( "list all/matching test cases" )
|
||||
.shortOpt( "l")
|
||||
.longOpt( "list-tests" );
|
||||
.into( &ConfigData::listTests );
|
||||
|
||||
cli.bind( &ConfigData::listTags )
|
||||
cli["-t"]["--list-tags"]
|
||||
.describe( "list all/matching tags" )
|
||||
.shortOpt( "t")
|
||||
.longOpt( "list-tags" );
|
||||
.into( &ConfigData::listTags );
|
||||
|
||||
cli.bind( &ConfigData::showSuccessfulTests )
|
||||
cli["-s"]["--success"]
|
||||
.describe( "include successful tests in output" )
|
||||
.shortOpt( "s")
|
||||
.longOpt( "success" );
|
||||
.into( &ConfigData::showSuccessfulTests );
|
||||
|
||||
cli.bind( &ConfigData::shouldDebugBreak )
|
||||
cli["-b"]["--break"]
|
||||
.describe( "break into debugger on failure" )
|
||||
.shortOpt( "b")
|
||||
.longOpt( "break" );
|
||||
.into( &ConfigData::shouldDebugBreak );
|
||||
|
||||
cli.bind( &ConfigData::noThrow )
|
||||
cli["-e"]["--nothrow"]
|
||||
.describe( "skip exception tests" )
|
||||
.shortOpt( "e")
|
||||
.longOpt( "nothrow" );
|
||||
.into( &ConfigData::noThrow );
|
||||
|
||||
cli.bind( &ConfigData::outputFilename )
|
||||
cli["-o"]["--out"]
|
||||
.placeholder( "filename" )
|
||||
.describe( "output filename" )
|
||||
.shortOpt( "o")
|
||||
.longOpt( "out" )
|
||||
.hint( "filename" );
|
||||
.into( &ConfigData::outputFilename );
|
||||
|
||||
cli.bind( &ConfigData::reporterName )
|
||||
cli["-r"]["--reporter"]
|
||||
// .placeholder( "name[:filename]" )
|
||||
.placeholder( "name" )
|
||||
.describe( "reporter to use (defaults to console)" )
|
||||
.shortOpt( "r")
|
||||
.longOpt( "reporter" )
|
||||
// .hint( "name[:filename]" );
|
||||
.hint( "name" );
|
||||
.into( &ConfigData::reporterName );
|
||||
|
||||
cli.bind( &ConfigData::name )
|
||||
cli["-n"]["--name"]
|
||||
.placeholder( "name" )
|
||||
.describe( "suite name" )
|
||||
.shortOpt( "n")
|
||||
.longOpt( "name" )
|
||||
.hint( "name" );
|
||||
.into( &ConfigData::name );
|
||||
|
||||
cli.bind( &abortAfterFirst )
|
||||
cli["-a"]["--abort"]
|
||||
.describe( "abort at first failure" )
|
||||
.shortOpt( "a")
|
||||
.longOpt( "abort" );
|
||||
.into( &abortAfterFirst );
|
||||
|
||||
cli.bind( &abortAfterX )
|
||||
cli["-x"]["--abortx"]
|
||||
.placeholder( "number of failures" )
|
||||
.describe( "abort after x failures" )
|
||||
.shortOpt( "x")
|
||||
.longOpt( "abortx" )
|
||||
.hint( "number of failures" );
|
||||
.into( &abortAfterX );
|
||||
|
||||
cli.bind( &addWarning )
|
||||
cli["-w"]["--warn"]
|
||||
.placeholder( "warning name" )
|
||||
.describe( "enable warnings" )
|
||||
.shortOpt( "w")
|
||||
.longOpt( "warn" )
|
||||
.hint( "warning name" );
|
||||
.into( &addWarning );
|
||||
|
||||
// cli.bind( &setVerbosity )
|
||||
// - needs updating if reinstated
|
||||
// cli.into( &setVerbosity )
|
||||
// .describe( "level of verbosity (0=no output)" )
|
||||
// .shortOpt( "v")
|
||||
// .longOpt( "verbosity" )
|
||||
// .hint( "level" );
|
||||
// .placeholder( "level" );
|
||||
|
||||
cli.bind( &addTestOrTags )
|
||||
cli[_]
|
||||
.placeholder( "test name, pattern or tags" )
|
||||
.describe( "which test or tests to use" )
|
||||
.hint( "test name, pattern or tags" );
|
||||
.into( &addTestOrTags );
|
||||
|
||||
cli.bind( &setShowDurations )
|
||||
cli["-d"]["--durations"]
|
||||
.placeholder( "yes/no" )
|
||||
.describe( "show test durations" )
|
||||
.shortOpt( "d")
|
||||
.longOpt( "durations" )
|
||||
.hint( "yes/no" );
|
||||
.into( &setShowDurations );
|
||||
|
||||
cli.bind( &loadTestNamesFromFile )
|
||||
cli["-f"]["--input-file"]
|
||||
.placeholder( "filename" )
|
||||
.describe( "load test names to run from a file" )
|
||||
.shortOpt( "f")
|
||||
.longOpt( "input-file" )
|
||||
.hint( "filename" );
|
||||
.into( &loadTestNamesFromFile );
|
||||
|
||||
// Less common commands which don't have a short form
|
||||
cli.bind( &ConfigData::listTestNamesOnly )
|
||||
cli["--list-test-names-only"]
|
||||
.describe( "list all/matching test cases names only" )
|
||||
.longOpt( "list-test-names-only" );
|
||||
.into( &ConfigData::listTestNamesOnly );
|
||||
|
||||
cli.bind( &ConfigData::listReporters )
|
||||
cli["--list-reporters"]
|
||||
.describe( "list all reporters" )
|
||||
.longOpt( "list-reporters" );
|
||||
.into( &ConfigData::listReporters );
|
||||
|
||||
return cli;
|
||||
}
|
||||
|
Reference in New Issue
Block a user