mirror of
https://github.com/catchorg/Catch2.git
synced 2025-01-11 04:13:29 +01:00
Factored ConfigData out of data
This commit is contained in:
parent
78372d09d4
commit
4c73aa5a0e
@ -85,6 +85,7 @@ namespace Catch {
|
|||||||
<< "\t-b, --break\n"
|
<< "\t-b, --break\n"
|
||||||
<< "\t-n, --name <name>\n"
|
<< "\t-n, --name <name>\n"
|
||||||
<< "\t-a, --abort [#]\n\n"
|
<< "\t-a, --abort [#]\n\n"
|
||||||
|
<< "\t-nt, --nothrow\n\n"
|
||||||
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
|
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
|
||||||
}
|
}
|
||||||
inline void showHelp( std::string exeName ) {
|
inline void showHelp( std::string exeName ) {
|
||||||
@ -99,21 +100,38 @@ namespace Catch {
|
|||||||
|
|
||||||
inline int Main( int argc, char* const argv[], Config& config ) {
|
inline int Main( int argc, char* const argv[], Config& config ) {
|
||||||
|
|
||||||
parseIntoConfig( CommandParser( argc, argv ), config );
|
try {
|
||||||
|
CommandParser parser( argc, argv );
|
||||||
|
|
||||||
if( !config.getMessage().empty() ) {
|
if( Command cmd = parser.find( "-h", "-?", "--help" ) ) {
|
||||||
std::cerr << config.getMessage() << + "\n\nUsage: ...\n\n";
|
if( cmd.argsCount() != 0 )
|
||||||
|
cmd.raiseError( "Does not accept arguments" );
|
||||||
|
|
||||||
|
showHelp( argv[0] );
|
||||||
|
Catch::Context::cleanUp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
parseIntoConfig( parser, config.data() );
|
||||||
|
|
||||||
|
// !TBD: wire up (do this lazily?)
|
||||||
|
if( !config.data().reporter.empty() )
|
||||||
|
config.setReporter( config.data().reporter );
|
||||||
|
|
||||||
|
if( !config.data().stream.empty() ) {
|
||||||
|
if( config.data().stream[0] == '%' )
|
||||||
|
config.useStream( config.data().stream.substr( 1 ) );
|
||||||
|
else
|
||||||
|
config.setFilename( config.data().stream );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( std::exception& ex ) {
|
||||||
|
std::cerr << ex.what() << + "\n\nUsage: ...\n\n";
|
||||||
showUsage( std::cerr );
|
showUsage( std::cerr );
|
||||||
Catch::Context::cleanUp();
|
Catch::Context::cleanUp();
|
||||||
return (std::numeric_limits<int>::max)();
|
return (std::numeric_limits<int>::max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle help
|
|
||||||
if( config.showHelp() ) {
|
|
||||||
showHelp( argv[0] );
|
|
||||||
Catch::Context::cleanUp();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return Main( config );
|
return Main( config );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,104 +89,89 @@ namespace Catch {
|
|||||||
char const * const * m_argv;
|
char const * const * m_argv;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool parseIntoConfig( const CommandParser& parser, Config& config ) {
|
inline void parseIntoConfig( const CommandParser& parser, ConfigData& config ) {
|
||||||
|
|
||||||
try {
|
if( Command cmd = parser.find( "-l", "--list" ) ) {
|
||||||
if( Command cmd = parser.find( "-l", "--list" ) ) {
|
if( cmd.argsCount() > 2 )
|
||||||
if( cmd.argsCount() > 2 )
|
cmd.raiseError( "Expected upto 2 arguments" );
|
||||||
cmd.raiseError( "Expected upto 2 arguments" );
|
|
||||||
|
|
||||||
List::What listSpec = List::All;
|
List::What listSpec = List::All;
|
||||||
if( cmd.argsCount() >= 1 ) {
|
if( cmd.argsCount() >= 1 ) {
|
||||||
if( cmd[0] == "tests" )
|
if( cmd[0] == "tests" )
|
||||||
listSpec = List::Tests;
|
config.listSpec = List::Tests;
|
||||||
else if( cmd[0] == "reporters" )
|
else if( cmd[0] == "reporters" )
|
||||||
listSpec = List::Reports;
|
config.listSpec = List::Reports;
|
||||||
else
|
|
||||||
cmd.raiseError( "Expected [tests] or [reporters]" );
|
|
||||||
}
|
|
||||||
if( cmd.argsCount() >= 2 ) {
|
|
||||||
if( cmd[1] == "xml" )
|
|
||||||
listSpec = static_cast<List::What>( listSpec | List::AsXml );
|
|
||||||
else if( cmd[1] == "text" )
|
|
||||||
listSpec = static_cast<List::What>( listSpec | List::AsText );
|
|
||||||
else
|
|
||||||
cmd.raiseError( "Expected [xml] or [text]" );
|
|
||||||
}
|
|
||||||
config.setListSpec( static_cast<List::What>( config.getListSpec() | listSpec ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-t", "--test" ) ) {
|
|
||||||
if( cmd.argsCount() == 0 )
|
|
||||||
cmd.raiseError( "Expected at least one argument" );
|
|
||||||
for( std::size_t i = 0; i < cmd.argsCount(); ++i )
|
|
||||||
config.addTestSpec( cmd[i] );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-r", "--reporter" ) ) {
|
|
||||||
if( cmd.argsCount() != 1 )
|
|
||||||
cmd.raiseError( "Expected one argument" );
|
|
||||||
config.setReporter( cmd[0] );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-o", "--out" ) ) {
|
|
||||||
if( cmd.argsCount() == 0 )
|
|
||||||
cmd.raiseError( "Expected filename" );
|
|
||||||
if( cmd[0][0] == '%' )
|
|
||||||
config.useStream( cmd[0].substr( 1 ) );
|
|
||||||
else
|
else
|
||||||
config.setFilename( cmd[0] );
|
cmd.raiseError( "Expected [tests] or [reporters]" );
|
||||||
}
|
}
|
||||||
|
if( cmd.argsCount() >= 2 ) {
|
||||||
if( Command cmd = parser.find( "-s", "--success" ) ) {
|
if( cmd[1] == "xml" )
|
||||||
if( cmd.argsCount() != 0 )
|
config.listSpec = static_cast<List::What>( listSpec | List::AsXml );
|
||||||
cmd.raiseError( "Does not accept arguments" );
|
else if( cmd[1] == "text" )
|
||||||
config.setIncludeWhichResults( Include::SuccessfulResults );
|
config.listSpec = static_cast<List::What>( listSpec | List::AsText );
|
||||||
|
else
|
||||||
|
cmd.raiseError( "Expected [xml] or [text]" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-b", "--break" ) ) {
|
|
||||||
if( cmd.argsCount() != 0 )
|
|
||||||
cmd.raiseError( "Does not accept arguments" );
|
|
||||||
config.setShouldDebugBreak( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-n", "--name" ) ) {
|
|
||||||
if( cmd.argsCount() != 1 )
|
|
||||||
cmd.raiseError( "Expected a name" );
|
|
||||||
config.setName( cmd[0] );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-h", "-?", "--help" ) ) {
|
|
||||||
if( cmd.argsCount() != 0 )
|
|
||||||
cmd.raiseError( "Does not accept arguments" );
|
|
||||||
config.setShowHelp( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-a", "--abort" ) ) {
|
|
||||||
if( cmd.argsCount() > 1 )
|
|
||||||
cmd.raiseError( "Only accepts 0-1 arguments" );
|
|
||||||
int threshold = 1;
|
|
||||||
if( cmd.argsCount() == 1 )
|
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << cmd[0];
|
|
||||||
ss >> threshold;
|
|
||||||
}
|
|
||||||
config.setCutoff( threshold );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( Command cmd = parser.find( "-nt", "--nothrow" ) ) {
|
|
||||||
if( cmd.argsCount() != 0 )
|
|
||||||
cmd.raiseError( "Does not accept arguments" );
|
|
||||||
config.setAllowThrows( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch( std::exception& ex ) {
|
|
||||||
config.setError( ex.what() );
|
if( Command cmd = parser.find( "-t", "--test" ) ) {
|
||||||
return false;
|
if( cmd.argsCount() == 0 )
|
||||||
|
cmd.raiseError( "Expected at least one argument" );
|
||||||
|
for( std::size_t i = 0; i < cmd.argsCount(); ++i )
|
||||||
|
config.testSpecs.push_back( cmd[i] );
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
if( Command cmd = parser.find( "-r", "--reporter" ) ) {
|
||||||
|
if( cmd.argsCount() != 1 )
|
||||||
|
cmd.raiseError( "Expected one argument" );
|
||||||
|
config.reporter = cmd[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Command cmd = parser.find( "-o", "--out" ) ) {
|
||||||
|
if( cmd.argsCount() == 0 )
|
||||||
|
cmd.raiseError( "Expected filename" );
|
||||||
|
if( cmd[0][0] == '%' )
|
||||||
|
config.stream = cmd[0].substr( 1 );
|
||||||
|
else
|
||||||
|
config.outputFilename = cmd[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Command cmd = parser.find( "-s", "--success" ) ) {
|
||||||
|
if( cmd.argsCount() != 0 )
|
||||||
|
cmd.raiseError( "Does not accept arguments" );
|
||||||
|
config.includeWhichResults = Include::SuccessfulResults;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Command cmd = parser.find( "-b", "--break" ) ) {
|
||||||
|
if( cmd.argsCount() != 0 )
|
||||||
|
cmd.raiseError( "Does not accept arguments" );
|
||||||
|
config.shouldDebugBreak = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Command cmd = parser.find( "-n", "--name" ) ) {
|
||||||
|
if( cmd.argsCount() != 1 )
|
||||||
|
cmd.raiseError( "Expected a name" );
|
||||||
|
config.name = cmd[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Command cmd = parser.find( "-a", "--abort" ) ) {
|
||||||
|
if( cmd.argsCount() > 1 )
|
||||||
|
cmd.raiseError( "Only accepts 0-1 arguments" );
|
||||||
|
int threshold = 1;
|
||||||
|
if( cmd.argsCount() == 1 ) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << cmd[0];
|
||||||
|
ss >> threshold;
|
||||||
|
}
|
||||||
|
config.cutoff = threshold;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( Command cmd = parser.find( "-nt", "--nothrow" ) ) {
|
||||||
|
if( cmd.argsCount() != 0 )
|
||||||
|
cmd.raiseError( "Does not accept arguments" );
|
||||||
|
config.allowThrows = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -38,6 +38,28 @@ namespace Catch {
|
|||||||
AsMask = 0xf0
|
AsMask = 0xf0
|
||||||
}; };
|
}; };
|
||||||
|
|
||||||
|
struct ConfigData {
|
||||||
|
ConfigData()
|
||||||
|
: listSpec( List::None ),
|
||||||
|
shouldDebugBreak( false ),
|
||||||
|
includeWhichResults( Include::FailedOnly ),
|
||||||
|
cutoff( -1 ),
|
||||||
|
allowThrows( true )
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::string reporter;
|
||||||
|
std::string outputFilename;
|
||||||
|
List::What listSpec;
|
||||||
|
std::vector<std::string> testSpecs;
|
||||||
|
bool shouldDebugBreak;
|
||||||
|
std::string stream;
|
||||||
|
Include::WhichResults includeWhichResults;
|
||||||
|
std::string name;
|
||||||
|
int cutoff;
|
||||||
|
bool allowThrows;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class Config : public IReporterConfig, public IConfig {
|
class Config : public IReporterConfig, public IConfig {
|
||||||
private:
|
private:
|
||||||
Config( const Config& other );
|
Config( const Config& other );
|
||||||
@ -45,14 +67,14 @@ namespace Catch {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
Config()
|
Config()
|
||||||
: m_listSpec( List::None ),
|
: m_streambuf( NULL ),
|
||||||
m_shouldDebugBreak( false ),
|
m_os( std::cout.rdbuf() )
|
||||||
m_showHelp( false ),
|
{}
|
||||||
|
|
||||||
|
Config( const ConfigData& data )
|
||||||
|
: m_data( data ),
|
||||||
m_streambuf( NULL ),
|
m_streambuf( NULL ),
|
||||||
m_os( std::cout.rdbuf() ),
|
m_os( std::cout.rdbuf() )
|
||||||
m_includeWhichResults( Include::FailedOnly ),
|
|
||||||
m_cutoff( -1 ),
|
|
||||||
m_allowThrows( true )
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
~Config() {
|
~Config() {
|
||||||
@ -62,44 +84,28 @@ namespace Catch {
|
|||||||
|
|
||||||
void setReporter( const std::string& reporterName ) {
|
void setReporter( const std::string& reporterName ) {
|
||||||
if( m_reporter.get() )
|
if( m_reporter.get() )
|
||||||
return setError( "Only one reporter may be specified" );
|
throw std::domain_error( "Only one reporter may be specified" );
|
||||||
setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
|
setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTestSpec( const std::string& testSpec ) {
|
void setFilename( const std::string& filename ) {
|
||||||
m_testSpecs.push_back( testSpec );
|
m_data.outputFilename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool testsSpecified() const {
|
bool testsSpecified() const {
|
||||||
return !m_testSpecs.empty();
|
return !m_data.testSpecs.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string>& getTestSpecs() const {
|
const std::vector<std::string>& getTestSpecs() const {
|
||||||
return m_testSpecs;
|
return m_data.testSpecs;
|
||||||
}
|
}
|
||||||
|
|
||||||
List::What getListSpec( void ) const {
|
List::What getListSpec( void ) const {
|
||||||
return m_listSpec;
|
return m_data.listSpec;
|
||||||
}
|
|
||||||
|
|
||||||
void setListSpec( List::What listSpec ) {
|
|
||||||
m_listSpec = listSpec;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFilename( const std::string& filename ) {
|
|
||||||
m_filename = filename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getFilename() const {
|
const std::string& getFilename() const {
|
||||||
return m_filename;
|
return m_data.outputFilename ;
|
||||||
}
|
|
||||||
|
|
||||||
const std::string& getMessage() const {
|
|
||||||
return m_message;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setError( const std::string& errorMessage ) {
|
|
||||||
m_message = errorMessage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setReporter( IReporter* reporter ) {
|
void setReporter( IReporter* reporter ) {
|
||||||
@ -113,39 +119,19 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List::What listWhat() const {
|
List::What listWhat() const {
|
||||||
return static_cast<List::What>( m_listSpec & List::WhatMask );
|
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
|
||||||
}
|
}
|
||||||
|
|
||||||
List::What listAs() const {
|
List::What listAs() const {
|
||||||
return static_cast<List::What>( m_listSpec & List::AsMask );
|
return static_cast<List::What>( m_data.listSpec & List::AsMask );
|
||||||
}
|
|
||||||
|
|
||||||
void setIncludeWhichResults( Include::WhichResults includeWhichResults ) {
|
|
||||||
m_includeWhichResults = includeWhichResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setShouldDebugBreak( bool shouldDebugBreakFlag ) {
|
|
||||||
m_shouldDebugBreak = shouldDebugBreakFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setName( const std::string& name ) {
|
|
||||||
m_name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getName() const {
|
std::string getName() const {
|
||||||
return m_name;
|
return m_data.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldDebugBreak() const {
|
bool shouldDebugBreak() const {
|
||||||
return m_shouldDebugBreak;
|
return m_data.shouldDebugBreak;
|
||||||
}
|
|
||||||
|
|
||||||
void setShowHelp( bool showHelpFlag ) {
|
|
||||||
m_showHelp = showHelpFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool showHelp() const {
|
|
||||||
return m_showHelp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::ostream& stream() const {
|
virtual std::ostream& stream() const {
|
||||||
@ -164,53 +150,30 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual bool includeSuccessfulResults() const {
|
virtual bool includeSuccessfulResults() const {
|
||||||
return m_includeWhichResults == Include::SuccessfulResults;
|
return m_data.includeWhichResults == Include::SuccessfulResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getCutoff() const {
|
int getCutoff() const {
|
||||||
return m_cutoff;
|
return m_data.cutoff;
|
||||||
}
|
|
||||||
|
|
||||||
void setCutoff( int cutoff ) {
|
|
||||||
m_cutoff = cutoff;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAllowThrows( bool allowThrows ) {
|
|
||||||
m_allowThrows = allowThrows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool allowThrows() const {
|
virtual bool allowThrows() const {
|
||||||
return m_allowThrows;
|
return m_data.allowThrows;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigData& data() {
|
||||||
|
return m_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ConfigData m_data;
|
||||||
|
|
||||||
|
// !TBD Move these out of here
|
||||||
Ptr<IReporter> m_reporter;
|
Ptr<IReporter> m_reporter;
|
||||||
std::string m_filename;
|
|
||||||
std::string m_message;
|
|
||||||
List::What m_listSpec;
|
|
||||||
std::vector<std::string> m_testSpecs;
|
|
||||||
bool m_shouldDebugBreak;
|
|
||||||
bool m_showHelp;
|
|
||||||
std::streambuf* m_streambuf;
|
std::streambuf* m_streambuf;
|
||||||
mutable std::ostream m_os;
|
mutable std::ostream m_os;
|
||||||
Include::WhichResults m_includeWhichResults;
|
|
||||||
std::string m_name;
|
|
||||||
int m_cutoff;
|
|
||||||
bool m_allowThrows;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NewConfig {
|
|
||||||
std::string reporter;
|
|
||||||
std::string outputFilename;
|
|
||||||
List::What listSpec;
|
|
||||||
std::vector<std::string> testSpecs;
|
|
||||||
bool shouldDebugBreak;
|
|
||||||
bool showHelp;
|
|
||||||
Include::WhichResults includeWhichResults;
|
|
||||||
std::string name;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ namespace Catch {
|
|||||||
m_config( config ),
|
m_config( config ),
|
||||||
m_reporter( config.getReporter() ),
|
m_reporter( config.getReporter() ),
|
||||||
m_prevRunner( &m_context.getRunner() ),
|
m_prevRunner( &m_context.getRunner() ),
|
||||||
m_prevResultCapture( &m_context.getResultCapture() )
|
m_prevResultCapture( &m_context.getResultCapture() ),
|
||||||
|
m_prevConfig( m_context.getConfig() )
|
||||||
{
|
{
|
||||||
m_context.setRunner( this );
|
m_context.setRunner( this );
|
||||||
m_context.setConfig( &m_config );
|
m_context.setConfig( &m_config );
|
||||||
@ -74,6 +75,7 @@ namespace Catch {
|
|||||||
m_context.setRunner( m_prevRunner );
|
m_context.setRunner( m_prevRunner );
|
||||||
m_context.setConfig( NULL );
|
m_context.setConfig( NULL );
|
||||||
m_context.setResultCapture( m_prevResultCapture );
|
m_context.setResultCapture( m_prevResultCapture );
|
||||||
|
m_context.setConfig( m_prevConfig );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void runAll( bool runHiddenTests = false ) {
|
virtual void runAll( bool runHiddenTests = false ) {
|
||||||
@ -293,6 +295,7 @@ namespace Catch {
|
|||||||
std::vector<ResultInfo> m_info;
|
std::vector<ResultInfo> m_info;
|
||||||
IRunner* m_prevRunner;
|
IRunner* m_prevRunner;
|
||||||
IResultCapture* m_prevResultCapture;
|
IResultCapture* m_prevResultCapture;
|
||||||
|
const IConfig* m_prevConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
@ -60,200 +60,154 @@ TEST_CASE( "meta/Misc/Sections", "looped tests" ) {
|
|||||||
#include "../../include/reporters/catch_reporter_junit.hpp"
|
#include "../../include/reporters/catch_reporter_junit.hpp"
|
||||||
|
|
||||||
template<size_t size>
|
template<size_t size>
|
||||||
bool parseIntoConfig( const char * (&argv)[size], Catch::Config& config ) {
|
void parseIntoConfig( const char * (&argv)[size], Catch::ConfigData& config ) {
|
||||||
return Catch::parseIntoConfig( Catch::CommandParser( size, argv ), config );
|
Catch::parseIntoConfig( Catch::CommandParser( size, argv ), config );
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "selftest/parser", "" ) {
|
template<size_t size>
|
||||||
|
std::string parseIntoConfigAndReturnError( const char * (&argv)[size], Catch::ConfigData& config ) {
|
||||||
|
try {
|
||||||
|
Catch::parseIntoConfig( Catch::CommandParser( size, argv ), config );
|
||||||
|
}
|
||||||
|
catch( std::exception& ex ) {
|
||||||
|
return ex.what();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "selftest/parser/2", "ConfigData" ) {
|
||||||
|
|
||||||
|
Catch::ConfigData config;
|
||||||
|
|
||||||
SECTION( "default", "" ) {
|
SECTION( "default", "" ) {
|
||||||
const char* argv[] = { "test" };
|
const char* argv[] = { "test" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
CHECK( config.getTestSpecs().empty() );
|
CHECK( config.testSpecs.empty() );
|
||||||
CHECK( config.shouldDebugBreak() == false );
|
CHECK( config.shouldDebugBreak == false );
|
||||||
CHECK( config.showHelp() == false );
|
CHECK( config.cutoff == -1 );
|
||||||
CHECK( config.getCutoff() == -1 );
|
CHECK( config.allowThrows == true );
|
||||||
CHECK( config.allowThrows() == true );
|
CHECK( config.reporter.empty() );
|
||||||
CHECK( dynamic_cast<Catch::BasicReporter*>( config.getReporter().get() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "test lists", "" ) {
|
SECTION( "test lists", "" ) {
|
||||||
SECTION( "-t/1", "Specify one test case using -t" ) {
|
SECTION( "-t/1", "Specify one test case using -t" ) {
|
||||||
const char* argv[] = { "test", "-t", "test1" };
|
const char* argv[] = { "test", "-t", "test1" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.getTestSpecs().size() == 1 );
|
REQUIRE( config.testSpecs.size() == 1 );
|
||||||
REQUIRE( config.getTestSpecs()[0] == "test1" );
|
REQUIRE( config.testSpecs[0] == "test1" );
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "--test/1", "Specify one test case using --test" ) {
|
SECTION( "--test/1", "Specify one test case using --test" ) {
|
||||||
const char* argv[] = { "test", "--test", "test1" };
|
const char* argv[] = { "test", "--test", "test1" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.getTestSpecs().size() == 1 );
|
REQUIRE( config.testSpecs.size() == 1 );
|
||||||
REQUIRE( config.getTestSpecs()[0] == "test1" );
|
REQUIRE( config.testSpecs[0] == "test1" );
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "-t/2", "Specify two test cases using -t" ) {
|
SECTION( "-t/2", "Specify two test cases using -t" ) {
|
||||||
const char* argv[] = { "test", "-t", "test1", "test2" };
|
const char* argv[] = { "test", "-t", "test1", "test2" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.getTestSpecs().size() == 2 );
|
REQUIRE( config.testSpecs.size() == 2 );
|
||||||
REQUIRE( config.getTestSpecs()[0] == "test1" );
|
REQUIRE( config.testSpecs[0] == "test1" );
|
||||||
REQUIRE( config.getTestSpecs()[1] == "test2" );
|
REQUIRE( config.testSpecs[1] == "test2" );
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "-t/0", "When no test names are supplied it is an error" ) {
|
SECTION( "-t/0", "When no test names are supplied it is an error" ) {
|
||||||
const char* argv[] = { "test", "-t" };
|
const char* argv[] = { "test", "-t" };
|
||||||
Catch::Config config;
|
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "at least one" ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) == false );
|
|
||||||
|
|
||||||
REQUIRE_THAT( config.getMessage(), Contains( "at least one" ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "reporter", "" ) {
|
SECTION( "reporter", "" ) {
|
||||||
SECTION( "-r/basic", "" ) {
|
SECTION( "-r/basic", "" ) {
|
||||||
const char* argv[] = { "test", "-reporter", "basic" };
|
const char* argv[] = { "test", "-r", "basic" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( dynamic_cast<Catch::BasicReporter*>( config.getReporter().get() ) );
|
REQUIRE( config.reporter == "basic" );
|
||||||
}
|
}
|
||||||
SECTION( "-r/xml", "" ) {
|
SECTION( "-r/xml", "" ) {
|
||||||
const char* argv[] = { "test", "-r", "xml" };
|
const char* argv[] = { "test", "-r", "xml" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( dynamic_cast<Catch::XmlReporter*>( config.getReporter().get() ) );
|
REQUIRE( config.reporter == "xml" );
|
||||||
}
|
}
|
||||||
SECTION( "-r/junit", "" ) {
|
SECTION( "--reporter/junit", "" ) {
|
||||||
const char* argv[] = { "test", "-r", "junit" };
|
const char* argv[] = { "test", "--reporter", "junit" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( dynamic_cast<Catch::JunitReporter*>( config.getReporter().get() ) );
|
REQUIRE( config.reporter == "junit" );
|
||||||
}
|
}
|
||||||
SECTION( "-r/error", "reporter config only accepts one argument" ) {
|
SECTION( "-r/error", "reporter config only accepts one argument" ) {
|
||||||
const char* argv[] = { "test", "-r", "one", "two" };
|
const char* argv[] = { "test", "-r", "one", "two" };
|
||||||
Catch::Config config;
|
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "one argument" ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) == false );
|
|
||||||
|
|
||||||
REQUIRE_THAT( config.getMessage(), Contains( "one argument" ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "debugger", "" ) {
|
SECTION( "debugger", "" ) {
|
||||||
SECTION( "-b", "" ) {
|
SECTION( "-b", "" ) {
|
||||||
const char* argv[] = { "test", "-b" };
|
const char* argv[] = { "test", "-b" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.shouldDebugBreak() == true );
|
REQUIRE( config.shouldDebugBreak == true );
|
||||||
}
|
}
|
||||||
SECTION( "--break", "" ) {
|
SECTION( "--break", "" ) {
|
||||||
const char* argv[] = { "test", "--break" };
|
const char* argv[] = { "test", "--break" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.shouldDebugBreak() );
|
REQUIRE( config.shouldDebugBreak );
|
||||||
}
|
}
|
||||||
SECTION( "-b", "break option has no arguments" ) {
|
SECTION( "-b", "break option has no arguments" ) {
|
||||||
const char* argv[] = { "test", "-b", "unexpected" };
|
const char* argv[] = { "test", "-b", "unexpected" };
|
||||||
Catch::Config config;
|
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "not accept" ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) == false );
|
|
||||||
|
|
||||||
REQUIRE_THAT( config.getMessage(), Contains( "not accept" ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION( "help", "" ) {
|
|
||||||
SECTION( "-h", "" ) {
|
|
||||||
const char* argv[] = { "test", "-h" };
|
|
||||||
Catch::Config config;
|
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.showHelp() );
|
|
||||||
}
|
|
||||||
SECTION( "-?", "" ) {
|
|
||||||
const char* argv[] = { "test", "-?" };
|
|
||||||
Catch::Config config;
|
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.showHelp() );
|
|
||||||
}
|
|
||||||
SECTION( "--help", "" ) {
|
|
||||||
const char* argv[] = { "test", "--help" };
|
|
||||||
Catch::Config config;
|
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.showHelp() );
|
|
||||||
}
|
|
||||||
SECTION( "-h", "help option has no arguments" ) {
|
|
||||||
const char* argv[] = { "test", "-h", "unexpected" };
|
|
||||||
Catch::Config config;
|
|
||||||
CHECK( parseIntoConfig( argv, config ) == false );
|
|
||||||
|
|
||||||
REQUIRE_THAT( config.getMessage(), Contains( "not accept" ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "abort", "" ) {
|
SECTION( "abort", "" ) {
|
||||||
SECTION( "-a", "" ) {
|
SECTION( "-a", "" ) {
|
||||||
const char* argv[] = { "test", "-a" };
|
const char* argv[] = { "test", "-a" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.getCutoff() == 1 );
|
REQUIRE( config.cutoff == 1 );
|
||||||
}
|
}
|
||||||
SECTION( "-a/2", "" ) {
|
SECTION( "-a/2", "" ) {
|
||||||
const char* argv[] = { "test", "-a", "2" };
|
const char* argv[] = { "test", "-a", "2" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.getCutoff() == 2 );
|
REQUIRE( config.cutoff == 2 );
|
||||||
}
|
}
|
||||||
SECTION( "-a/error", "cutoff only takes one argument" ) {
|
SECTION( "-a/error", "cutoff only takes one argument" ) {
|
||||||
const char* argv[] = { "test", "-a", "1", "2" };
|
const char* argv[] = { "test", "-a", "1", "2" };
|
||||||
Catch::Config config;
|
REQUIRE_THAT( parseIntoConfigAndReturnError( argv, config ), Contains( "accepts" ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) == false );
|
|
||||||
|
|
||||||
REQUIRE_THAT( config.getMessage(), Contains( "accepts" ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION( "nothrow", "" ) {
|
SECTION( "nothrow", "" ) {
|
||||||
SECTION( "-nt", "" ) {
|
SECTION( "-nt", "" ) {
|
||||||
const char* argv[] = { "test", "-nt" };
|
const char* argv[] = { "test", "-nt" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.allowThrows() == false );
|
REQUIRE( config.allowThrows == false );
|
||||||
}
|
}
|
||||||
SECTION( "--nothrow", "" ) {
|
SECTION( "--nothrow", "" ) {
|
||||||
const char* argv[] = { "test", "--nothrow" };
|
const char* argv[] = { "test", "--nothrow" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
REQUIRE( config.allowThrows() == false );
|
REQUIRE( config.allowThrows == false );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
SECTION( "combinations", "" ) {
|
SECTION( "combinations", "" ) {
|
||||||
SECTION( "-a -b", "" ) {
|
SECTION( "-a -b", "" ) {
|
||||||
const char* argv[] = { "test", "-a", "-b", "-nt" };
|
const char* argv[] = { "test", "-a", "-b", "-nt" };
|
||||||
Catch::Config config;
|
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||||
CHECK( parseIntoConfig( argv, config ) );
|
|
||||||
|
|
||||||
CHECK( config.getCutoff() == 1 );
|
CHECK( config.cutoff == 1 );
|
||||||
CHECK( config.shouldDebugBreak() );
|
CHECK( config.shouldDebugBreak );
|
||||||
CHECK( config.allowThrows() == false );
|
CHECK( config.allowThrows == false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user