mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Moved use of reporter into runner (our of Main, directly)
This commit is contained in:
parent
02006d85d7
commit
8fbd8e0f9e
@ -47,13 +47,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, config.getReporter() );
|
||||||
|
|
||||||
// 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,
|
||||||
@ -61,13 +59,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 );
|
||||||
@ -85,7 +79,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;
|
||||||
}
|
}
|
||||||
|
@ -55,11 +55,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() )
|
||||||
@ -79,6 +79,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() ) {
|
||||||
@ -89,9 +90,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();
|
||||||
@ -106,6 +112,7 @@ namespace Catch {
|
|||||||
testsRun++;
|
testsRun++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_reporter->EndGroup( rawTestSpec, getTotals() - prevTotals );
|
||||||
return testsRun;
|
return testsRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,25 +96,27 @@ TEST_CASE( "Sections/nested3", "nested SECTION tests" )
|
|||||||
|
|
||||||
runner.runMatching( "./Sections/nested/a/b", "mock" );
|
runner.runMatching( "./Sections/nested/a/b", "mock" );
|
||||||
CHECK( runner.getLog() ==
|
CHECK( runner.getLog() ==
|
||||||
"\\[tc] ./Sections/nested/a/b\n"
|
"\\[g] ./Sections/nested/a/b\n"
|
||||||
|
" \\[tc] ./Sections/nested/a/b\n"
|
||||||
|
|
||||||
" \\ [s] c\n"
|
" \\ [s] c\n"
|
||||||
" \\ [s] d (leaf)\n"
|
" \\ [s] d (leaf)\n"
|
||||||
" / [s] d (leaf)\n"
|
" / [s] d (leaf)\n"
|
||||||
" / [s] c\n"
|
" / [s] c\n"
|
||||||
|
|
||||||
" \\ [s] c\n"
|
" \\ [s] c\n"
|
||||||
" \\ [s] e (leaf)\n"
|
" \\ [s] e (leaf)\n"
|
||||||
" / [s] e (leaf)\n"
|
" / [s] e (leaf)\n"
|
||||||
" / [s] c\n"
|
" / [s] c\n"
|
||||||
|
|
||||||
" \\ [s] c\n"
|
" \\ [s] c\n"
|
||||||
" / [s] c\n"
|
" / [s] c\n"
|
||||||
|
|
||||||
" \\ [s] f (leaf)\n"
|
" \\ [s] f (leaf)\n"
|
||||||
" / [s] f (leaf)\n"
|
" / [s] f (leaf)\n"
|
||||||
|
|
||||||
"/[tc] ./Sections/nested/a/b\n" );
|
" /[tc] ./Sections/nested/a/b\n"
|
||||||
|
"/[g] ./Sections/nested/a/b\n" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ namespace Catch{
|
|||||||
|
|
||||||
// Scoped because Runner doesn't report EndTesting until its destructor
|
// Scoped because Runner doesn't report EndTesting until its destructor
|
||||||
{
|
{
|
||||||
Runner runner( config );
|
Runner runner( config, config.getReporter() );
|
||||||
result = runner.runMatching( rawTestSpec );
|
result = runner.runMatching( rawTestSpec );
|
||||||
m_totals = runner.getTotals();
|
m_totals = runner.getTotals();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user