mirror of
https://github.com/catchorg/Catch2.git
synced 2025-01-11 04:13:29 +01:00
More things using ConfigData
This commit is contained in:
parent
a695eb9006
commit
a67d833091
@ -26,59 +26,72 @@ namespace Catch {
|
||||
INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
|
||||
INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
|
||||
|
||||
inline int Main( Config& config ) {
|
||||
inline int resolveStream( Config& configWrapper ) {
|
||||
const ConfigData& config = configWrapper.data();
|
||||
|
||||
std::string reporterName = config.data().reporter.empty()
|
||||
? "basic"
|
||||
: config.data().reporter;
|
||||
|
||||
ReporterConfig reporterConfig( config.getName(), config.stream(), config.includeSuccessfulResults() );
|
||||
|
||||
Ptr<IReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig );
|
||||
|
||||
if( !reporter )
|
||||
{
|
||||
std::cerr << "No reporter registered with name: '" << reporterName << "'" << std::endl;
|
||||
return (std::numeric_limits<int>::max)();
|
||||
}
|
||||
|
||||
if( !config.data().stream.empty() ) {
|
||||
if( config.data().stream[0] == '%' )
|
||||
config.useStream( config.data().stream.substr( 1 ) );
|
||||
if( !config.stream.empty() ) {
|
||||
if( config.stream[0] == '%' )
|
||||
configWrapper.useStream( config.stream.substr( 1 ) );
|
||||
else
|
||||
config.setFilename( config.data().stream );
|
||||
configWrapper.setFilename( config.stream );
|
||||
}
|
||||
|
||||
// Handle list request
|
||||
if( config.listWhat() != List::None )
|
||||
return List( config );
|
||||
|
||||
// Open output file, if specified
|
||||
std::ofstream ofs;
|
||||
if( !config.getFilename().empty() ) {
|
||||
ofs.open( config.getFilename().c_str() );
|
||||
if( !config.outputFilename.empty() ) {
|
||||
ofs.open( config.outputFilename.c_str() );
|
||||
if( ofs.fail() ) {
|
||||
std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl;
|
||||
std::cerr << "Unable to open file: '" << config.outputFilename << "'" << std::endl;
|
||||
return (std::numeric_limits<int>::max)();
|
||||
}
|
||||
config.setStreamBuf( ofs.rdbuf() );
|
||||
configWrapper.setStreamBuf( ofs.rdbuf() );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
inline Ptr<IReporter> makeReporter( Config& configWrapper ) {
|
||||
const ConfigData& config = configWrapper.data();
|
||||
|
||||
std::string reporterName = config.reporter.empty()
|
||||
? "basic"
|
||||
: config.reporter;
|
||||
|
||||
ReporterConfig reporterConfig( config.name, configWrapper.stream(), config.includeWhichResults == Include::SuccessfulResults );
|
||||
|
||||
Ptr<IReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig );
|
||||
if( !reporter )
|
||||
std::cerr << "No reporter registered with name: '" << reporterName << "'" << std::endl;
|
||||
return reporter;
|
||||
}
|
||||
|
||||
inline int Main( Config& configWrapper ) {
|
||||
|
||||
int result = resolveStream( configWrapper );
|
||||
if( result != 0 )
|
||||
return result;
|
||||
|
||||
Ptr<IReporter> reporter = makeReporter( configWrapper );
|
||||
if( !reporter )
|
||||
return (std::numeric_limits<int>::max)();
|
||||
|
||||
const ConfigData& config = configWrapper.data();
|
||||
|
||||
// Handle list request
|
||||
if( config.listSpec != List::None )
|
||||
return List( config );
|
||||
|
||||
// Scope here for the Runner so it can use the context before it is cleaned-up
|
||||
{
|
||||
Runner runner( config, reporter );
|
||||
Runner runner( configWrapper, reporter );
|
||||
|
||||
// Run test specs specified on the command line - or default to all
|
||||
if( !config.testsSpecified() ) {
|
||||
if( config.testSpecs.empty() ) {
|
||||
runner.runAll();
|
||||
}
|
||||
else {
|
||||
// !TBD We should get all the testcases upfront, report any missing,
|
||||
// then just run them
|
||||
std::vector<std::string>::const_iterator it = config.getTestSpecs().begin();
|
||||
std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end();
|
||||
std::vector<std::string>::const_iterator it = config.testSpecs.begin();
|
||||
std::vector<std::string>::const_iterator itEnd = config.testSpecs.end();
|
||||
for(; it != itEnd; ++it ) {
|
||||
if( runner.runMatching( *it ) == 0 ) {
|
||||
std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl;
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include <limits>
|
||||
|
||||
namespace Catch {
|
||||
inline int List( Config& config ) {
|
||||
inline int List( const ConfigData& config ) {
|
||||
|
||||
if( config.listWhat() & List::Reports ) {
|
||||
if( config.listSpec & List::Reports ) {
|
||||
std::cout << "Available reports:\n";
|
||||
IReporterRegistry::FactoryMap::const_iterator it = getRegistryHub().getReporterRegistry().getFactories().begin();
|
||||
IReporterRegistry::FactoryMap::const_iterator itEnd = getRegistryHub().getReporterRegistry().getFactories().end();
|
||||
@ -25,7 +25,7 @@ namespace Catch {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
if( config.listWhat() & List::Tests ) {
|
||||
if( config.listSpec & List::Tests ) {
|
||||
std::cout << "Available tests:\n";
|
||||
std::vector<TestCaseInfo>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin();
|
||||
std::vector<TestCaseInfo>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end();
|
||||
@ -36,7 +36,7 @@ namespace Catch {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
if( ( config.listWhat() & List::All ) == 0 ) {
|
||||
if( ( config.listSpec & List::All ) == 0 ) {
|
||||
std::cerr << "Unknown list type" << std::endl;
|
||||
return (std::numeric_limits<int>::max)();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user