mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
SectionInfo now goes via new streaming reporter interface
This commit is contained in:
parent
95df676a27
commit
ad6701d222
@ -50,7 +50,7 @@ namespace Catch {
|
||||
for(; it != itEnd && !context.aborting(); ++it ) {
|
||||
reporter.testGroupStarting( it->getName() );
|
||||
totals += runTestsForGroup( context, *it );
|
||||
reporter.testGroupEnding( TestGroupStats( it->getName(), totals, context.aborting() ) );
|
||||
reporter.testGroupEnded( TestGroupStats( it->getName(), totals, context.aborting() ) );
|
||||
}
|
||||
return totals;
|
||||
}
|
||||
|
@ -20,22 +20,21 @@ namespace Catch {
|
||||
class ExpressionResultBuilder;
|
||||
class AssertionResult;
|
||||
struct AssertionInfo;
|
||||
struct SectionInfo;
|
||||
|
||||
struct IResultCapture {
|
||||
|
||||
virtual ~IResultCapture();
|
||||
|
||||
virtual void testEnded( const AssertionResult& result ) = 0;
|
||||
virtual bool sectionStarted( const std::string& name,
|
||||
const std::string& description,
|
||||
const SourceLineInfo& lineInfo,
|
||||
virtual void testEnded( AssertionResult const& result ) = 0;
|
||||
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
||||
Counts& assertions ) = 0;
|
||||
virtual void sectionEnded( const std::string& name, const Counts& assertions ) = 0;
|
||||
virtual void sectionEnded( SectionInfo const& name, Counts const& assertions ) = 0;
|
||||
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0;
|
||||
virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
|
||||
virtual bool shouldDebugBreak() const = 0;
|
||||
|
||||
virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) = 0;
|
||||
virtual ResultAction::Value acceptExpression( ExpressionResultBuilder const& assertionResult, AssertionInfo const& assertionInfo ) = 0;
|
||||
|
||||
virtual std::string getCurrentTestName() const = 0;
|
||||
virtual const AssertionResult* getLastResult() const = 0;
|
||||
|
@ -49,12 +49,12 @@ namespace Catch
|
||||
SourceLineInfo const& _lineInfo )
|
||||
: name( _name ),
|
||||
description( _description ),
|
||||
sourceLineInfo( _lineInfo )
|
||||
lineInfo( _lineInfo )
|
||||
{}
|
||||
|
||||
std::string name;
|
||||
std::string description;
|
||||
SourceLineInfo sourceLineInfo;
|
||||
SourceLineInfo lineInfo;
|
||||
};
|
||||
|
||||
struct AssertionStats {
|
||||
@ -70,8 +70,17 @@ namespace Catch
|
||||
};
|
||||
|
||||
struct SectionStats {
|
||||
SectionStats( SectionInfo const& _sectionInfo,
|
||||
Counts const& _assertions,
|
||||
bool _missingAssertions )
|
||||
: sectionInfo( _sectionInfo ),
|
||||
assertions( _assertions ),
|
||||
missingAssertions( _missingAssertions )
|
||||
{}
|
||||
|
||||
SectionInfo sectionInfo;
|
||||
Totals totals;
|
||||
Counts assertions;
|
||||
bool missingAssertions;
|
||||
};
|
||||
|
||||
struct TestCaseStats {
|
||||
@ -133,14 +142,16 @@ namespace Catch
|
||||
virtual void testRunStarting( std::string const& runName ) = 0;
|
||||
virtual void testGroupStarting( std::string const& groupName ) = 0;
|
||||
|
||||
// !TBD: include section info (perhaps TestCase has an isSection flag and/ or a parent pointer
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
|
||||
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
|
||||
|
||||
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
||||
|
||||
virtual void assertionEnding( AssertionStats const& assertionStats ) = 0;
|
||||
virtual void testCaseEnding( TestCaseStats const& testCaseStats ) = 0;
|
||||
virtual void testGroupEnding( TestGroupStats const& testGroupStats ) = 0;
|
||||
virtual void testRunEnding( TestRunStats const& testRunStats ) = 0;
|
||||
virtual void assertionEnded( AssertionStats const& assertionStats ) = 0;
|
||||
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
|
||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
|
||||
};
|
||||
// !TBD: Derived helper that implements the streaming interface but holds the stats
|
||||
// - declares a new interface where methods are called at the end of each event
|
||||
@ -204,24 +215,32 @@ namespace Catch
|
||||
virtual void testCaseStarting( TestCaseInfo const& testInfo ) {
|
||||
m_legacyReporter->StartTestCase( testInfo );
|
||||
}
|
||||
virtual void sectionStarting( SectionInfo const& sectionInfo ) {
|
||||
m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
|
||||
}
|
||||
virtual void assertionStarting( AssertionInfo const& ) {
|
||||
// Not on legacy interface
|
||||
}
|
||||
|
||||
virtual void assertionEnding( AssertionStats const& assertionStats ) {
|
||||
virtual void assertionEnded( AssertionStats const& assertionStats ) {
|
||||
m_legacyReporter->Result( assertionStats.assertionResult );
|
||||
}
|
||||
virtual void testCaseEnding( TestCaseStats const& testCaseStats ) {
|
||||
virtual void sectionEnded( SectionStats const& sectionStats ) {
|
||||
if( sectionStats.missingAssertions )
|
||||
m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
|
||||
m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
|
||||
}
|
||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) {
|
||||
if( testCaseStats.missingAssertions )
|
||||
m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name );
|
||||
m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr );
|
||||
}
|
||||
virtual void testGroupEnding( TestGroupStats const& testGroupStats ) {
|
||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) {
|
||||
if( testGroupStats.aborting )
|
||||
m_legacyReporter->Aborted();
|
||||
m_legacyReporter->EndGroup( testGroupStats.groupName, testGroupStats.totals );
|
||||
}
|
||||
virtual void testRunEnding( TestRunStats const& testRunStats ) {
|
||||
virtual void testRunEnded( TestRunStats const& testRunStats ) {
|
||||
m_legacyReporter->EndTesting( testRunStats.totals );
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
virtual ~Runner() {
|
||||
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnding( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name
|
||||
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnded( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name
|
||||
m_context.setRunner( m_prevRunner );
|
||||
m_context.setConfig( NULL );
|
||||
m_context.setResultCapture( m_prevResultCapture );
|
||||
@ -94,7 +94,7 @@ namespace Catch {
|
||||
for(; it != itEnd; ++it )
|
||||
totals += runTest( *it );
|
||||
|
||||
reporter.testGroupEnding( TestGroupStats( testSpec, totals, aborting() ) );
|
||||
reporter.testGroupEnded( TestGroupStats( testSpec, totals, aborting() ) );
|
||||
return totals;
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ namespace Catch {
|
||||
m_totals.testCases += deltaTotals.testCases;
|
||||
|
||||
TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() );
|
||||
reporter.testCaseEnding( stats );
|
||||
reporter.testCaseEnded( stats );
|
||||
|
||||
|
||||
delete m_runningTest;
|
||||
@ -163,13 +163,13 @@ namespace Catch {
|
||||
std::vector<ScopedInfo*>::const_iterator it = m_scopedInfos.begin();
|
||||
std::vector<ScopedInfo*>::const_iterator itEnd = m_scopedInfos.end();
|
||||
for(; it != itEnd; ++it )
|
||||
reporter.assertionEnding( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) );
|
||||
reporter.assertionEnded( AssertionStats( (*it)->buildResult( m_lastAssertionInfo ), m_totals ) );
|
||||
}
|
||||
{
|
||||
std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin();
|
||||
std::vector<AssertionResult>::const_iterator itEnd = m_assertionResults.end();
|
||||
for(; it != itEnd; ++it )
|
||||
reporter.assertionEnding( AssertionStats( *it, m_totals ) );
|
||||
reporter.assertionEnded( AssertionStats( *it, m_totals ) );
|
||||
}
|
||||
m_assertionResults.clear();
|
||||
}
|
||||
@ -180,49 +180,48 @@ namespace Catch {
|
||||
m_totals.assertions.info++;
|
||||
}
|
||||
else
|
||||
reporter.assertionEnding( AssertionStats( result, m_totals ) );
|
||||
reporter.assertionEnded( AssertionStats( result, m_totals ) );
|
||||
|
||||
// Reset AssertionInfo
|
||||
m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after this line}" , m_lastAssertionInfo.resultDisposition );
|
||||
}
|
||||
|
||||
virtual bool sectionStarted (
|
||||
const std::string& name,
|
||||
const std::string& description,
|
||||
const SourceLineInfo& lineInfo,
|
||||
SectionInfo const& sectionInfo,
|
||||
Counts& assertions
|
||||
)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << name << "@" << lineInfo;
|
||||
oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
|
||||
|
||||
|
||||
if( !m_runningTest->addSection( oss.str() ) )
|
||||
return false;
|
||||
|
||||
m_lastAssertionInfo.lineInfo = lineInfo;
|
||||
m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
|
||||
|
||||
// !TBD: ------------
|
||||
std::string className = m_runningTest->getTestCase().getTestCaseInfo().className;
|
||||
TestCaseInfo sectionInfo( name, className, description, std::set<std::string>(), false, lineInfo );
|
||||
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionStarting( sectionInfo );
|
||||
|
||||
m_reporter->StartSection( name, description );
|
||||
assertions = m_totals.assertions;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void sectionEnded( const std::string& name, const Counts& prevAssertions ) {
|
||||
virtual void sectionEnded( SectionInfo const& info, Counts const& prevAssertions ) {
|
||||
Counts assertions = m_totals.assertions - prevAssertions;
|
||||
bool missingAssertions = false;
|
||||
if( assertions.total() == 0 &&
|
||||
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
|
||||
!m_runningTest->isBranchSection() ) {
|
||||
m_reporter->NoAssertionsInSection( name );
|
||||
m_totals.assertions.failed++;
|
||||
assertions.failed++;
|
||||
missingAssertions = true;
|
||||
|
||||
}
|
||||
m_runningTest->endSection( name );
|
||||
m_reporter->EndSection( name, assertions );
|
||||
m_runningTest->endSection( info.name );
|
||||
|
||||
SectionStats stats( info, assertions, missingAssertions );
|
||||
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).sectionEnded( stats );
|
||||
}
|
||||
|
||||
virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
|
||||
|
@ -20,13 +20,13 @@ namespace Catch {
|
||||
Section( const std::string& name,
|
||||
const std::string& description,
|
||||
const SourceLineInfo& lineInfo )
|
||||
: m_name( name ),
|
||||
m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) )
|
||||
: m_info( name, description, lineInfo ),
|
||||
m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( m_info, m_assertions ) )
|
||||
{}
|
||||
|
||||
~Section() {
|
||||
if( m_sectionIncluded )
|
||||
getCurrentContext().getResultCapture().sectionEnded( m_name, m_assertions );
|
||||
getCurrentContext().getResultCapture().sectionEnded( m_info, m_assertions );
|
||||
}
|
||||
|
||||
// This indicates whether the section should be executed or not
|
||||
@ -35,6 +35,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
private:
|
||||
SectionInfo m_info;
|
||||
|
||||
std::string m_name;
|
||||
Counts m_assertions;
|
||||
|
Loading…
Reference in New Issue
Block a user