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