mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-04 05:09:53 +01:00
Test Case counts reported separately from assertions
Test case passed/ failures are counted as well as individual assertions. The basic reporter now reports them seperately
This commit is contained in:
parent
edd8f02bec
commit
5e5698b792
@ -387,6 +387,11 @@ namespace Catch
|
|||||||
delete m_runningTest;
|
delete m_runningTest;
|
||||||
m_runningTest = NULL;
|
m_runningTest = NULL;
|
||||||
|
|
||||||
|
if( m_totals.assertions.failed > prevTotals.assertions.failed )
|
||||||
|
++m_totals.testCases.failed;
|
||||||
|
else
|
||||||
|
++m_totals.testCases.passed;
|
||||||
|
|
||||||
m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr );
|
m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,25 @@
|
|||||||
|
|
||||||
namespace Catch
|
namespace Catch
|
||||||
{
|
{
|
||||||
|
struct pluralise
|
||||||
|
{
|
||||||
|
pluralise( std::size_t count, const std::string& label )
|
||||||
|
: m_count( count ),
|
||||||
|
m_label( label )
|
||||||
|
{}
|
||||||
|
|
||||||
|
friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser )
|
||||||
|
{
|
||||||
|
os << pluraliser.m_count << " " << pluraliser.m_label;
|
||||||
|
if( pluraliser.m_count != 1 )
|
||||||
|
os << "s";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t m_count;
|
||||||
|
std::string m_label;
|
||||||
|
};
|
||||||
|
|
||||||
class BasicReporter : public IReporter
|
class BasicReporter : public IReporter
|
||||||
{
|
{
|
||||||
struct SpanInfo
|
struct SpanInfo
|
||||||
@ -63,35 +82,26 @@ namespace Catch
|
|||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
void ReportCounts
|
void ReportCounts
|
||||||
(
|
(
|
||||||
const Counts& assertions
|
const std::string& label,
|
||||||
|
const Counts& counts
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( assertions.failed + assertions.passed == 0 )
|
if( counts.failed > 0 )
|
||||||
m_config.stream() << "No tests ran";
|
|
||||||
else if( assertions.failed == 0 )
|
|
||||||
{
|
{
|
||||||
if( assertions.passed == 1 )
|
if( counts.passed > 0 )
|
||||||
m_config.stream() << "1 test succeeded";
|
m_config.stream() << counts.failed << " of " << counts.total() << " " << label << "s failed";
|
||||||
else
|
else
|
||||||
m_config.stream() << "All " << assertions.passed << " tests succeeded";
|
{
|
||||||
}
|
if( counts.failed > 1 )
|
||||||
else if( assertions.passed == 0 )
|
m_config.stream() << "All ";
|
||||||
{
|
m_config.stream() << pluralise( counts.failed, label ) << " failed";
|
||||||
if( assertions.failed == 1 )
|
}
|
||||||
m_config.stream() << "1 test failed";
|
|
||||||
else
|
|
||||||
m_config.stream() << "All " << assertions.failed << " tests failed";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_config.stream() << assertions.passed << " test";
|
if( counts.passed > 1 )
|
||||||
if( assertions.passed > 1 )
|
m_config.stream() << "All ";
|
||||||
m_config.stream() << "s";
|
m_config.stream() << pluralise( counts.passed, label ) << " passed";
|
||||||
|
|
||||||
m_config.stream() << " passed but " << assertions.failed << " test";
|
|
||||||
if( assertions.failed > 1 )
|
|
||||||
m_config.stream() << "s";
|
|
||||||
m_config.stream() << " failed";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +111,17 @@ namespace Catch
|
|||||||
const Totals& totals
|
const Totals& totals
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ReportCounts( totals.assertions );
|
if( totals.assertions.total() == 0 )
|
||||||
|
{
|
||||||
|
m_config.stream() << "No tests ran";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ReportCounts( "test case", totals.testCases );
|
||||||
|
if( totals.testCases.failed > 0 )
|
||||||
|
{
|
||||||
|
m_config.stream() << ". ";
|
||||||
|
ReportCounts( "assertion", totals.assertions );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private: // IReporter
|
private: // IReporter
|
||||||
@ -188,7 +208,7 @@ namespace Catch
|
|||||||
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( assertions);
|
ReportCounts( "assertion", assertions);
|
||||||
m_config.stream() << "]\n" << std::endl;
|
m_config.stream() << "]\n" << std::endl;
|
||||||
}
|
}
|
||||||
m_sectionSpans.pop_back();
|
m_sectionSpans.pop_back();
|
||||||
|
Loading…
Reference in New Issue
Block a user