Moved use of reporter into runner (our of Main, directly)

This commit is contained in:
Phil Nash 2012-07-16 08:58:28 +01:00
parent 02006d85d7
commit 8fbd8e0f9e
4 changed files with 29 additions and 26 deletions

View File

@ -47,13 +47,11 @@ namespace Catch {
// 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
if( !config.testsSpecified() ) {
config.getReporter()->StartGroup( "" );
runner.runAll();
config.getReporter()->EndGroup( "", runner.getTotals() );
}
else {
// !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 itEnd = config.getTestSpecs().end();
for(; it != itEnd; ++it ) {
Totals prevTotals = runner.getTotals();
config.getReporter()->StartGroup( *it );
if( runner.runMatching( *it ) == 0 ) {
// Use reporter?
// std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl;
}
config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals );
}
}
result = static_cast<int>( runner.getTotals().assertions.failed );
@ -85,7 +79,7 @@ namespace Catch {
<< "\t-s, --success\n"
<< "\t-b, --break\n"
<< "\t-n, --name <name>\n"
<< "\t-a, --abort [#]\n\n"
<< "\t-a, --abort [#]\n"
<< "\t-nt, --nothrow\n\n"
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
}

View File

@ -55,11 +55,11 @@ namespace Catch {
public:
explicit Runner( Config& config )
explicit Runner( Config& config, const Ptr<IReporter>& reporter )
: m_context( getCurrentMutableContext() ),
m_runningTest( NULL ),
m_config( config ),
m_reporter( config.getReporter() ),
m_reporter( reporter ),
m_prevRunner( &m_context.getRunner() ),
m_prevResultCapture( &m_context.getResultCapture() ),
m_prevConfig( m_context.getConfig() )
@ -79,6 +79,7 @@ namespace Catch {
}
virtual void runAll( bool runHiddenTests = false ) {
m_reporter->StartGroup( "" );
const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
for( std::size_t i=0; i < allTests.size(); ++i ) {
if( runHiddenTests || !allTests[i].isHidden() ) {
@ -89,9 +90,14 @@ namespace Catch {
runTest( allTests[i] );
}
}
m_reporter->EndGroup( "", getTotals() );
}
virtual std::size_t runMatching( const std::string& rawTestSpec ) {
Totals prevTotals = getTotals();
m_reporter->StartGroup( rawTestSpec );
TestSpec testSpec( rawTestSpec );
const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
@ -106,6 +112,7 @@ namespace Catch {
testsRun++;
}
}
m_reporter->EndGroup( rawTestSpec, getTotals() - prevTotals );
return testsRun;
}

View File

@ -96,25 +96,27 @@ TEST_CASE( "Sections/nested3", "nested SECTION tests" )
runner.runMatching( "./Sections/nested/a/b", "mock" );
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] d (leaf)\n"
" / [s] d (leaf)\n"
" / [s] c\n"
" \\ [s] c\n"
" \\ [s] d (leaf)\n"
" / [s] d (leaf)\n"
" / [s] c\n"
" \\ [s] c\n"
" \\ [s] e (leaf)\n"
" / [s] e (leaf)\n"
" / [s] c\n"
" \\ [s] c\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] 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" );
}

View File

@ -27,7 +27,7 @@ namespace Catch{
// Scoped because Runner doesn't report EndTesting until its destructor
{
Runner runner( config );
Runner runner( config, config.getReporter() );
result = runner.runMatching( rawTestSpec );
m_totals = runner.getTotals();
}