mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
embedded v1.0-develop.2 of Clara, which addresses / prefixed options, which should impact non-windows platforms
See #1054
This commit is contained in:
23
include/external/clara.hpp
vendored
23
include/external/clara.hpp
vendored
@@ -1,4 +1,4 @@
|
||||
// v1.0
|
||||
// v1.0-develop.2
|
||||
// See https://github.com/philsquared/Clara
|
||||
|
||||
#ifndef CATCH_CLARA_HPP_INCLUDED
|
||||
@@ -409,6 +409,14 @@ namespace detail {
|
||||
std::string token;
|
||||
};
|
||||
|
||||
inline auto isOptPrefix( char c ) -> bool {
|
||||
return c == '-'
|
||||
#ifdef CATCH_PLATFORM_WINDOWS
|
||||
|| c == '/'
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
// Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled
|
||||
class TokenStream {
|
||||
using Iterator = std::vector<std::string>::const_iterator;
|
||||
@@ -425,7 +433,7 @@ namespace detail {
|
||||
|
||||
if( it != itEnd ) {
|
||||
auto const &next = *it;
|
||||
if( next[0] == '-' || next[0] == '/' ) {
|
||||
if( isOptPrefix( next[0] ) ) {
|
||||
auto delimiterPos = next.find_first_of( " :=" );
|
||||
if( delimiterPos != std::string::npos ) {
|
||||
m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } );
|
||||
@@ -915,9 +923,11 @@ namespace detail {
|
||||
};
|
||||
|
||||
inline auto normaliseOpt( std::string const &optName ) -> std::string {
|
||||
#ifdef CATCH_PLATFORM_WINDOWS
|
||||
if( optName[0] == '/' )
|
||||
return "-" + optName.substr( 1 );
|
||||
else
|
||||
#endif
|
||||
return optName;
|
||||
}
|
||||
|
||||
@@ -958,11 +968,7 @@ namespace detail {
|
||||
}
|
||||
|
||||
auto isMatch( std::string const &optToken ) const -> bool {
|
||||
#ifdef CATCH_PLATFORM_WINDOWS
|
||||
auto normalisedToken = normaliseOpt( optToken );
|
||||
#else
|
||||
auto const &normalisedToken = optToken;
|
||||
#endif
|
||||
for( auto const &name : m_optNames ) {
|
||||
if( normaliseOpt( name ) == normalisedToken )
|
||||
return true;
|
||||
@@ -1012,8 +1018,13 @@ namespace detail {
|
||||
for( auto const &name : m_optNames ) {
|
||||
if( name.empty() )
|
||||
return Result::logicError( "Option name cannot be empty" );
|
||||
#ifdef CATCH_PLATFORM_WINDOWS
|
||||
if( name[0] != '-' && name[0] != '/' )
|
||||
return Result::logicError( "Option name must begin with '-' or '/'" );
|
||||
#else
|
||||
if( name[0] != '-' )
|
||||
return Result::logicError( "Option name must begin with '-'" );
|
||||
#endif
|
||||
}
|
||||
return ParserRefImpl::validate();
|
||||
}
|
||||
|
Reference in New Issue
Block a user