mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
Tightened up ReporterConfig and added it to LegacyReporterAdapter
This commit is contained in:
@@ -23,31 +23,17 @@ namespace Catch
|
||||
{
|
||||
struct ReporterConfig
|
||||
{
|
||||
ReporterConfig( const std::string& _name,
|
||||
std::ostream& _stream,
|
||||
bool _includeSuccessfulResults,
|
||||
const ConfigData& _fullConfig )
|
||||
: name( _name ),
|
||||
stream( _stream ),
|
||||
includeSuccessfulResults( _includeSuccessfulResults ),
|
||||
fullConfig( _fullConfig )
|
||||
{}
|
||||
|
||||
ReporterConfig( const ReporterConfig& other )
|
||||
: name( other.name ),
|
||||
stream( other.stream ),
|
||||
includeSuccessfulResults( other.includeSuccessfulResults ),
|
||||
fullConfig( other.fullConfig )
|
||||
{}
|
||||
|
||||
ReporterConfig( std::ostream& _stream, const ConfigData& _fullConfig )
|
||||
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
||||
|
||||
std::string name;
|
||||
std::ostream& stream;
|
||||
bool includeSuccessfulResults;
|
||||
ConfigData fullConfig;
|
||||
std::ostream& stream() { return *m_stream; }
|
||||
std::string name() const { return m_fullConfig.name; }
|
||||
bool includeSuccessfulResults() const { return m_fullConfig.includeWhichResults == Include::SuccessfulResults; }
|
||||
bool warnAboutMissingAssertions() const { return m_fullConfig.warnings & ConfigData::WarnAbout::NoAssertions; }
|
||||
|
||||
private:
|
||||
void operator=(const ReporterConfig&);
|
||||
std::ostream* m_stream;
|
||||
ConfigData m_fullConfig;
|
||||
};
|
||||
|
||||
struct AssertionStats {
|
||||
@@ -67,11 +53,13 @@ namespace Catch
|
||||
const Totals& _totals,
|
||||
const std::string& _stdOut,
|
||||
const std::string& _stdErr,
|
||||
bool _missingAssertions,
|
||||
bool _aborting )
|
||||
: testInfo( _testInfo ),
|
||||
totals( _totals ),
|
||||
stdOut( _stdOut ),
|
||||
stdErr( _stdErr ),
|
||||
missingAssertions( _missingAssertions ),
|
||||
aborting( _aborting )
|
||||
{}
|
||||
|
||||
@@ -79,6 +67,7 @@ namespace Catch
|
||||
Totals totals;
|
||||
std::string stdOut;
|
||||
std::string stdErr;
|
||||
bool missingAssertions;
|
||||
bool aborting;
|
||||
};
|
||||
|
||||
@@ -166,8 +155,9 @@ namespace Catch
|
||||
class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
|
||||
{
|
||||
public:
|
||||
LegacyReporterAdapter( const Ptr<IReporter>& legacyReporter )
|
||||
: m_legacyReporter( legacyReporter )
|
||||
LegacyReporterAdapter( const Ptr<IReporter>& legacyReporter, const ReporterConfig& config )
|
||||
: m_legacyReporter( legacyReporter ),
|
||||
m_config( config )
|
||||
{}
|
||||
virtual ~LegacyReporterAdapter();
|
||||
|
||||
@@ -189,6 +179,8 @@ namespace Catch
|
||||
m_legacyReporter->Result( assertionStats.assertionResult );
|
||||
}
|
||||
virtual void testCaseEnding( const TestCaseStats& testCaseStats ) {
|
||||
if( testCaseStats.missingAssertions )
|
||||
m_legacyReporter->NoAssertionsInTestCase( testCaseStats.testInfo.name );
|
||||
m_legacyReporter->EndTestCase( testCaseStats.testInfo, testCaseStats.totals, testCaseStats.stdOut, testCaseStats.stdErr );
|
||||
}
|
||||
virtual void testGroupEnding( const TestGroupStats& testGroupStats ) {
|
||||
@@ -202,6 +194,7 @@ namespace Catch
|
||||
|
||||
private:
|
||||
Ptr<IReporter> m_legacyReporter;
|
||||
ReporterConfig m_config;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -68,11 +68,11 @@ namespace Catch {
|
||||
m_context.setRunner( this );
|
||||
m_context.setConfig( &m_config );
|
||||
m_context.setResultCapture( this );
|
||||
LegacyReporterAdapter( m_reporter ).testRunStarting( "" ); // !TBD - name
|
||||
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunStarting( "" ); // !TBD - name
|
||||
}
|
||||
|
||||
virtual ~Runner() {
|
||||
LegacyReporterAdapter( m_reporter ).testRunEnding( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name
|
||||
LegacyReporterAdapter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) ).testRunEnding( TestRunStats( "", m_totals, aborting() ) ); // !TBD - name
|
||||
m_context.setRunner( m_prevRunner );
|
||||
m_context.setConfig( NULL );
|
||||
m_context.setResultCapture( m_prevResultCapture );
|
||||
@@ -85,7 +85,7 @@ namespace Catch {
|
||||
|
||||
Totals totals;
|
||||
|
||||
LegacyReporterAdapter reporter( m_reporter );
|
||||
LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) );
|
||||
|
||||
reporter.testGroupStarting( testSpec );
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace Catch {
|
||||
|
||||
TestCaseInfo testInfo = testCase.getTestCaseInfo();
|
||||
|
||||
LegacyReporterAdapter reporter( m_reporter );
|
||||
LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) );
|
||||
reporter.testCaseStarting( testInfo );
|
||||
|
||||
m_runningTest = new RunningTest( &testCase );
|
||||
@@ -120,15 +120,17 @@ namespace Catch {
|
||||
while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
|
||||
|
||||
Totals deltaTotals = m_totals.delta( prevTotals );
|
||||
bool missingAssertions = false;
|
||||
if( deltaTotals.assertions.total() == 0 &&
|
||||
( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) ) {
|
||||
m_totals.assertions.failed++;
|
||||
deltaTotals = m_totals.delta( prevTotals );
|
||||
m_reporter->NoAssertionsInTestCase( testInfo.name );
|
||||
missingAssertions = true;
|
||||
}
|
||||
|
||||
m_totals.testCases += deltaTotals.testCases;
|
||||
|
||||
TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr , aborting() );
|
||||
TestCaseStats stats( testInfo, deltaTotals, redirectedCout, redirectedCerr, missingAssertions, aborting() );
|
||||
reporter.testCaseEnding( stats );
|
||||
|
||||
|
||||
@@ -150,7 +152,7 @@ namespace Catch {
|
||||
}
|
||||
|
||||
virtual void testEnded( const AssertionResult& result ) {
|
||||
LegacyReporterAdapter reporter( m_reporter );
|
||||
LegacyReporterAdapter reporter( m_reporter, ReporterConfig( m_config.stream(), m_config.data() ) );
|
||||
if( result.getResultType() == ResultWas::Ok ) {
|
||||
m_totals.assertions.passed++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user