Use char const * const * for Session::run

Needed to embed newer version of Clara

Closes #1178
Closes #1031
This commit is contained in:
Martin Hořeňovský 2018-03-04 14:25:23 +01:00
parent d2ddb997a7
commit 2e285b9579
4 changed files with 62 additions and 32 deletions

View File

@ -5,7 +5,7 @@
// //
// See https://github.com/philsquared/Clara for more details // See https://github.com/philsquared/Clara for more details
// Clara v1.1.2 // Clara v1.1.3
#ifndef CATCH_CLARA_HPP_INCLUDED #ifndef CATCH_CLARA_HPP_INCLUDED
#define CATCH_CLARA_HPP_INCLUDED #define CATCH_CLARA_HPP_INCLUDED
@ -18,6 +18,15 @@
#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH
#endif #endif
#ifndef CLARA_CONFIG_OPTIONAL_TYPE
#ifdef __has_include
#if __has_include(<optional>) && __cplusplus >= 201703L
#define CLARA_CONFIG_OPTIONAL_TYPE std::optional
#endif
#endif
#endif
// ----------- #included from clara_textflow.hpp ----------- // ----------- #included from clara_textflow.hpp -----------
// TextFlowCpp // TextFlowCpp
@ -389,11 +398,9 @@ namespace detail {
std::vector<std::string> m_args; std::vector<std::string> m_args;
public: public:
Args( int argc, char *argv[] ) { Args( int argc, char const* const* argv )
m_exeName = argv[0]; : m_exeName(argv[0]),
for( int i = 1; i < argc; ++i ) m_args(argv + 1, argv + argc) {}
m_args.push_back( argv[i] );
}
Args( std::initializer_list<std::string> args ) Args( std::initializer_list<std::string> args )
: m_exeName( *args.begin() ), : m_exeName( *args.begin() ),
@ -580,15 +587,13 @@ namespace detail {
protected: protected:
void enforceOk() const override { void enforceOk() const override {
// !TBD: If no exceptions, std::terminate here or something
switch( m_type ) { // Errors shouldn't reach this point, but if they do
case ResultBase::LogicError: // the actual error message will be in m_errorMessage
throw std::logic_error( m_errorMessage ); assert( m_type != ResultBase::LogicError );
case ResultBase::RuntimeError: assert( m_type != ResultBase::RuntimeError );
throw std::runtime_error( m_errorMessage ); if( m_type != ResultBase::Ok )
case ResultBase::Ok: std::abort();
break;
}
} }
std::string m_errorMessage; // Only populated if resultType is an error std::string m_errorMessage; // Only populated if resultType is an error
@ -658,6 +663,16 @@ namespace detail {
return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" );
return ParserResult::ok( ParseResultType::Matched ); return ParserResult::ok( ParseResultType::Matched );
} }
#ifdef CLARA_CONFIG_OPTIONAL_TYPE
template<typename T>
inline auto convertInto( std::string const &source, std::optional<T>& target ) -> ParserResult {
T temp;
auto result = convertInto( source, temp );
if( result )
target = temp;
return result;
}
#endif // CLARA_CONFIG_OPTIONAL_TYPE
struct NonCopyable { struct NonCopyable {
NonCopyable() = default; NonCopyable() = default;

View File

@ -165,7 +165,7 @@ namespace Catch {
<< std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
} }
int Session::applyCommandLine( int argc, char* argv[] ) { int Session::applyCommandLine( int argc, char const * const * argv ) {
if( m_startupExceptions ) if( m_startupExceptions )
return 1; return 1;

View File

@ -25,7 +25,7 @@ namespace Catch {
void showHelp() const; void showHelp() const;
void libIdentify(); void libIdentify();
int applyCommandLine( int argc, char* argv[] ); int applyCommandLine( int argc, char const * const * argv );
void useConfigData( ConfigData const& configData ); void useConfigData( ConfigData const& configData );

45
third_party/clara.hpp vendored
View File

@ -5,7 +5,7 @@
// //
// See https://github.com/philsquared/Clara for more details // See https://github.com/philsquared/Clara for more details
// Clara v1.1.2 // Clara v1.1.3
#ifndef CLARA_HPP_INCLUDED #ifndef CLARA_HPP_INCLUDED
#define CLARA_HPP_INCLUDED #define CLARA_HPP_INCLUDED
@ -18,6 +18,15 @@
#define CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH #define CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
#endif #endif
#ifndef CLARA_CONFIG_OPTIONAL_TYPE
#ifdef __has_include
#if __has_include(<optional>) && __cplusplus >= 201703L
#define CLARA_CONFIG_OPTIONAL_TYPE std::optional
#endif
#endif
#endif
// ----------- #included from clara_textflow.hpp ----------- // ----------- #included from clara_textflow.hpp -----------
// TextFlowCpp // TextFlowCpp
@ -389,11 +398,9 @@ namespace detail {
std::vector<std::string> m_args; std::vector<std::string> m_args;
public: public:
Args( int argc, char *argv[] ) { Args( int argc, char const* const* argv )
m_exeName = argv[0]; : m_exeName(argv[0]),
for( int i = 1; i < argc; ++i ) m_args(argv + 1, argv + argc) {}
m_args.push_back( argv[i] );
}
Args( std::initializer_list<std::string> args ) Args( std::initializer_list<std::string> args )
: m_exeName( *args.begin() ), : m_exeName( *args.begin() ),
@ -580,15 +587,13 @@ namespace detail {
protected: protected:
void enforceOk() const override { void enforceOk() const override {
// !TBD: If no exceptions, std::terminate here or something
switch( m_type ) { // Errors shouldn't reach this point, but if they do
case ResultBase::LogicError: // the actual error message will be in m_errorMessage
throw std::logic_error( m_errorMessage ); assert( m_type != ResultBase::LogicError );
case ResultBase::RuntimeError: assert( m_type != ResultBase::RuntimeError );
throw std::runtime_error( m_errorMessage ); if( m_type != ResultBase::Ok )
case ResultBase::Ok: std::abort();
break;
}
} }
std::string m_errorMessage; // Only populated if resultType is an error std::string m_errorMessage; // Only populated if resultType is an error
@ -658,6 +663,16 @@ namespace detail {
return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" );
return ParserResult::ok( ParseResultType::Matched ); return ParserResult::ok( ParseResultType::Matched );
} }
#ifdef CLARA_CONFIG_OPTIONAL_TYPE
template<typename T>
inline auto convertInto( std::string const &source, std::optional<T>& target ) -> ParserResult {
T temp;
auto result = convertInto( source, temp );
if( result )
target = temp;
return result;
}
#endif // CLARA_CONFIG_OPTIONAL_TYPE
struct NonCopyable { struct NonCopyable {
NonCopyable() = default; NonCopyable() = default;