mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Pass totals around instead of individual success/ fail counts
This commit is contained in:
parent
9bbaeba3ae
commit
edd8f02bec
@ -57,7 +57,7 @@ namespace Catch
|
||||
{
|
||||
config.getReporter()->StartGroup( "" );
|
||||
runner.runAll();
|
||||
config.getReporter()->EndGroup( "", runner.getTotals().assertions.passed, runner.getTotals().assertions.failed );
|
||||
config.getReporter()->EndGroup( "", runner.getTotals() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -74,8 +74,7 @@ namespace Catch
|
||||
// Use reporter?
|
||||
// std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
|
||||
}
|
||||
Totals diffTotals = runner.getTotals() - prevTotals;
|
||||
config.getReporter()->EndGroup( *it, diffTotals.assertions.passed, diffTotals.assertions.failed );
|
||||
config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#define TWOBLUECUBES_CATCH_IREPORTERREGISTRY_INCLUDED
|
||||
|
||||
#include "catch_common.h"
|
||||
#include "catch_totals.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
@ -54,8 +55,7 @@ namespace Catch
|
||||
() = 0;
|
||||
|
||||
virtual void EndTesting
|
||||
( std::size_t succeeded,
|
||||
std::size_t failed
|
||||
( const Totals& totals
|
||||
) = 0;
|
||||
|
||||
virtual void StartGroup
|
||||
@ -64,8 +64,7 @@ namespace Catch
|
||||
|
||||
virtual void EndGroup
|
||||
( const std::string& groupName,
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Totals& totals
|
||||
) = 0;
|
||||
|
||||
virtual void StartSection
|
||||
@ -75,8 +74,7 @@ namespace Catch
|
||||
|
||||
virtual void EndSection
|
||||
( const std::string& sectionName,
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Counts& assertions
|
||||
) = 0;
|
||||
|
||||
virtual void StartTestCase
|
||||
@ -85,8 +83,7 @@ namespace Catch
|
||||
|
||||
virtual void EndTestCase
|
||||
( const TestCaseInfo& testInfo,
|
||||
std::size_t succeeded,
|
||||
std::size_t failed,
|
||||
const Totals& totals,
|
||||
const std::string& stdOut,
|
||||
const std::string& stdErr
|
||||
) = 0;
|
||||
|
@ -317,7 +317,7 @@ namespace Catch
|
||||
~Runner
|
||||
()
|
||||
{
|
||||
m_reporter->EndTesting( m_totals.assertions.passed, m_totals.assertions.failed );
|
||||
m_reporter->EndTesting( m_totals );
|
||||
Hub::setRunner( m_prevRunner );
|
||||
Hub::setResultCapture( m_prevResultCapture );
|
||||
}
|
||||
@ -387,7 +387,7 @@ namespace Catch
|
||||
delete m_runningTest;
|
||||
m_runningTest = NULL;
|
||||
|
||||
m_reporter->EndTestCase( testInfo, m_totals.assertions.passed - prevTotals.assertions.passed, m_totals.assertions.failed - prevTotals.assertions.failed, redirectedCout, redirectedCerr );
|
||||
m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -496,7 +496,7 @@ namespace Catch
|
||||
)
|
||||
{
|
||||
m_runningTest->endSection( name );
|
||||
m_reporter->EndSection( name, m_totals.assertions.passed - prevAssertions.passed, m_totals.assertions.failed - prevAssertions.failed );
|
||||
m_reporter->EndSection( name, m_totals.assertions - prevAssertions );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -30,6 +30,10 @@ namespace Catch
|
||||
return diff;
|
||||
}
|
||||
|
||||
std::size_t total() const
|
||||
{
|
||||
return passed + failed;
|
||||
}
|
||||
std::size_t passed;
|
||||
std::size_t failed;
|
||||
};
|
||||
|
@ -63,39 +63,47 @@ namespace Catch
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void ReportCounts
|
||||
(
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Counts& assertions
|
||||
)
|
||||
{
|
||||
if( failed + succeeded == 0 )
|
||||
if( assertions.failed + assertions.passed == 0 )
|
||||
m_config.stream() << "No tests ran";
|
||||
else if( failed == 0 )
|
||||
else if( assertions.failed == 0 )
|
||||
{
|
||||
if( succeeded == 1 )
|
||||
if( assertions.passed == 1 )
|
||||
m_config.stream() << "1 test succeeded";
|
||||
else
|
||||
m_config.stream() << "All " << succeeded << " tests succeeded";
|
||||
m_config.stream() << "All " << assertions.passed << " tests succeeded";
|
||||
}
|
||||
else if( succeeded == 0 )
|
||||
else if( assertions.passed == 0 )
|
||||
{
|
||||
if( failed == 1 )
|
||||
if( assertions.failed == 1 )
|
||||
m_config.stream() << "1 test failed";
|
||||
else
|
||||
m_config.stream() << "All " << failed << " tests failed";
|
||||
m_config.stream() << "All " << assertions.failed << " tests failed";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_config.stream() << succeeded << " test";
|
||||
if( succeeded > 1 )
|
||||
m_config.stream() << assertions.passed << " test";
|
||||
if( assertions.passed > 1 )
|
||||
m_config.stream() << "s";
|
||||
|
||||
m_config.stream() << " passed but " << failed << " test";
|
||||
if( failed > 1 )
|
||||
m_config.stream() << " passed but " << assertions.failed << " test";
|
||||
if( assertions.failed > 1 )
|
||||
m_config.stream() << "s";
|
||||
m_config.stream() << " failed";
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
void ReportCounts
|
||||
(
|
||||
const Totals& totals
|
||||
)
|
||||
{
|
||||
ReportCounts( totals.assertions );
|
||||
}
|
||||
|
||||
private: // IReporter
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -116,13 +124,12 @@ namespace Catch
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTesting
|
||||
(
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Totals& totals
|
||||
)
|
||||
{
|
||||
// Output the overall test results even if "Started Testing" was not emitted
|
||||
m_config.stream() << "\n[Testing completed. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
ReportCounts( totals);
|
||||
m_config.stream() << "]\n" << std::endl;
|
||||
}
|
||||
|
||||
@ -139,14 +146,13 @@ namespace Catch
|
||||
virtual void EndGroup
|
||||
(
|
||||
const std::string& groupName,
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Totals& totals
|
||||
)
|
||||
{
|
||||
if( m_groupSpan.emitted && !groupName.empty() )
|
||||
{
|
||||
m_config.stream() << "[End of group: '" << groupName << "'. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
ReportCounts( totals );
|
||||
m_config.stream() << "]\n" << std::endl;
|
||||
m_groupSpan = SpanInfo();
|
||||
}
|
||||
@ -175,15 +181,14 @@ namespace Catch
|
||||
virtual void EndSection
|
||||
(
|
||||
const std::string& sectionName,
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Counts& assertions
|
||||
)
|
||||
{
|
||||
SpanInfo& sectionSpan = m_sectionSpans.back();
|
||||
if( sectionSpan.emitted && !sectionSpan.name.empty() )
|
||||
{
|
||||
m_config.stream() << "[End of section: '" << sectionName << "'. ";
|
||||
ReportCounts( succeeded, failed );
|
||||
ReportCounts( assertions);
|
||||
m_config.stream() << "]\n" << std::endl;
|
||||
}
|
||||
m_sectionSpans.pop_back();
|
||||
@ -262,8 +267,7 @@ namespace Catch
|
||||
virtual void EndTestCase
|
||||
(
|
||||
const TestCaseInfo& testInfo,
|
||||
std::size_t succeeded,
|
||||
std::size_t failed,
|
||||
const Totals& totals,
|
||||
const std::string& stdOut,
|
||||
const std::string& stdErr
|
||||
)
|
||||
@ -283,7 +287,7 @@ namespace Catch
|
||||
if( m_testSpan.emitted )
|
||||
{
|
||||
m_config.stream() << "[Finished: " << testInfo.getName() << " ";
|
||||
ReportCounts( succeeded, failed );
|
||||
ReportCounts( totals );
|
||||
m_config.stream() << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -104,9 +104,9 @@ namespace Catch
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndGroup( const std::string&, std::size_t succeeded, std::size_t failed )
|
||||
virtual void EndGroup( const std::string&, const Totals& totals )
|
||||
{
|
||||
m_currentStats->m_testsCount = failed+succeeded;
|
||||
m_currentStats->m_testsCount = totals.assertions.total();
|
||||
m_currentStats = &m_testSuiteStats;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ namespace Catch
|
||||
{
|
||||
}
|
||||
|
||||
virtual void EndSection( const std::string& /*sectionName*/, std::size_t /*succeeded*/, std::size_t /*failed*/ )
|
||||
virtual void EndSection( const std::string& /*sectionName*/, const Counts& /* assertions */ )
|
||||
{
|
||||
}
|
||||
|
||||
@ -178,7 +178,7 @@ namespace Catch
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTestCase( const Catch::TestCaseInfo&, std::size_t /* succeeded */, std::size_t /* failed */, const std::string& stdOut, const std::string& stdErr )
|
||||
virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals& /* totals */, const std::string& stdOut, const std::string& stdErr )
|
||||
{
|
||||
if( !stdOut.empty() )
|
||||
m_stdOut << stdOut << "\n";
|
||||
@ -187,7 +187,7 @@ namespace Catch
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTesting( std::size_t /* succeeded */, std::size_t /* failed */ )
|
||||
virtual void EndTesting( const Totals& /* totals */ )
|
||||
{
|
||||
std::ostream& str = m_config.stream();
|
||||
{
|
||||
|
@ -61,13 +61,12 @@ namespace Catch
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTesting
|
||||
(
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Totals& totals
|
||||
)
|
||||
{
|
||||
m_xml.scopedElement( "OverallResults" )
|
||||
.writeAttribute( "successes", succeeded )
|
||||
.writeAttribute( "failures", failed );
|
||||
.writeAttribute( "successes", totals.assertions.passed )
|
||||
.writeAttribute( "failures", totals.assertions.failed );
|
||||
m_xml.endElement();
|
||||
}
|
||||
|
||||
@ -85,13 +84,12 @@ namespace Catch
|
||||
virtual void EndGroup
|
||||
(
|
||||
const std::string& /*groupName*/,
|
||||
std::size_t succeeded,
|
||||
std::size_t failed
|
||||
const Totals& totals
|
||||
)
|
||||
{
|
||||
m_xml.scopedElement( "OverallResults" )
|
||||
.writeAttribute( "successes", succeeded )
|
||||
.writeAttribute( "failures", failed );
|
||||
.writeAttribute( "successes", totals.assertions.passed )
|
||||
.writeAttribute( "failures", totals.assertions.failed );
|
||||
m_xml.endElement();
|
||||
}
|
||||
|
||||
@ -104,11 +102,11 @@ namespace Catch
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndSection( const std::string& /*sectionName*/, std::size_t succeeded, std::size_t failed )
|
||||
virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions )
|
||||
{
|
||||
m_xml.scopedElement( "OverallResults" )
|
||||
.writeAttribute( "successes", succeeded )
|
||||
.writeAttribute( "failures", failed );
|
||||
.writeAttribute( "successes", assertions.passed )
|
||||
.writeAttribute( "failures", assertions.failed );
|
||||
m_xml.endElement();
|
||||
}
|
||||
|
||||
@ -175,7 +173,7 @@ namespace Catch
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
virtual void EndTestCase( const Catch::TestCaseInfo&, std::size_t /* succeeded */, std::size_t /* failed */, const std::string& /*stdOut*/, const std::string& /*stdErr*/ )
|
||||
virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals& /* totals */, const std::string& /*stdOut*/, const std::string& /*stdErr*/ )
|
||||
{
|
||||
m_xml.scopedElement( "OverallResult" ).writeAttribute( "success", m_currentTestSuccess );
|
||||
m_xml.endElement();
|
||||
|
Loading…
Reference in New Issue
Block a user