mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Resolve reporter outside of Config
config now only only holds reporter name
This commit is contained in:
parent
8fbd8e0f9e
commit
5d73c5a008
@ -28,6 +28,18 @@ namespace Catch {
|
|||||||
|
|
||||||
inline int Main( Config& config ) {
|
inline int Main( Config& config ) {
|
||||||
|
|
||||||
|
std::string reporterName = config.data().reporter.empty()
|
||||||
|
? "basic"
|
||||||
|
: config.data().reporter;
|
||||||
|
Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, config );
|
||||||
|
|
||||||
|
if( !config.data().stream.empty() ) {
|
||||||
|
if( config.data().stream[0] == '%' )
|
||||||
|
config.useStream( config.data().stream.substr( 1 ) );
|
||||||
|
else
|
||||||
|
config.setFilename( config.data().stream );
|
||||||
|
}
|
||||||
|
|
||||||
// Handle list request
|
// Handle list request
|
||||||
if( config.listWhat() != List::None )
|
if( config.listWhat() != List::None )
|
||||||
return List( config );
|
return List( config );
|
||||||
@ -47,7 +59,7 @@ namespace Catch {
|
|||||||
|
|
||||||
// Scope here for the Runner so it can use the context before it is cleaned-up
|
// Scope here for the Runner so it can use the context before it is cleaned-up
|
||||||
{
|
{
|
||||||
Runner runner( config, config.getReporter() );
|
Runner runner( config, reporter );
|
||||||
|
|
||||||
// Run test specs specified on the command line - or default to all
|
// Run test specs specified on the command line - or default to all
|
||||||
if( !config.testsSpecified() ) {
|
if( !config.testsSpecified() ) {
|
||||||
@ -107,18 +119,7 @@ namespace Catch {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
parseIntoConfig( parser, config.data() );
|
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 ) {
|
catch( std::exception& ex ) {
|
||||||
std::cerr << ex.what() << + "\n\nUsage: ...\n\n";
|
std::cerr << ex.what() << + "\n\nUsage: ...\n\n";
|
||||||
|
@ -82,12 +82,6 @@ namespace Catch {
|
|||||||
delete m_streambuf;
|
delete m_streambuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setReporter( const std::string& reporterName ) {
|
|
||||||
if( m_reporter.get() )
|
|
||||||
throw std::domain_error( "Only one reporter may be specified" );
|
|
||||||
setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFilename( const std::string& filename ) {
|
void setFilename( const std::string& filename ) {
|
||||||
m_data.outputFilename = filename;
|
m_data.outputFilename = filename;
|
||||||
}
|
}
|
||||||
@ -108,16 +102,6 @@ namespace Catch {
|
|||||||
return m_data.outputFilename ;
|
return m_data.outputFilename ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setReporter( IReporter* reporter ) {
|
|
||||||
m_reporter = reporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ptr<IReporter> getReporter() {
|
|
||||||
if( !m_reporter.get() )
|
|
||||||
const_cast<Config*>( this )->setReporter( getCurrentContext().getReporterRegistry().create( "basic", *this ) );
|
|
||||||
return m_reporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
List::What listWhat() const {
|
List::What listWhat() const {
|
||||||
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
|
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
|
||||||
}
|
}
|
||||||
@ -169,7 +153,6 @@ namespace Catch {
|
|||||||
ConfigData m_data;
|
ConfigData m_data;
|
||||||
|
|
||||||
// !TBD Move these out of here
|
// !TBD Move these out of here
|
||||||
Ptr<IReporter> m_reporter;
|
|
||||||
std::streambuf* m_streambuf;
|
std::streambuf* m_streambuf;
|
||||||
mutable std::ostream m_os;
|
mutable std::ostream m_os;
|
||||||
};
|
};
|
||||||
|
@ -42,10 +42,6 @@ namespace Catch {
|
|||||||
return (std::numeric_limits<int>::max)();
|
return (std::numeric_limits<int>::max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( config.getReporter().get() )
|
|
||||||
std::cerr << "Reporters ignored when listing" << std::endl;
|
|
||||||
if( !config.testsSpecified() )
|
|
||||||
std::cerr << "Test specs ignored when listing" << std::endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
struct TestData
|
struct TestData {
|
||||||
{
|
|
||||||
TestData()
|
TestData()
|
||||||
: int_seven( 7 ),
|
: int_seven( 7 ),
|
||||||
str_hello( "hello" ),
|
str_hello( "hello" ),
|
||||||
@ -30,6 +29,25 @@ struct TestData
|
|||||||
double double_pi;
|
double double_pi;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct TestDef {
|
||||||
|
TestDef& operator + ( const std::string& ) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
TestDef& operator[]( const std::string& ) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//TEST( "./succeeding/conditions/equality" + Description("nyaya") )
|
||||||
|
//{
|
||||||
|
// TEST_CASE( [Name("inner")] )
|
||||||
|
// {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
// The "failing" tests all use the CHECK macro, which continues if the specific test fails.
|
// The "failing" tests all use the CHECK macro, which continues if the specific test fails.
|
||||||
// This allows us to see all results, even if an earlier check fails
|
// This allows us to see all results, even if an earlier check fails
|
||||||
|
|
||||||
@ -37,6 +55,10 @@ struct TestData
|
|||||||
TEST_CASE( "./succeeding/conditions/equality",
|
TEST_CASE( "./succeeding/conditions/equality",
|
||||||
"Equality checks that should succeed" )
|
"Equality checks that should succeed" )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
TestDef td;
|
||||||
|
td + "hello" + "hello";
|
||||||
|
|
||||||
TestData data;
|
TestData data;
|
||||||
|
|
||||||
REQUIRE( data.int_seven == 7 );
|
REQUIRE( data.int_seven == 7 );
|
||||||
@ -225,6 +247,21 @@ TEST_CASE( "./succeeding/conditions/negative ints",
|
|||||||
CHECK( minInt > 2u );
|
CHECK( minInt > 2u );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Ex
|
||||||
|
{
|
||||||
|
Ex( T ){}
|
||||||
|
|
||||||
|
bool operator == ( const T& ) const { return true; }
|
||||||
|
T operator * ( const T& ) const { return T(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_CASE( "./succeeding/conditions/computed ints",
|
||||||
|
"Comparisons between ints where one side is computed" )
|
||||||
|
{
|
||||||
|
CHECK( 54 == 6*9 );
|
||||||
|
}
|
||||||
|
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
|||||||
SECTION( "selftest/test counts/succeeding tests",
|
SECTION( "selftest/test counts/succeeding tests",
|
||||||
"Number of 'succeeding' tests is fixed" ) {
|
"Number of 'succeeding' tests is fixed" ) {
|
||||||
runner.runMatching( "./succeeding/*" );
|
runner.runMatching( "./succeeding/*" );
|
||||||
CHECK( runner.getTotals().assertions.passed == 284 );
|
CHECK( runner.getTotals().assertions.passed == 285 );
|
||||||
CHECK( runner.getTotals().assertions.failed == 0 );
|
CHECK( runner.getTotals().assertions.failed == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +20,11 @@ namespace Catch{
|
|||||||
Config config;
|
Config config;
|
||||||
config.setStreamBuf( oss.rdbuf() );
|
config.setStreamBuf( oss.rdbuf() );
|
||||||
|
|
||||||
//if( reporter == "mock" ) // !TBD
|
|
||||||
config.setReporter( m_reporter.get() );
|
|
||||||
|
|
||||||
std::size_t result;
|
std::size_t result;
|
||||||
|
|
||||||
// Scoped because Runner doesn't report EndTesting until its destructor
|
// Scoped because Runner doesn't report EndTesting until its destructor
|
||||||
{
|
{
|
||||||
Runner runner( config, config.getReporter() );
|
Runner runner( config, m_reporter.get() );
|
||||||
result = runner.runMatching( rawTestSpec );
|
result = runner.runMatching( rawTestSpec );
|
||||||
m_totals = runner.getTotals();
|
m_totals = runner.getTotals();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Generated: 2012-07-05 18:47:13.729198
|
* Generated: 2012-07-17 08:02:44.293339
|
||||||
* ----------------------------------------------------------
|
* ----------------------------------------------------------
|
||||||
* This file has been merged from multiple headers. Please don't edit it directly
|
* This file has been merged from multiple headers. Please don't edit it directly
|
||||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
@ -2500,12 +2500,6 @@ namespace Catch {
|
|||||||
delete m_streambuf;
|
delete m_streambuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setReporter( const std::string& reporterName ) {
|
|
||||||
if( m_reporter.get() )
|
|
||||||
throw std::domain_error( "Only one reporter may be specified" );
|
|
||||||
setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFilename( const std::string& filename ) {
|
void setFilename( const std::string& filename ) {
|
||||||
m_data.outputFilename = filename;
|
m_data.outputFilename = filename;
|
||||||
}
|
}
|
||||||
@ -2526,16 +2520,6 @@ namespace Catch {
|
|||||||
return m_data.outputFilename ;
|
return m_data.outputFilename ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setReporter( IReporter* reporter ) {
|
|
||||||
m_reporter = reporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ptr<IReporter> getReporter() {
|
|
||||||
if( !m_reporter.get() )
|
|
||||||
const_cast<Config*>( this )->setReporter( getCurrentContext().getReporterRegistry().create( "basic", *this ) );
|
|
||||||
return m_reporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
List::What listWhat() const {
|
List::What listWhat() const {
|
||||||
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
|
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
|
||||||
}
|
}
|
||||||
@ -2587,7 +2571,6 @@ namespace Catch {
|
|||||||
ConfigData m_data;
|
ConfigData m_data;
|
||||||
|
|
||||||
// !TBD Move these out of here
|
// !TBD Move these out of here
|
||||||
Ptr<IReporter> m_reporter;
|
|
||||||
std::streambuf* m_streambuf;
|
std::streambuf* m_streambuf;
|
||||||
mutable std::ostream m_os;
|
mutable std::ostream m_os;
|
||||||
};
|
};
|
||||||
@ -2814,11 +2797,11 @@ namespace Catch {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit Runner( Config& config )
|
explicit Runner( Config& config, const Ptr<IReporter>& reporter )
|
||||||
: m_context( getCurrentMutableContext() ),
|
: m_context( getCurrentMutableContext() ),
|
||||||
m_runningTest( NULL ),
|
m_runningTest( NULL ),
|
||||||
m_config( config ),
|
m_config( config ),
|
||||||
m_reporter( config.getReporter() ),
|
m_reporter( reporter ),
|
||||||
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_prevConfig( m_context.getConfig() )
|
||||||
@ -2838,6 +2821,7 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void runAll( bool runHiddenTests = false ) {
|
virtual void runAll( bool runHiddenTests = false ) {
|
||||||
|
m_reporter->StartGroup( "" );
|
||||||
const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
|
const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
|
||||||
for( std::size_t i=0; i < allTests.size(); ++i ) {
|
for( std::size_t i=0; i < allTests.size(); ++i ) {
|
||||||
if( runHiddenTests || !allTests[i].isHidden() ) {
|
if( runHiddenTests || !allTests[i].isHidden() ) {
|
||||||
@ -2848,9 +2832,14 @@ namespace Catch {
|
|||||||
runTest( allTests[i] );
|
runTest( allTests[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_reporter->EndGroup( "", getTotals() );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::size_t runMatching( const std::string& rawTestSpec ) {
|
virtual std::size_t runMatching( const std::string& rawTestSpec ) {
|
||||||
|
|
||||||
|
Totals prevTotals = getTotals();
|
||||||
|
m_reporter->StartGroup( rawTestSpec );
|
||||||
|
|
||||||
TestSpec testSpec( rawTestSpec );
|
TestSpec testSpec( rawTestSpec );
|
||||||
|
|
||||||
const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
|
const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
|
||||||
@ -2865,6 +2854,7 @@ namespace Catch {
|
|||||||
testsRun++;
|
testsRun++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_reporter->EndGroup( rawTestSpec, getTotals() - prevTotals );
|
||||||
return testsRun;
|
return testsRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3701,10 +3691,6 @@ namespace Catch {
|
|||||||
return (std::numeric_limits<int>::max)();
|
return (std::numeric_limits<int>::max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( config.getReporter().get() )
|
|
||||||
std::cerr << "Reporters ignored when listing" << std::endl;
|
|
||||||
if( !config.testsSpecified() )
|
|
||||||
std::cerr << "Test specs ignored when listing" << std::endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4612,6 +4598,18 @@ namespace Catch {
|
|||||||
|
|
||||||
inline int Main( Config& config ) {
|
inline int Main( Config& config ) {
|
||||||
|
|
||||||
|
std::string reporterName = config.data().reporter.empty()
|
||||||
|
? "basic"
|
||||||
|
: config.data().reporter;
|
||||||
|
Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, config );
|
||||||
|
|
||||||
|
if( !config.data().stream.empty() ) {
|
||||||
|
if( config.data().stream[0] == '%' )
|
||||||
|
config.useStream( config.data().stream.substr( 1 ) );
|
||||||
|
else
|
||||||
|
config.setFilename( config.data().stream );
|
||||||
|
}
|
||||||
|
|
||||||
// Handle list request
|
// Handle list request
|
||||||
if( config.listWhat() != List::None )
|
if( config.listWhat() != List::None )
|
||||||
return List( config );
|
return List( config );
|
||||||
@ -4631,13 +4629,11 @@ namespace Catch {
|
|||||||
|
|
||||||
// Scope here for the Runner so it can use the context before it is cleaned-up
|
// Scope here for the Runner so it can use the context before it is cleaned-up
|
||||||
{
|
{
|
||||||
Runner runner( config );
|
Runner runner( config, reporter );
|
||||||
|
|
||||||
// Run test specs specified on the command line - or default to all
|
// Run test specs specified on the command line - or default to all
|
||||||
if( !config.testsSpecified() ) {
|
if( !config.testsSpecified() ) {
|
||||||
config.getReporter()->StartGroup( "" );
|
|
||||||
runner.runAll();
|
runner.runAll();
|
||||||
config.getReporter()->EndGroup( "", runner.getTotals() );
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// !TBD We should get all the testcases upfront, report any missing,
|
// !TBD We should get all the testcases upfront, report any missing,
|
||||||
@ -4645,13 +4641,9 @@ namespace Catch {
|
|||||||
std::vector<std::string>::const_iterator it = config.getTestSpecs().begin();
|
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 itEnd = config.getTestSpecs().end();
|
||||||
for(; it != itEnd; ++it ) {
|
for(; it != itEnd; ++it ) {
|
||||||
Totals prevTotals = runner.getTotals();
|
|
||||||
config.getReporter()->StartGroup( *it );
|
|
||||||
if( runner.runMatching( *it ) == 0 ) {
|
if( runner.runMatching( *it ) == 0 ) {
|
||||||
// Use reporter?
|
std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl;
|
||||||
// std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
|
|
||||||
}
|
}
|
||||||
config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = static_cast<int>( runner.getTotals().assertions.failed );
|
result = static_cast<int>( runner.getTotals().assertions.failed );
|
||||||
@ -4669,7 +4661,7 @@ namespace Catch {
|
|||||||
<< "\t-s, --success\n"
|
<< "\t-s, --success\n"
|
||||||
<< "\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"
|
||||||
<< "\t-nt, --nothrow\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;
|
||||||
}
|
}
|
||||||
@ -4698,17 +4690,6 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseIntoConfig( parser, config.data() );
|
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 ) {
|
catch( std::exception& ex ) {
|
||||||
std::cerr << ex.what() << + "\n\nUsage: ...\n\n";
|
std::cerr << ex.what() << + "\n\nUsage: ...\n\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user